00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SINGLETON_H
00021 #define SINGLETON_H
00022
00030 template <typename T>
00031 class Singleton
00032 {
00033 protected:
00034 Singleton() {}
00035 ~Singleton() {}
00036
00037 public:
00038
00042 static T *instance()
00043 {
00044 if (NULL == inst)
00045 {
00046 inst = new T;
00047 }
00048 return (static_cast<T*> (inst));
00049 }
00050
00054 static void destroy()
00055 {
00056 if (NULL != inst)
00057 {
00058 delete inst;
00059 inst = NULL;
00060 }
00061 }
00062
00063 private:
00064 static T *inst;
00065
00066 Singleton(const Singleton&);
00067 Singleton& operator =(const Singleton&);
00068 };
00069
00070 template <typename T>
00071 T *Singleton<T>::inst = NULL;
00072
00073 #endif