This commit is contained in:
朱子楚\zhuzi
2024-03-06 00:34:43 +08:00
parent 1baa1ca754
commit 2ae2e2509a
47 changed files with 1174 additions and 1273 deletions

View File

@ -1,25 +1,18 @@
#ifndef SINGLETON_H
#define SINGLETON_H
#include <QMutex>
/**
* @brief The Singleton class
*/
template <typename T>
class Singleton {
public:
static T* getInstance();
private:
Q_DISABLE_COPY_MOVE(Singleton)
};
template <typename T>
T* Singleton<T>::getInstance() {
static QMutex mutex;
QMutexLocker locker(&mutex);
static T* instance = nullptr;
if (instance == nullptr) {
instance = new T();
}
static T* instance = new T();
return instance;
}
@ -31,10 +24,4 @@ private: \
return Singleton<Class>::getInstance(); \
}
#define HIDE_CONSTRUCTOR(Class) \
private: \
Class() = default; \
Class(const Class& other) = delete; \
Q_DISABLE_COPY_MOVE(Class);
#endif // SINGLETON_H