32 lines
665 B
C
32 lines
665 B
C
|
//
|
||
|
// Created by 29019 on 2019/12/17.
|
||
|
//
|
||
|
|
||
|
#ifndef GENERAL_SIGNLETON_H
|
||
|
#define GENERAL_SIGNLETON_H
|
||
|
|
||
|
#include <memory>
|
||
|
#include <vector>
|
||
|
|
||
|
using namespace std;
|
||
|
template <typename T> class Singletone
|
||
|
{
|
||
|
public:
|
||
|
static Singletone<T> Instance(){
|
||
|
if(mInstance.get() == nullptr){
|
||
|
mInstance = std::unique_ptr<T>();
|
||
|
}
|
||
|
return mInstance;
|
||
|
}
|
||
|
private:
|
||
|
Singletone<T>(){};
|
||
|
~Singletone<T>(){};
|
||
|
Singletone &operator=(const Singletone&){};
|
||
|
static unique_ptr<T> mInstance;
|
||
|
};
|
||
|
|
||
|
#define DECLARE_SINGLETON(type) \
|
||
|
friend class unique_ptr<type> mInstacnePtr; \
|
||
|
friend class Singletone<type> ;
|
||
|
#endif //GENERAL_SIGNLETON_H
|