#ifndef __SINGlETON_H__
#define __SINGlETON_H__
#include <stdlib.h>
#define SINGLETON(CBaseClass) CBaseClass::Instance()
#define DECLARE_SINGLETON(CBaseClass) \
private:\
CBaseClass(){} \
virtual ~CBaseClass(){} \
public:\
static CBaseClass* Instance(void); \
static void Destory(void); \
private:\
volatile static CBaseClass* m_pInstance;
#define DECLARE_SINGLETON_INIT(CBaseClass) \
private:\
CBaseClass();\
virtual ~CBaseClass(); \
public:\
static CBaseClass* Instance(void); \
static void Destory(void); \
private:\
volatile static CBaseClass* m_pInstance;
#define IMPLEMENT_SINGLETON(CBaseClass) \
volatile CBaseClass *CBaseClass::m_pInstance = NULL;\
CBaseClass *CBaseClass::Instance()\
{\
if(NULL == m_pInstance)\
{\
if (NULL == m_pInstance)\
{\
m_pInstance = new CBaseClass;\
atexit(CBaseClass::Destory);\
}\
}\
return (CBaseClass *)m_pInstance;\
}\
\
void CBaseClass::Destory()\
{\
if(NULL != m_pInstance)\
{\
delete m_pInstance;\
m_pInstance = NULL;\
}\
}
#endif//__SINGlETON_H__
#define __SINGlETON_H__
#include <stdlib.h>
#define SINGLETON(CBaseClass) CBaseClass::Instance()
#define DECLARE_SINGLETON(CBaseClass) \
private:\
CBaseClass(){} \
virtual ~CBaseClass(){} \
public:\
static CBaseClass* Instance(void); \
static void Destory(void); \
private:\
volatile static CBaseClass* m_pInstance;
#define DECLARE_SINGLETON_INIT(CBaseClass) \
private:\
CBaseClass();\
virtual ~CBaseClass(); \
public:\
static CBaseClass* Instance(void); \
static void Destory(void); \
private:\
volatile static CBaseClass* m_pInstance;
#define IMPLEMENT_SINGLETON(CBaseClass) \
volatile CBaseClass *CBaseClass::m_pInstance = NULL;\
CBaseClass *CBaseClass::Instance()\
{\
if(NULL == m_pInstance)\
{\
if (NULL == m_pInstance)\
{\
m_pInstance = new CBaseClass;\
atexit(CBaseClass::Destory);\
}\
}\
return (CBaseClass *)m_pInstance;\
}\
\
void CBaseClass::Destory()\
{\
if(NULL != m_pInstance)\
{\
delete m_pInstance;\
m_pInstance = NULL;\
}\
}
#endif//__SINGlETON_H__