// Singleton.h: interface for the Singleton class. // ////////////////////////////////////////////////////////////////////// #ifndef SINGLETON_H_ #define SINGLETON_H_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include #include namespace util { // ½Ì±ÛÅæ ÇØÁ¦ ¹æ¹ý struct SingletonRelease { enum Value { kManual = 1, // ¼öµ¿ kAuto = 2 // ÀÚµ¿ }; }; // ¼öµ¿ ÇØÁ¦ ¹öÀü (±âº»°ª) template class Singleton { protected: Singleton() { } ~Singleton() { } public: static T* Instance() { if (instance_ == NULL) { instance_ = new T; } return instance_; } static void DestroyInstance() { if (instance_ != NULL) { delete instance_; instance_ = NULL; } } private: static T* instance_; }; // ÀÚµ¿ ÇØÁ¦ ¹öÀü template class Singleton { protected: Singleton() { } ~Singleton() { } public: static T* Instance() { static T instance; return &instance; } }; template T* Singleton< T, kRelease >::instance_ = NULL; } // util #endif // SINGLETON_H_