2016-05-30 16:37:03 +00:00
|
|
|
#include <cstdint>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace ace {
|
|
|
|
template<typename T>
|
|
|
|
class singleton {
|
|
|
|
public:
|
|
|
|
static T & get() {
|
|
|
|
|
|
|
|
if (_singletonInstance == nullptr) {
|
|
|
|
assert(_initialized == false);
|
|
|
|
_initialized = true;
|
|
|
|
_singletonInstance = new T();
|
|
|
|
}
|
|
|
|
|
|
|
|
return *_singletonInstance;
|
|
|
|
}
|
|
|
|
static void release() {
|
|
|
|
delete _singletonInstance;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
static T *_singletonInstance;
|
|
|
|
static bool _initialized;
|
|
|
|
};
|
|
|
|
template<typename T>
|
|
|
|
T* singleton<T>::_singletonInstance = nullptr;
|
|
|
|
template<typename T>
|
|
|
|
bool singleton<T>::_initialized = false;
|
2015-05-13 15:34:14 +00:00
|
|
|
}
|