aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/common/singleton.h
blob: e6326b2fd82ccb2b295b586231650f85374e73ef (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
#ifndef __JIN_SINGLETON_H
#define __JIN_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() {};
    private: 
        Singleton(const Singleton&);
        Singleton& operator = (const Singleton&);

        static T* _instance;
    };

    template<class T> T* Singleton<T>::_instance = nullptr;
}

#endif