diff options
Diffstat (limited to 'src/leeds/base/singletonManager.h')
-rw-r--r-- | src/leeds/base/singletonManager.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/leeds/base/singletonManager.h b/src/leeds/base/singletonManager.h new file mode 100644 index 00000000..833e178b --- /dev/null +++ b/src/leeds/base/singletonManager.h @@ -0,0 +1,60 @@ +#pragma once + +#include "common.h" + +namespace base +{ + +class cSingletonBase +{ + friend class cSingletonManager; + + cSingletonBase* next; + +public: + virtual ~cSingletonBase() {} +}; + +template<typename T> +class cSingleton : public cSingletonBase +{ + static T* mspInstance; + static void cSingleton<T>::CreateInstance() + { + mspInstance = new T(); + SingletonManager().Add(mspInstance); + } + +public: + static T* Instance() + { + if (!mspInstance) + CreateInstance(); + return mspInstance; + } + + ~cSingleton<T>() + { + mspInstance = nil; + } +}; + +class cSingletonManager +{ + cSingletonBase* head; + cSingletonBase* tail; + +public: + cSingletonManager() : + head(nil), + tail(nil) + {} + + void Add(cSingletonBase*); + void Purge(); + ~cSingletonManager(); +}; + +cSingletonManager& SingletonManager(); + +}
\ No newline at end of file |