PVRTSingleton.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /******************************************************************************
  2. @File PVRTSingleton.h
  3. @Title PVRTSingleton
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI compatible
  7. @Description Singleton template Pattern Usage: Inherit from CPVRTSingleton
  8. class like this: class Foo : public CPVRTSingleton<Foo> { ... };
  9. ******************************************************************************/
  10. #ifndef __PVRTSINGLETON__
  11. #define __PVRTSINGLETON__
  12. template<typename T> class CPVRTSingleton
  13. {
  14. private:
  15. CPVRTSingleton(const CPVRTSingleton&);
  16. CPVRTSingleton & operator=(const CPVRTSingleton&);
  17. public:
  18. static T& inst()
  19. {
  20. static T object;
  21. return object;
  22. }
  23. static T* ptr()
  24. {
  25. return &inst();
  26. }
  27. protected:
  28. CPVRTSingleton() {};
  29. virtual ~CPVRTSingleton() {};
  30. };
  31. #endif // __PVRTSINGLETON__
  32. /*****************************************************************************
  33. End of file (PVRTSingleton.h)
  34. *****************************************************************************/