source: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCSingleton.h @ 721

Revision 721, 826 bytes checked in by igarcia, 19 years ago (diff)
Line 
1#ifndef __BBCSINGLETON_H__
2#define __BBCSINGLETON_H__
3
4namespace BBC {
5
6
7template <typename T> class _BBCExport CSingleton
8{
9    protected:
10
11        static T* ms_Singleton;
12
13    public:
14        CSingleton( void )
15        {
16            assert( !ms_Singleton );
17#if defined( _MSC_VER ) && _MSC_VER < 1200       
18            int offset = (int)(T*)1 - (int)(CSingleton <T>*)(T*)1;
19            ms_Singleton = (T*)((int)this + offset);
20#else
21            ms_Singleton = static_cast< T* >( this );
22#endif
23        }
24        ~CSingleton( void )
25            {  assert( ms_Singleton );  ms_Singleton = 0;  }
26        static T& getSingleton( void )
27                {       assert( ms_Singleton );  return ( *ms_Singleton ); }
28        static T* getSingletonPtr( void )
29                { return ms_Singleton; }
30};
31
32
33}
34
35#endif // ! defined __SINGLETON_H__
Note: See TracBrowser for help on using the repository browser.