#pragma once
#include "hNoncopyable.h"
template <typename T>
class SingletonFactory
{
public:
static T* instance()
{
return new T();
}
};
template <typename T, typename MANA = SingletonFactory<T> >
class Singleton : private hNoncopyable
{
private:
static T* ms_Singleton;
protected:
Singleton() {}
~Singleton() {}
public:
static void delInstance()
{
if (ms_Singleton)
{
delete ms_Singleton;
ms_Singleton = 0;
}
}
static T* instance()
{
if (! ms_Singleton)
{
ms_Singleton = MANA::instance();
}
return ms_Singleton;
}
static T& getMe()
{
return *instance();
}
static T& getInstance()
{
return *instance();
}
};
template <typename T, typename MANA>
T* Singleton<T,MANA>::ms_Singleton = 0;
#include "hNoncopyable.h"
template <typename T>
class SingletonFactory
{
public:
static T* instance()
{
return new T();
}
};
template <typename T, typename MANA = SingletonFactory<T> >
class Singleton : private hNoncopyable
{
private:
static T* ms_Singleton;
protected:
Singleton() {}
~Singleton() {}
public:
static void delInstance()
{
if (ms_Singleton)
{
delete ms_Singleton;
ms_Singleton = 0;
}
}
static T* instance()
{
if (! ms_Singleton)
{
ms_Singleton = MANA::instance();
}
return ms_Singleton;
}
static T& getMe()
{
return *instance();
}
static T& getInstance()
{
return *instance();
}
};
template <typename T, typename MANA>
T* Singleton<T,MANA>::ms_Singleton = 0;