blob: f37f3af3bced7dcf70821e88739c88f6c188f689 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#ifndef __JE_SINGLETON_H
#define __JE_SINGLETON_H
namespace JinEngine
{
template<class T>
class Singleton
{
public:
static T* get()
{
if (_instance == nullptr)
_instance = new T;
return _instance;
}
static void destroy()
{
delete _instance;
_instance = nullptr;
}
protected:
Singleton() {};
virtual ~Singleton() {};
static T* _instance;
private:
Singleton(const Singleton&);
Singleton& operator = (const Singleton&);
};
template<class T> T* Singleton<T>::_instance = nullptr;
#define singleton(T) friend Singleton<T>
} // namespace JinEngine
#endif // __JE_SINGLETON_H
|