2024-04-11 14:51:43 +08:00
|
|
|
#pragma once
|
2023-09-17 20:36:33 +08:00
|
|
|
|
2024-03-06 00:34:43 +08:00
|
|
|
/**
|
|
|
|
* @brief The Singleton class
|
|
|
|
*/
|
2024-06-28 17:09:23 +08:00
|
|
|
template <typename T>
|
2023-09-17 20:36:33 +08:00
|
|
|
class Singleton {
|
|
|
|
public:
|
2024-04-11 14:51:43 +08:00
|
|
|
static T *getInstance();
|
2023-09-17 20:36:33 +08:00
|
|
|
};
|
|
|
|
|
2024-06-28 17:09:23 +08:00
|
|
|
template <typename T>
|
2024-04-11 14:51:43 +08:00
|
|
|
T *Singleton<T>::getInstance() {
|
|
|
|
static T *instance = new T();
|
2023-09-17 20:36:33 +08:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2024-06-28 17:09:23 +08:00
|
|
|
#define SINGLETON(Class) \
|
|
|
|
private: \
|
|
|
|
friend class Singleton<Class>; \
|
|
|
|
\
|
|
|
|
public: \
|
|
|
|
static Class *getInstance() { \
|
|
|
|
return Singleton<Class>::getInstance(); \
|
|
|
|
}
|