Nebula
Loading...
Searching...
No Matches
win32singleton.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
21#include "core/types.h"
22
23//------------------------------------------------------------------------------
24#define __DeclareSingleton(type) \
25public: \
26 thread_local static type * Singleton; \
27 static type * Instance() { n_assert(nullptr != Singleton); return Singleton; }; \
28 static bool HasInstance() { return nullptr != Singleton; }; \
29private:
30
31#define __DeclareInterfaceSingleton(type) \
32public: \
33 static type * Singleton; \
34 static type * Instance() { n_assert(nullptr != Singleton); return Singleton; }; \
35 static bool HasInstance() { return nullptr != Singleton; }; \
36private:
37
38#define __ImplementSingleton(type) \
39 thread_local type * type::Singleton = nullptr;
40
41#define __ImplementInterfaceSingleton(type) \
42 type * type::Singleton = nullptr;
43
44#define __ConstructSingleton \
45 n_assert(nullptr == Singleton); Singleton = this;
46
47#define __ConstructInterfaceSingleton \
48 n_assert(nullptr == Singleton); Singleton = this;
49
50#define __DestructSingleton \
51 n_assert(Singleton); Singleton = nullptr;
52
53#define __DestructInterfaceSingleton \
54 n_assert(Singleton); Singleton = nullptr;
55//------------------------------------------------------------------------------