summaryrefslogtreecommitdiff
path: root/source/tests/02-luax/header.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/tests/02-luax/header.h')
-rw-r--r--source/tests/02-luax/header.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/source/tests/02-luax/header.h b/source/tests/02-luax/header.h
new file mode 100644
index 0000000..386ae71
--- /dev/null
+++ b/source/tests/02-luax/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;