00001
00002
00003
00004
00005
00006
00007
00008
00019 #ifndef _FU_SINGLETON_H_
00020 #define _FU_SINGLETON_H_
00021
00025 #define DECLARE_SINGLETON_CLASS(className) \
00026 private: \
00027 static className* m_pSingleton; \
00028 public: \
00029 static bool CreateSingleton(); \
00030 static void DestroySingleton(); \
00031 friend className* Get##className();
00032
00037 #define DECLARE_SINGLETON_CLASS_WITH_ARGS(className, createArgs) \
00038 private: \
00039 static className* m_pSingleton; \
00040 public: \
00041 static bool CreateSingleton(createArgs); \
00042 static void DestroySingleton(); \
00043 friend className* Get##className();
00044
00050 #define DECLARE_SINGLETON_CLASS_WITH_ARGS2(className, createArgs1, createArgs2) \
00051 private: \
00052 static className* m_pSingleton; \
00053 public: \
00054 static bool CreateSingleton(createArgs1, createArgs2); \
00055 static void DestroySingleton(); \
00056 friend className* Get##className();
00057
00061 #define IMPLEMENT_SINGLETON(className) \
00062 IMPLEMENT_CREATE_SINGLETON(className) \
00063 IMPLEMENT_DESTROY_SINGLETON(className)
00064
00069 #define IMPLEMENT_SINGLETON_WITH_ARGS(className, createArg1) \
00070 IMPLEMENT_CREATE_SINGLETON_WITH_ARGS(className, createArg1) \
00071 IMPLEMENT_DESTROY_SINGLETON(className)
00072
00078 #define IMPLEMENT_SINGLETON_WITH_ARGS2(className, createArg1, createArg2) \
00079 IMPLEMENT_CREATE_SINGLETON_WITH_ARGS2(className, createArg1, createArg2) \
00080 IMPLEMENT_DESTROY_SINGLETON(className)
00081
00085 #define IMPLEMENT_CREATE_SINGLETON(className) \
00086 className* className::m_pSingleton; \
00087 className* Get##className() { return className::m_pSingleton; } \
00088 bool className::CreateSingleton() { \
00089 m_pSingleton = new className(); \
00090 return true; }
00091
00096 #define IMPLEMENT_CREATE_SINGLETON_WITH_ARGS(className, createArg1) \
00097 className* className::m_pSingleton; \
00098 className* Get##className() { return className::m_pSingleton; } \
00099 bool className::CreateSingleton(createArg1 argument1) { \
00100 m_pSingleton = new className(argument1); }
00101
00107 #define IMPLEMENT_CREATE_SINGLETON_WITH_ARGS2(className, createArg1, createArg2) \
00108 className* className::m_pSingleton; \
00109 className* Get##className() { return className::m_pSingleton; } \
00110 bool className::CreateSingleton(createArg1 argument1, createArg2 argument2) { \
00111 m_pSingleton = new className(argument1, argument2); }
00112
00116 #define IMPLEMENT_DESTROY_SINGLETON(className) \
00117 void className::DestroySingleton() \
00118 { SAFE_DELETE(m_pSingleton); }
00119
00120 #endif // _FU_SINGLETON_H_