1 Commits

Author SHA1 Message Date
d36e3e0d7f Static Analysis (#12)
All checks were successful
Bigfoot / Build & Test Debug (Unity Build: OFF) (push) Successful in 25s
Bigfoot / Build & Test Debug (Unity Build: ON) (push) Successful in 26s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: OFF) (push) Successful in 24s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: ON) (push) Successful in 24s
Bigfoot / Build & Test Release (Unity Build: OFF) (push) Successful in 21s
Bigfoot / Build & Test Release (Unity Build: ON) (push) Successful in 17s
Bigfoot / Clang Format Checks (push) Successful in 9s
Bigfoot / Sonarqube (push) Successful in 1m14s
Reviewed-on: #12
Co-authored-by: Romain BOULLARD <romain.boullard@protonmail.com>
Co-committed-by: Romain BOULLARD <romain.boullard@protonmail.com>
2026-02-02 06:51:27 +00:00

View File

@@ -9,7 +9,6 @@
#include <EASTL/array.h> #include <EASTL/array.h>
#include <EASTL/bit.h> #include <EASTL/bit.h>
#include <EASTL/optional.h>
#include <EASTL/type_traits.h> #include <EASTL/type_traits.h>
#include <EASTL/utility.h> #include <EASTL/utility.h>
@@ -33,7 +32,7 @@ class Singleton
*/ */
static constexpr TYPE& Instance() static constexpr TYPE& Instance()
{ {
return ms_instance.value(); return *eastl::bit_cast<TYPE*>(ms_instance.data());
} }
class Lifetime class Lifetime
@@ -79,7 +78,9 @@ class Singleton
template<typename... ARGS> template<typename... ARGS>
static void Initialize(ARGS&&... p_args) static void Initialize(ARGS&&... p_args)
{ {
ms_instance.emplace(eastl::forward<ARGS>(p_args)...); new (ms_instance.data()) TYPE(eastl::forward<ARGS>(p_args)...);
ms_initialized = true;
} }
/** /**
@@ -88,13 +89,20 @@ class Singleton
*/ */
static void Finalize() static void Finalize()
{ {
ms_instance.reset(); eastl::bit_cast<TYPE*>(ms_instance.data())->~TYPE();
ms_initialized = false;
} }
/** /**
* The singleton. * The singleton.
*/ */
inline static eastl::optional<TYPE> ms_instance; alignas(alignof(TYPE)) inline static eastl::array<std::byte, sizeof(TYPE)> ms_instance;
/**
* Is the singleton initialized?
*/
inline static bool ms_initialized = false;
}; };
} // namespace Bigfoot } // namespace Bigfoot
#endif #endif