1 #ifndef SINGLETON_H_INCLUDED
\r
2 #define SINGLETON_H_INCLUDED
\r
7 static T* ms_singleton;
\r
11 assert(!ms_singleton);
\r
12 //use a cunning trick to get the singleton pointing to the start of the whole, rather than
\r
13 //the start of the Singleton part of the object
\r
14 int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
\r
15 ms_singleton = (T*)((int)this + offset);
\r
19 assert(ms_singleton);
\r
22 static inline T& GetSingleton()
\r
24 assert(ms_singleton);
\r
25 return *ms_singleton;
\r
27 static inline T* GetSingletonPtr()
\r
29 assert(ms_singleton);
\r
30 return ms_singleton;
\r
34 template <typename T> T* Singleton <T>::ms_singleton = 0;
\r