/src/libtomahawk/thirdparty/kdsingleapplicationguard/pimpl_ptr.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 44 lines · 30 code · 11 blank · 3 comment · 0 complexity · ec6df6accbe133d36cc4464a150272e2 MD5 · raw file

  1. #ifndef __KDTOOLSCORE__PIMPL_PTR_H__
  2. #define __KDTOOLSCORE__PIMPL_PTR_H__
  3. #include "kdtoolsglobal.h"
  4. #ifndef DOXYGEN_RUN
  5. namespace kdtools {
  6. #endif
  7. template <typename T>
  8. class pimpl_ptr {
  9. KDAB_DISABLE_COPY( pimpl_ptr );
  10. T * d;
  11. public:
  12. pimpl_ptr() : d( new T ) {}
  13. explicit pimpl_ptr( T * t ) : d( t ) {}
  14. ~pimpl_ptr() { delete d; d = 0; }
  15. T * get() { return d; }
  16. const T * get() const { return d; }
  17. T * operator->() { return get(); }
  18. const T * operator->() const { return get(); }
  19. T & operator*() { return *get(); }
  20. const T & operator*() const { return *get(); }
  21. KDAB_IMPLEMENT_SAFE_BOOL_OPERATOR( get() )
  22. };
  23. // these are not implemented, so's we can catch their use at
  24. // link-time. Leaving them undeclared would open up a comparison
  25. // via operator unspecified-bool-type().
  26. template <typename T, typename S>
  27. void operator==( const pimpl_ptr<T> &, const pimpl_ptr<S> & );
  28. template <typename T, typename S>
  29. void operator!=( const pimpl_ptr<T> &, const pimpl_ptr<S> & );
  30. #ifndef DOXYGEN_RUN
  31. } // namespace kdtools
  32. #endif
  33. #endif /* __KDTOOLSCORE__PIMPL_PTR_H__ */