00001 template <typename T, typename InstanceArg> class Singleton { 00002 public: 00003 static T* getInstance() { 00004 if(Singleton<T,InstanceArg>::m_pInstance == 0) { 00005 Singleton<T,InstanceArg>::m_pInstance = new T(); 00006 return Singleton<T,InstanceArg>::m_pInstance; 00007 } 00008 else 00009 return Singleton<T,InstanceArg>::m_pInstance; 00010 } 00011 static T* getInstance(InstanceArg *Arg) { 00012 if(Singleton<T,InstanceArg>::m_pInstance == 0) { 00013 Singleton<T,InstanceArg>::m_pInstance = new T(Arg); 00014 return Singleton<T,InstanceArg>::m_pInstance; 00015 } 00016 else 00017 return Singleton<T,InstanceArg>::m_pInstance; 00018 } 00019 00020 private: 00021 static T* m_pInstance; 00022 }; 00023 00024 template <typename T> class SingletonNoArg { 00025 public: 00026 static T* getInstance() { 00027 if(SingletonNoArg<T>::m_pInstance == 0) { 00028 SingletonNoArg<T>::m_pInstance = new T(); 00029 return SingletonNoArg<T>::m_pInstance; 00030 } 00031 else 00032 return SingletonNoArg<T>::m_pInstance; 00033 } 00034 00035 private: 00036 static T* m_pInstance; 00037 }; 00038 00039 template <class T,class InstanceArg> T* Singleton<T,InstanceArg>::m_pInstance = 0; 00040 template <typename T> T* SingletonNoArg<T>::m_pInstance = 0;