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