CSEngine
Loading...
Searching...
No Matches
MacroDef.h
1#pragma once
2
3
4#define MAKE_NO_COPY(CLASSNAME) \
5 private: \
6 CLASSNAME(const CLASSNAME&); \
7 CLASSNAME& operator=(const CLASSNAME&);
8
9
10#define DECLARE_SINGLETON(CLASSNAME) \
11 MAKE_NO_COPY(CLASSNAME) \
12 private: \
13 explicit CLASSNAME(); \
14 static CLASSNAME* sInstance; \
15 public: \
16 static CLASSNAME* getInstance(); \
17 static void delInstance();
18
19
20#define IMPLEMENT_SINGLETON(CLASSNAME) \
21 CLASSNAME* CLASSNAME::sInstance= nullptr; \
22 \
23 CLASSNAME* CLASSNAME::getInstance() { \
24 if(sInstance == nullptr) \
25 sInstance = new CLASSNAME; \
26 return sInstance; \
27 } \
28 void CLASSNAME::delInstance() \
29 { \
30 SAFE_DELETE(sInstance); \
31 }
32
33
34#define NULLPTR(p) { (p) = nullptr; }
35#define SAFE_DELETE(p) { delete (p); NULLPTR(p); }
36#define SAFE_DELETE_SOBJECT(p) {if(p) MemoryMgr::getInstance()->ReleaseObject(p);}
37#define SAFE_DELETE_SGAMEOBJECT(p) {if(p) GameObjectMgr::getInstance()->DeleteGameObject(p);}
38#define SAFE_DELETE_ARRAY(p) { if(p) delete[] (p); NULLPTR(p); }
39#define SAFE_DESTROY(p) { if(p) (p)->Destroy(); NULLPTR(p); }
40#define SAFE_RELEASE(p) { if(p) (p)->Release(); }
41