Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members
E:/Programming/MyProject/K_Game_hg/GameEngine/include/core/Singleton.h
Go to the documentation of this file.
00001 // Copyright 2006-2011 by Kat'Oun
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 } // end namespace core
00046 
00047 #endif

The KG Game Engine
The KG Game Engine Documentation © 2006-2011 by Kat'Oun. Generated on Sat Jul 2 2011 00:50:04 by Doxygen (1.7.4)