#pragma once #include "of_def.hpp" #include #include #include #include namespace ofen { template class OfSingleton { public: OfSingleton(const OfSingleton&) = delete; OfSingleton& operator=(const OfSingleton&) = delete; static std::shared_ptr getInstance() { std::call_once(init_flag, []() { instance.reset(new T()); }); return instance; } protected: OfSingleton() = default; virtual ~OfSingleton() = default; private: static std::shared_ptr instance; static std::once_flag init_flag; }; template std::shared_ptr OfSingleton::instance = nullptr; template std::once_flag OfSingleton::init_flag; } // namespace ofen