Go to the documentation of this file.00001
00002
00003 #ifndef _SINGLETON_H_
00004 #define _SINGLETON_H_
00005
00006 #include <EngineConfig.h>
00007
00008 namespace core
00009 {
00010
00012 template <typename T>
00013 class ENGINE_TEMPLATE_EXPORT Singleton
00014 {
00015 public:
00016
00017 Singleton()
00018 {
00019 assert(!ms_Singleton);
00020 #if defined( _MSC_VER ) && _MSC_VER < 1200
00021 int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
00022 ms_Singleton = (T*)((int)this + offset);
00023 #else
00024 ms_Singleton = static_cast<T*>(this);
00025 #endif
00026 }
00027
00028 ~Singleton()
00029 {
00030 assert(ms_Singleton);
00031 ms_Singleton = NULL;
00032 }
00033
00035 static T* getInstance()
00036 {
00037 return ms_Singleton;
00038 }
00039
00040 protected:
00041
00042 static T* ms_Singleton;
00043 };
00044
00045 }
00046
00047 #endif