blob: 12b14502b1f40a3d5f9506d523590e145340b551 (
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 __LIBJIN_SINGLETON_H
#define __LIBJIN_SINGLETON_H
namespace jin
{
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 jin
#endif // __LIBJIN_SINGLETON_H
|