7#ifndef MYGUI_SINGLETON_H_
8#define MYGUI_SINGLETON_H_
15#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
25 #if defined(__clang__)
28 __attribute__((no_sanitize(
"vptr")))
33 msInstance =
static_cast<T*
>(
this);
38 if (
nullptr == msInstance)
56 return mClassTypeName;
61 static const char* mClassTypeName;
101 mInstance->initialiseSingleton();
105 mInstance->shutdownSingleton();
111#define MYGUI_SINGLETON_DECLARATION(ClassName) \
113 friend MyGUI::SingletonHolder<ClassName>; \
114 MyGUI::SingletonHolder<ClassName> mSingletonHolder; \
115 void initialiseSingleton(); \
116 void shutdownSingleton(); \
119 static ClassName& getInstance(); \
120 static ClassName* getInstancePtr(); \
121 static const char* getClassTypeName()
123#define MYGUI_SINGLETON_DEFINITION(ClassName) \
124 static ClassName* ClassName##Instance = nullptr; \
125 static const char* ClassName##ClassTypeName = #ClassName; \
127 void ClassName::initialiseSingleton() \
129 MYGUI_ASSERT(nullptr == ClassName##Instance, "Singleton instance " << getClassTypeName() << " already exsist"); \
130 ClassName##Instance = this; \
133 void ClassName::shutdownSingleton() \
135 if (nullptr == ClassName##Instance) \
136 MYGUI_LOG(Critical, "Destroying Singleton instance " << getClassTypeName() << " before constructing it."); \
137 ClassName##Instance = nullptr; \
140 ClassName& ClassName::getInstance() \
142 MYGUI_ASSERT(nullptr != getInstancePtr(), "Singleton instance " << getClassTypeName() << " was not created"); \
143 return (*getInstancePtr()); \
146 ClassName* ClassName::getInstancePtr() \
148 return ClassName##Instance; \
151 const char* ClassName::getClassTypeName() \
153 return ClassName##ClassTypeName; \
155 static_assert(true, "require semicolon")
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_OBSOLETE(text)
#define MYGUI_LOG(level, text)
SingletonHolder(T *instance)
static T * getInstancePtr()
static const char * getClassTypeName()