00001 #pragma once
00002
00003 #ifndef NULL
00004 #define NULL 0
00005 #endif
00006
00013 template <typename T>
00014 class Singleton
00015 {
00016 private:
00017
00018 static T* m_pInstance;
00019
00020 private:
00021
00025 Singleton(const Singleton<T>&) {}
00026
00030 void operator =(const Singleton&) {}
00031
00032 protected:
00033
00037 Singleton() {}
00038
00042 virtual ~Singleton() {}
00043
00044 public:
00045
00049 static void Create()
00050 {
00051 if(m_pInstance == NULL)
00052 {
00053 m_pInstance = new T();
00054 }
00055 }
00056
00060 static void Release()
00061 {
00062 if(m_pInstance != NULL)
00063 {
00064 delete m_pInstance;
00065 m_pInstance = NULL;
00066 }
00067 }
00068
00072 static T& Get()
00073 {
00074 Create();
00075 return *m_pInstance;
00076 }
00077
00078 };
00079
00080 template <typename T> T *Singleton<T>::m_pInstance = NULL;