summaryrefslogtreecommitdiff
path: root/Source/Samples/LuaxTest/header.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-03-12 00:39:26 +0800
committerchai <chaifix@163.com>2019-03-12 00:39:26 +0800
commit70b82d1981c0de3c7b77670ff8abcfeb26815142 (patch)
treef69c05bcd204cc3f9bf745be37a2ba5911e52436 /Source/Samples/LuaxTest/header.h
parentc19a282e10f51ddd50d198b903f8fbd5a2238b62 (diff)
*misc
Diffstat (limited to 'Source/Samples/LuaxTest/header.h')
-rw-r--r--Source/Samples/LuaxTest/header.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/Source/Samples/LuaxTest/header.h b/Source/Samples/LuaxTest/header.h
new file mode 100644
index 0000000..386ae71
--- /dev/null
+++ b/Source/Samples/LuaxTest/header.h
@@ -0,0 +1,60 @@
+
+#ifndef ASSERT
+#ifdef NDEBUG
+#define ASSERT(x) { false ? (void)(x) : (void)0; }
+#else
+#ifdef _WIN32
+#define ASURA_DEBUG_BREAK() __debugbreak()
+#else
+#define ASURA_DEBUG_BREAK() raise(SIGTRAP)
+#endif
+#define ASSERT(x) do { const volatile bool asura_assert_b____ = !(x); if(asura_assert_b____) ASURA_DEBUG_BREAK(); } while (false)
+#endif
+#endif
+
+///
+/// ̳Singletonڵһʵʱʵ֮ٴʵᱨ
+///
+template<class T>
+class Singleton
+{
+public:
+
+ static T* Get()
+ {
+ // ֮ǰûдһ
+ if (!instance) instance = new T;
+ // ʵ
+ return instance;
+ }
+
+ static void Destroy()
+ {
+ delete instance;
+ instance = nullptr;
+ }
+
+protected:
+
+ Singleton()
+ {
+ // instanceζִһʵǴġ
+ ASSERT(!instance);
+ // 򣬽ʵΪʵ
+ instance = static_cast<T*>(this);
+ };
+
+ virtual ~Singleton() {};
+
+ static T* instance;
+
+private:
+
+ Singleton(const Singleton& singleton);
+
+ Singleton& operator = (const Singleton& singleton);
+
+};
+
+template<class T>
+T* Singleton<T>::instance = nullptr;