Created
March 16, 2013 13:12
-
-
Save 0xa/5176306 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef COMMON_SINGLETON_H | |
#define COMMON_SINGLETON_H | |
#include <cstdlib> | |
template<typename T> | |
class Singleton { | |
public: | |
Singleton() { | |
m_Instance = static_cast<T*>(this); | |
} | |
static T* GetInstancePtr() { | |
if (m_Instance == NULL) { | |
m_Instance = new T(); | |
} | |
return m_Instance; | |
} | |
static T& GetInstance() { | |
return *GetInstancePtr(); | |
} | |
static void DeleteInstance() { | |
delete m_Instance; | |
} | |
private: | |
static T* m_Instance; | |
Singleton(const Singleton<T> &); | |
Singleton& operator=(const Singleton<T> &); | |
}; | |
template<typename T> | |
T* Singleton<T>::m_Instance = NULL; | |
#endif // COMMON_SINGLETON_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment