LazyGlobal
Bigfoot / Sonarqube (game) (push) Skipped
Bigfoot / Sonarqube (toolmode) (push) Skipped
Bigfoot / Build & Test Debug with clang (Unity Build: OFF, Variant: game) (push) Successful in 1m5s
Bigfoot / Build & Test Debug with clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m12s
Bigfoot / Build & Test Debug with clang (Unity Build: ON, Variant: game) (push) Successful in 45s
Bigfoot / Build & Test Debug with clang (Unity Build: ON, Variant: toolmode) (push) Successful in 48s
Bigfoot / Build & Test Debug with clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 2m17s
Bigfoot / Build & Test Debug with clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 2m18s
Bigfoot / Build & Test Debug with clang_asan (Unity Build: ON, Variant: game) (push) Successful in 1m48s
Bigfoot / Build & Test Debug with clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m58s
Bigfoot / Build & Test Release with clang (Unity Build: OFF, Variant: game) (push) Successful in 1m3s
Bigfoot / Build & Test Release with clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m28s
Bigfoot / Build & Test Release with clang (Unity Build: ON, Variant: game) (push) Successful in 53s
Bigfoot / Build & Test Release with clang (Unity Build: ON, Variant: toolmode) (push) Successful in 1m12s
Bigfoot / Build & Test Release with clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m46s
Bigfoot / Build & Test Release with clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m50s
Bigfoot / Build & Test Release with clang_asan (Unity Build: ON, Variant: game) (push) Successful in 1m30s
Bigfoot / Build & Test Release with clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m37s
Bigfoot / Build & Test RelWithDebInfo with clang (Unity Build: OFF, Variant: game) (push) Successful in 1m16s
Bigfoot / Build & Test RelWithDebInfo with clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m17s
Bigfoot / Build & Test RelWithDebInfo with clang (Unity Build: ON, Variant: game) (push) Successful in 49s
Bigfoot / Build & Test RelWithDebInfo with clang (Unity Build: ON, Variant: toolmode) (push) Successful in 52s
Bigfoot / Build & Test RelWithDebInfo with clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 2m20s
Bigfoot / Build & Test RelWithDebInfo with clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 2m24s
Bigfoot / Build & Test RelWithDebInfo with clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m58s
Bigfoot / Build & Test RelWithDebInfo with clang_asan (Unity Build: ON, Variant: game) (push) Successful in 1m49s
Bigfoot / Clang Format Checks (push) Successful in 10s
Bigfoot / Sonarqube (game) (push) Skipped
Bigfoot / Sonarqube (toolmode) (push) Skipped
Bigfoot / Build & Test Debug with clang (Unity Build: OFF, Variant: game) (push) Successful in 1m5s
Bigfoot / Build & Test Debug with clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m12s
Bigfoot / Build & Test Debug with clang (Unity Build: ON, Variant: game) (push) Successful in 45s
Bigfoot / Build & Test Debug with clang (Unity Build: ON, Variant: toolmode) (push) Successful in 48s
Bigfoot / Build & Test Debug with clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 2m17s
Bigfoot / Build & Test Debug with clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 2m18s
Bigfoot / Build & Test Debug with clang_asan (Unity Build: ON, Variant: game) (push) Successful in 1m48s
Bigfoot / Build & Test Debug with clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m58s
Bigfoot / Build & Test Release with clang (Unity Build: OFF, Variant: game) (push) Successful in 1m3s
Bigfoot / Build & Test Release with clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m28s
Bigfoot / Build & Test Release with clang (Unity Build: ON, Variant: game) (push) Successful in 53s
Bigfoot / Build & Test Release with clang (Unity Build: ON, Variant: toolmode) (push) Successful in 1m12s
Bigfoot / Build & Test Release with clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m46s
Bigfoot / Build & Test Release with clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m50s
Bigfoot / Build & Test Release with clang_asan (Unity Build: ON, Variant: game) (push) Successful in 1m30s
Bigfoot / Build & Test Release with clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m37s
Bigfoot / Build & Test RelWithDebInfo with clang (Unity Build: OFF, Variant: game) (push) Successful in 1m16s
Bigfoot / Build & Test RelWithDebInfo with clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m17s
Bigfoot / Build & Test RelWithDebInfo with clang (Unity Build: ON, Variant: game) (push) Successful in 49s
Bigfoot / Build & Test RelWithDebInfo with clang (Unity Build: ON, Variant: toolmode) (push) Successful in 52s
Bigfoot / Build & Test RelWithDebInfo with clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 2m20s
Bigfoot / Build & Test RelWithDebInfo with clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 2m24s
Bigfoot / Build & Test RelWithDebInfo with clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m58s
Bigfoot / Build & Test RelWithDebInfo with clang_asan (Unity Build: ON, Variant: game) (push) Successful in 1m49s
Bigfoot / Clang Format Checks (push) Successful in 10s
Will help us avoid SIOF
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* \file LazyGlobal.hpp
|
||||||
|
*
|
||||||
|
* \author Romain BOULLARD
|
||||||
|
* \date September 2026
|
||||||
|
*********************************************************************/
|
||||||
|
#ifndef BIGFOOT_UTILS_LAZYGLOBAL_HPP
|
||||||
|
#define BIGFOOT_UTILS_LAZYGLOBAL_HPP
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace Bigfoot
|
||||||
|
{
|
||||||
|
template<class TYPE, class TAG = TYPE>
|
||||||
|
requires std::is_default_constructible_v<TYPE>
|
||||||
|
class LazyGlobal
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
[[nodiscard]]
|
||||||
|
TYPE* operator->() const
|
||||||
|
{
|
||||||
|
return &Get();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
operator TYPE*() const
|
||||||
|
{
|
||||||
|
return &Get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
[[nodiscard]]
|
||||||
|
static TYPE& Get()
|
||||||
|
{
|
||||||
|
static TYPE instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace Bigfoot
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* \file LazyGlobal.cpp
|
||||||
|
*
|
||||||
|
* \author Romain BOULLARD
|
||||||
|
* \date September 2026
|
||||||
|
*********************************************************************/
|
||||||
|
#include <Utils/LazyGlobal.hpp>
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace Bigfoot
|
||||||
|
{
|
||||||
|
class DummyValue
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
[[nodiscard]]
|
||||||
|
std::uint32_t GetValue() const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetValue(const std::uint32_t p_value)
|
||||||
|
{
|
||||||
|
m_value = p_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::uint32_t m_value = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
class LazyGlobalFixture: public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
};
|
||||||
|
|
||||||
|
LazyGlobal<DummyValue> g_dummyValueA;
|
||||||
|
LazyGlobal<DummyValue, class DummyValueA> g_dummyValueB;
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
TEST_F(LazyGlobalFixture, ArrowOperator)
|
||||||
|
{
|
||||||
|
g_dummyValueA->SetValue(42);
|
||||||
|
|
||||||
|
EXPECT_EQ(g_dummyValueA->GetValue(), 42);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
TEST_F(LazyGlobalFixture, PointerConversion)
|
||||||
|
{
|
||||||
|
DummyValue* const pointer = g_dummyValueA;
|
||||||
|
pointer->SetValue(7);
|
||||||
|
|
||||||
|
EXPECT_EQ(g_dummyValueA->GetValue(), 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
TEST_F(LazyGlobalFixture, DifferentTags_ShouldYieldIndependentInstancesOfTheSameType)
|
||||||
|
{
|
||||||
|
g_dummyValueA->SetValue(1);
|
||||||
|
g_dummyValueB->SetValue(2);
|
||||||
|
|
||||||
|
EXPECT_EQ(g_dummyValueA->GetValue(), 1);
|
||||||
|
EXPECT_EQ(g_dummyValueB->GetValue(), 2);
|
||||||
|
}
|
||||||
|
} // namespace Bigfoot
|
||||||
Reference in New Issue
Block a user