00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef TA_SINGLETON_H
00015 #define TA_SINGLETON_H
00016
00017 #ifndef TA_DEBUG_H
00018 #include "Debug.h"
00019 #endif // TA_DEBUG_H
00020
00021 #ifndef TA_MEMORYMGR_H
00022 #include "MemoryMgr.h"
00023 #endif // TA_MEMORYMGR_H
00024
00025 namespace TA
00026 {
00027
00028
00029 #define SINGLETON_DEFINE_OVERRIDE_CREATE(Type) \
00030 public: \
00031 static void TAC_CALL DestroyInstance(); \
00032 static Type& TAC_CALL GetInstance() \
00033 { \
00034 TA_ASSERT_MSG(s_p##Type, "Singleton("#Type")::GetInstance. Not initialised"); \
00035 return *s_p##Type; \
00036 } \
00037 static Type* TAC_CALL GetInstancePtr() { return s_p##Type; } \
00038 private: \
00039 static Type* s_p##Type; \
00040 public:
00041
00042
00043 #define SINGLETON_DEFINE(Type) \
00044 public: \
00045 static void TAC_CALL CreateInstance(); \
00046 friend class MemoryMgr; \
00047 SINGLETON_DEFINE_OVERRIDE_CREATE(Type)
00048
00049
00050 #define SINGLETON_IMPLEMENT_OVERRIDE_CREATE(Type) \
00051 Type* Type::s_p##Type; \
00052 void Type::DestroyInstance() \
00053 { \
00054 if (!s_p##Type) \
00055 return; \
00056 TA_MEMORY_MGR_DELETE(s_p##Type, Type); \
00057 s_p##Type = 0; \
00058 }
00059
00060 #define SINGLETON_IMPLEMENT(Type) \
00061 SINGLETON_IMPLEMENT_OVERRIDE_CREATE(Type) \
00062 void Type::CreateInstance() \
00063 { \
00064 if (s_p##Type) \
00065 return; \
00066 TA_MEMORY_MGR_NEW(s_p##Type, Type); \
00067 s_p##Type->Initialise(); \
00068 }
00069
00070 }
00071
00072 #endif // TA_SINGLETON_H
© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.