/********************************************************************* * \file Singleton.hpp * * \author Romain BOULLARD * \date February 2026 *********************************************************************/ #ifndef BIN2CPP_SINGLETON_HPP #define BIN2CPP_SINGLETON_HPP #include namespace Bin2CPP { template class Singleton { public: Singleton() = delete; Singleton(const Singleton& p_singleton) = delete; Singleton(Singleton&& p_singleton) = delete; ~Singleton() = delete; /** * Get the instance. * * \return The instance */ static TYPE& Instance() { return ms_instance.value(); } /** * Is the instance initialized * * \return True if initialized, false otherwise */ static bool HasInstance() { return ms_instance.has_value(); } class Lifetime { public: /** * Constructor. * * \param p_args Arguments for the singleton */ template explicit Lifetime(ARGS&&... p_args) { Initialize(std::forward(p_args)...); } Lifetime(const Lifetime& p_lifetime) = delete; Lifetime(Lifetime&& p_lifetime) = delete; ~Lifetime() { Finalize(); } [[nodiscard]] Lifetime& operator=(const Lifetime& p_lifetime) = delete; [[nodiscard]] Lifetime& operator=(Lifetime&& p_lifetime) = delete; }; [[nodiscard]] Singleton& operator=(const Singleton& p_singleton) = delete; [[nodiscard]] Singleton& operator=(Singleton&& p_singleton) = delete; private: /** * Initialize the singleton. * * \param p_args Arguments for the singleton */ template static void Initialize(ARGS&&... p_args) { ms_instance.emplace(std::forward(p_args)...); } /** * Finalize the singleton. * */ static void Finalize() { ms_instance.reset(); } /** * The singleton. */ inline static eastl::optional ms_instance; }; } // namespace Bin2CPP #endif