src/Resource/singleton.h

Go to the documentation of this file.
00001 #ifndef SINGLETON_H
00002 #define SINGLETON_H
00003 
00011 #include "Assert.h"
00012 
00013 extern bool g_shutdown; 
00020 template <class T> class Singleton
00021 {       
00022         static T* ms_instance; 
00023 public:
00028         static T* Get();
00029 
00031         static void Free();
00032 
00033 protected:
00035         Singleton();
00036 
00038         virtual ~Singleton();
00039 };
00040 
00041 template <class T> T* Singleton<T>::ms_instance = 0;
00042 
00043 template <class T> Singleton<T>::Singleton()
00044 {
00045 }
00046 
00047 template <class T> Singleton<T>::~Singleton()
00048 {
00049 }
00050 
00051 template <class T> T* Singleton<T>::Get()
00052 {
00053         Assert(!g_shutdown);
00054         
00055         if(!ms_instance)
00056                 ms_instance = new T();
00057         return ms_instance;
00058 }
00059 
00060 template <class T> void Singleton<T>::Free()
00061 {
00062         if( ms_instance )
00063         {
00064                 delete ms_instance;
00065                 ms_instance = 0;
00066         }
00067 }
00068 
00069 #endif // SINGLETON_H

Generated for UnsignedByte by  doxygen 1.5.3
SourceForge.net Logo