C:/Users/Mike/Documents/Visual Studio Projects/GameEngine/include/Singleton.h

Go to the documentation of this file.
00001 // Original author @ http://www.drizzle.com/~scottb/publish/gpgems1_singleton.htm
00002 #ifndef SINGLETON_H
00003 #define SINGLETON_H
00004 
00005 #include <cassert>
00006 
00007 namespace GameEngine{
00008 
00011         template <typename T> class Singleton {
00012 
00013         private://
00014                 static T* ms_Singleton;
00015 
00016         public:
00017                 Singleton( void ) {
00018                         assert( !ms_Singleton ); // Can only constructor a singleton once!
00019                         ms_Singleton = static_cast<T*>(this); // Note to self: See http://www.drizzle.com/~scottb/publish/gpgems1_singleton_notes.htm
00020                 }
00021 
00022                 ~Singleton( void ){  assert( ms_Singleton );  ms_Singleton = 0;  }
00023 
00024                 static T& getSingleton( void ){ assert( ms_Singleton );  return ( *ms_Singleton );  }
00025                 static T* getSingletonPtr( void ){  return ( ms_Singleton );  }
00026 
00027         };
00028 
00029         template <typename T> T* Singleton <T>::ms_Singleton = 0;
00030 }
00031 
00032 #endif

Generated on Thu Apr 19 09:47:02 2007 for GameEngine by  doxygen 1.5.2