#ifndef __OBASINGLETON_H__ #define __OBASINGLETON_H__ namespace OBA { template class _OBAExport CSingleton { protected: static T* ms_Singleton; public: CSingleton( void ) { assert( !ms_Singleton ); #if defined( _MSC_VER ) && _MSC_VER < 1200 int offset = (int)(T*)1 - (int)(CSingleton *)(T*)1; ms_Singleton = (T*)((int)this + offset); #else ms_Singleton = static_cast< T* >( this ); #endif } ~CSingleton( void ) { assert( ms_Singleton ); ms_Singleton = 0; } static T& getSingleton( void ) { assert( ms_Singleton ); return ( *ms_Singleton ); } static T* getSingletonPtr( void ) { return ms_Singleton; } }; } #endif // ! defined __SINGLETON_H__