#ifndef SINGLETON_H #define SINGLETON_H #include #include #include #include template class Singleton { public: static T* getInstance(); Singleton(const Singleton& other) = delete; Singleton& operator=(const Singleton& other) = delete; private: static std::mutex mutex; static T* instance; }; template std::mutex Singleton::mutex; template T* Singleton::instance; template T* Singleton::getInstance() { if (instance == nullptr) { std::lock_guard locker(mutex); if (instance == nullptr) { instance = new T(); } } return instance; } #define SINGLETONG(Class) \ private: \ friend class Singleton; \ friend struct QScopedPointerDeleter; \ \ public: \ static Class* getInstance() { \ return Singleton::getInstance(); \ } #define HIDE_CONSTRUCTOR(Class) \ private: \ Class() = default; \ Class(const Class& other) = delete; \ Class& operator=(const Class& other) = delete; #endif // SINGLETON_H