diff options
Diffstat (limited to 'Runner/Utilities/Singleton.h')
-rw-r--r-- | Runner/Utilities/Singleton.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Runner/Utilities/Singleton.h b/Runner/Utilities/Singleton.h new file mode 100644 index 0000000..65c9e60 --- /dev/null +++ b/Runner/Utilities/Singleton.h @@ -0,0 +1,45 @@ +#ifndef SINGLETON_H +#define SINGLETON_H + +template<class T> +class Singleton +{ +public: + + static T* Instance() + { + if (!instance) instance = new T; + return instance; + } + + static void Destroy() + { + delete instance; + instance = nullptr; + } + +protected: + + Singleton() + { + instance = static_cast<T*>(this); + }; + + virtual ~Singleton() {}; + + static T* instance; + +private: + + Singleton(const Singleton& singleton); + + Singleton& operator = (const Singleton& singleton); + +}; + +template<class T> +T* Singleton<T>::instance = nullptr; + +#define Get(T) T::Instance() + +#endif
\ No newline at end of file |