1 /*!**************************************************************************** 2 3 @file PVRTSingleton.h 4 @copyright Copyright (c) Imagination Technologies Limited. 5 @brief Singleton template. 6 @details Pattern Usage: Inherit from CPVRTSingleton 7 class like this: class Foo : public CPVRTSingleton<Foo> { ... }; 8 9 ******************************************************************************/ 10 #ifndef __PVRTSINGLETON__ 11 #define __PVRTSINGLETON__ 12 13 /*!**************************************************************************** 14 @class CPVRTSingleton 15 @brief Singleton template. 16 @details Pattern Usage: Inherit from CPVRTSingleton class like this: 17 class Foo : public CPVRTSingleton<Foo> { ... }; 18 ******************************************************************************/ 19 template<typename T> class CPVRTSingleton 20 { 21 private: 22 /*! @brief Constructor. */ 23 CPVRTSingleton(const CPVRTSingleton&); 24 25 /*! @brief Deconstructor. */ 26 CPVRTSingleton & operator=(const CPVRTSingleton&); 27 28 public: 29 static T& inst() 30 { 31 static T object; 32 return object; 33 } 34 35 static T* ptr() 36 { 37 return &inst(); 38 } 39 40 protected: 41 CPVRTSingleton() {}; 42 virtual ~CPVRTSingleton() {}; 43 }; 44 45 46 #endif // __PVRTSINGLETON__ 47 48 /***************************************************************************** 49 End of file (PVRTSingleton.h) 50 *****************************************************************************/ 51 52