Guest User

Untitled

a guest
Nov 17th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #ifndef _CHS_SINGLETON_H
  2. #define _CHS_SINGLETON_H
  3. //--------------------------------------------------------------------------------------------------
  4. #include <assert.h>
  5.  
  6. #include <assert.h>
  7. //--------------------------------------------------------------------------------------------------
  8. namespace Chaos{
  9.  
  10. //------------------------------------------------------------------------------------------------
  11. template < typename T > class ChsSingleton {
  12. public:
  13. ChsSingleton( void );
  14. ~ChsSingleton( void );
  15. static T* sharedInstance( void );
  16. protected:
  17. static T* _shareInstance;
  18. };
  19.  
  20. //------------------------------------------------------------------------------------------------
  21. template < typename T >T* ChsSingleton< T >::_shareInstance = 0;
  22.  
  23. //------------------------------------------------------------------------------------------------
  24. template < typename T >ChsSingleton< T >::ChsSingleton( void ) {
  25. assert( !_shareInstance );
  26. _shareInstance = static_cast< T * >( this );
  27. }
  28.  
  29. //------------------------------------------------------------------------------------------------
  30. template < typename T >ChsSingleton< T >::~ChsSingleton( void ) {
  31. assert( _shareInstance );
  32. _shareInstance = 0;
  33. }
  34.  
  35. //------------------------------------------------------------------------------------------------
  36. template < typename T >T* ChsSingleton< T >::sharedInstance( void ) {
  37. assert( _shareInstance );
  38. return _shareInstance;
  39. }
  40.  
  41. //------------------------------------------------------------------------------------------------
  42.  
  43. }//namespace
  44.  
  45. //--------------------------------------------------------------------------------------------------
  46. #endif//_CHS_SINGLETON_H
Add Comment
Please, Sign In to add comment