Compare commits
1 Commits
Developmen
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d36e3e0d7f |
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user