diff options
| author | chai <chaifix@163.com> | 2021-12-13 00:07:19 +0800 | 
|---|---|---|
| committer | chai <chaifix@163.com> | 2021-12-13 00:07:19 +0800 | 
| commit | 60cbbdec07ab7a5636eac5b3c024ae44e937f4d4 (patch) | |
| tree | b2c7b0a868f18159dbc43d8954e1bd7668549a88 /Client/Source/Utilities/Singleton.h | |
+init
Diffstat (limited to 'Client/Source/Utilities/Singleton.h')
| -rw-r--r-- | Client/Source/Utilities/Singleton.h | 43 | 
1 files changed, 43 insertions, 0 deletions
| diff --git a/Client/Source/Utilities/Singleton.h b/Client/Source/Utilities/Singleton.h new file mode 100644 index 0000000..f864a42 --- /dev/null +++ b/Client/Source/Utilities/Singleton.h @@ -0,0 +1,43 @@ +#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; + +#endif
\ No newline at end of file | 
