pi1541/src/Singleton.h

52 lines
542 B
C
Raw Normal View History

2018-05-20 04:53:34 +00:00
#ifndef _Singleton_h_
#define _Singleton_h_
#include "types.h"
2018-05-20 04:53:34 +00:00
template <typename T>
class Singleton
{
public:
static T* Instance()
{
if (m_pInstance == 0)
m_pInstance = new T;
//assert(m_pInstance != 0);
return m_pInstance;
};
static void DestroyInstance()
{
delete m_pInstance;
m_pInstance = 0;
};
protected:
Singleton()
{
};
virtual ~Singleton()
{
};
static T* m_pInstance;
private:
Singleton(const Singleton& source)
{
};
};
template <typename T> T* Singleton<T>::m_pInstance = 0;
#endif