From b867701d2a971d7ce508ef826f02c48b4526504d Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Thu, 14 May 2026 01:54:38 +0200 Subject: [PATCH] SlotMaps --- .../Include/Engine/EngineLogger_generated.hpp | 2 +- Bigfoot/Sources/System/CMakeLists.txt | 9 - .../Include/System/SystemLogger_generated.hpp | 2 +- Bigfoot/Sources/Utils/CMakeLists.txt | 12 +- .../Sources/Utils/Include/Utils/Assert.hpp | 2 +- .../Include/Utils/Containers/SlotMap.hpp | 212 ++++++++++++++++++ .../Include/Utils}/Log/EASTLFormatters.hpp | 0 .../Include/Utils}/Log/Log.fbs | 0 .../Include/Utils}/Log/Log.hpp | 9 +- .../Include/Utils}/Log/Log_generated.hpp | 0 .../Utils}/Log/TargetLogger_generated.hpp.in | 2 +- .../Include/Utils}/Profiler.hpp | 4 +- .../Include/Utils/UtilsAssertHandler.hpp | 56 +++++ .../Include/Utils/UtilsLogger_generated.hpp} | 10 +- Bigfoot/Sources/{System => Utils}/Log/Log.cpp | 2 +- .../{System => Utils}/MimallocImpl.cpp | 2 +- Bigfoot/Tests/Engine/Asset/Asset.cpp | 3 +- Bigfoot/Tests/Engine/BigFile/BigFile.cpp | 2 +- Bigfoot/Tests/System/CMakeLists.txt | 4 +- Bigfoot/Tests/Utils/CMakeLists.txt | 4 +- Bigfoot/Tests/Utils/Containers/SlotMap.cpp | 19 ++ .../UtilsTests/UtilsTestsLogger_generated.hpp | 21 ++ Bigfoot/Tests/{System => Utils}/Log/Log.cpp | 36 +-- CMake/Utils.cmake | 2 +- 24 files changed, 361 insertions(+), 54 deletions(-) rename Bigfoot/Sources/{System/Include/System => Utils/Include/Utils}/Log/EASTLFormatters.hpp (100%) rename Bigfoot/Sources/{System/Include/System => Utils/Include/Utils}/Log/Log.fbs (100%) rename Bigfoot/Sources/{System/Include/System => Utils/Include/Utils}/Log/Log.hpp (98%) rename Bigfoot/Sources/{System/Include/System => Utils/Include/Utils}/Log/Log_generated.hpp (100%) rename Bigfoot/Sources/{System/Include/System => Utils/Include/Utils}/Log/TargetLogger_generated.hpp.in (94%) rename Bigfoot/Sources/{System/Include/System => Utils/Include/Utils}/Profiler.hpp (96%) create mode 100644 Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp rename Bigfoot/{Tests/System/Include/SystemTests/SystemTestsLogger_generated.hpp => Sources/Utils/Include/Utils/UtilsLogger_generated.hpp} (52%) rename Bigfoot/Sources/{System => Utils}/Log/Log.cpp (98%) rename Bigfoot/Sources/{System => Utils}/MimallocImpl.cpp (99%) create mode 100644 Bigfoot/Tests/Utils/Include/UtilsTests/UtilsTestsLogger_generated.hpp rename Bigfoot/Tests/{System => Utils}/Log/Log.cpp (74%) diff --git a/Bigfoot/Sources/Engine/Include/Engine/EngineLogger_generated.hpp b/Bigfoot/Sources/Engine/Include/Engine/EngineLogger_generated.hpp index e3e58e9..49b6617 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/EngineLogger_generated.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/EngineLogger_generated.hpp @@ -6,7 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_ENGINELOGGER_GENERATED_HPP #define BIGFOOT_ENGINELOGGER_GENERATED_HPP -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED diff --git a/Bigfoot/Sources/System/CMakeLists.txt b/Bigfoot/Sources/System/CMakeLists.txt index c41e1c9..1688ada 100644 --- a/Bigfoot/Sources/System/CMakeLists.txt +++ b/Bigfoot/Sources/System/CMakeLists.txt @@ -2,8 +2,6 @@ get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME) project(${PackageName}) set(PublicDependencies - $<$:quill::quill> - $,mimalloc-asan,mimalloc-static> stduuid::stduuid) set(PrivateDependencies) set(BigfootPublicDependencies @@ -18,10 +16,3 @@ bigfoot_create_package_lib( "") bigfoot_create_logger() - -target_compile_definitions(${PROJECT_NAME} - PUBLIC - $<$:QUILL_NO_EXCEPTIONS> - $<$:QUILL_DISABLE_NON_PREFIXED_MACROS>) -set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/MimallocImpl.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) - diff --git a/Bigfoot/Sources/System/Include/System/SystemLogger_generated.hpp b/Bigfoot/Sources/System/Include/System/SystemLogger_generated.hpp index dcdf934..64b4dc3 100644 --- a/Bigfoot/Sources/System/Include/System/SystemLogger_generated.hpp +++ b/Bigfoot/Sources/System/Include/System/SystemLogger_generated.hpp @@ -6,7 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_SYSTEMLOGGER_GENERATED_HPP #define BIGFOOT_SYSTEMLOGGER_GENERATED_HPP -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED diff --git a/Bigfoot/Sources/Utils/CMakeLists.txt b/Bigfoot/Sources/Utils/CMakeLists.txt index 39cebc8..b8284d1 100644 --- a/Bigfoot/Sources/Utils/CMakeLists.txt +++ b/Bigfoot/Sources/Utils/CMakeLists.txt @@ -2,6 +2,8 @@ get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME) project(${PackageName}) set(PublicDependencies + $<$:quill::quill> + $,mimalloc-asan,mimalloc-static> unordered_dense::unordered_dense) set(PrivateDependencies) set(BigfootPublicDependencies) @@ -12,4 +14,12 @@ bigfoot_create_package_lib( "${PrivateLibraries}" "${BigfootPublicDependencies}" "${BigfootPrivateDependencies}" - "") \ No newline at end of file + "") +set_source_files_properties(../Utils/MimallocImpl.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) + +bigfoot_create_logger() + +target_compile_definitions(${PROJECT_NAME} + PUBLIC + $<$:QUILL_NO_EXCEPTIONS> + $<$:QUILL_DISABLE_NON_PREFIXED_MACROS>) \ No newline at end of file diff --git a/Bigfoot/Sources/Utils/Include/Utils/Assert.hpp b/Bigfoot/Sources/Utils/Include/Utils/Assert.hpp index 45d98af..9a51a0e 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Assert.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Assert.hpp @@ -6,7 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_UTILS_ASSERT_HPP #define BIGFOOT_UTILS_ASSERT_HPP -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED diff --git a/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp b/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp index e5994cf..aa90777 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp @@ -6,5 +6,217 @@ *********************************************************************/ #ifndef BIGFOOT_UTILS_CONTAINERS_SLOTMAP_HPP #define BIGFOOT_UTILS_CONTAINERS_SLOTMAP_HPP +#include + +#include + +#include + +namespace Bigfoot +{ +template +class SlotMap +{ + private: + using IndexType = std::uint32_t; + using VersionType = std::uint32_t; + + public: + struct SlotKey + { + VersionType m_version = 0; + IndexType m_index = 0; + + bool Invalid() const + { + return m_version == 0; + } + + bool operator==(const SlotKey p_key) const + { + return m_version == p_key.m_version && m_index == p_key.m_index; + } + }; + + SlotMap(): + m_freeSlotHead(std::numeric_limits::max()) + { + } + + SlotMap(const SlotMap& p_slotMap) = default; + SlotMap(SlotMap&& p_slotMap) = default; + + template + SlotKey Insert(ARGS&&... p_args) + { + ASSERT(UtilsAssertHandler, + m_data.size() < std::numeric_limits::max(), + "Too many elements for SlotMap!"); + + m_data.emplace_back(std::forward(p_args)...); + + if (m_freeSlotHead != std::numeric_limits::max()) + { + const IndexType freeSlotIndex = m_freeSlotHead; + m_freeSlotHead = m_slots[freeSlotIndex].m_index; + + const VersionType version = m_slots[freeSlotIndex].m_version; + m_slots[freeSlotIndex] = {.m_version = version, .m_index = static_cast(m_data.size()) - 1}; + m_dataToSlots.push_back(freeSlotIndex); + + return {.m_version = version, .m_index = freeSlotIndex}; + } + + const IndexType newSlotIndex = m_slots.size(); + m_slots.push_back({.m_version = 1, .m_index = static_cast(m_data.size()) - 1}); + m_dataToSlots.push_back(newSlotIndex); + + return {.m_version = 1, .m_index = newSlotIndex}; + } + + void Remove(const SlotKey p_key) + { + const IndexType slotIndex = p_key.m_index; + if (slotIndex >= m_slots.size()) + { + return; + } + if (p_key.m_version != m_slots[slotIndex].m_version) + { + return; + } + + const IndexType dataIndex = m_slots[slotIndex].m_index; + m_data.erase_unsorted(m_data.begin() + dataIndex); + m_dataToSlots.erase_unsorted(m_dataToSlots.begin() + dataIndex); + + if (dataIndex < m_data.size()) + { + const IndexType movedSlotIndex = m_dataToSlots[dataIndex]; + m_slots[movedSlotIndex].m_index = dataIndex; + } + + m_slots[slotIndex] = {.m_version = p_key.m_version + 1, .m_index = m_freeSlotHead}; + m_freeSlotHead = slotIndex; + } + + TYPE* Get(const SlotKey p_key) + { + const IndexType slotIndex = p_key.m_index; + if (slotIndex >= m_slots.size()) + { + return nullptr; + } + if (p_key.m_version != m_slots[slotIndex].m_version) + { + return nullptr; + } + return &m_data[m_slots[slotIndex].m_index]; + } + + const TYPE* Get(const SlotKey p_key) const + { + const IndexType slotIndex = p_key.m_index; + if (slotIndex >= m_slots.size()) + { + return nullptr; + } + if (p_key.m_version != m_slots[slotIndex].m_version) + { + return nullptr; + } + return &m_data[m_slots[slotIndex].m_index]; + } + + void Reserve(const std::uint32_t p_size) + { + m_data.reserve(p_size); + m_slots.reserve(p_size); + m_dataToSlots.reserve(p_size); + } + + typename eastl::vector::size_type Size() const + { + return m_data.size(); + } + + typename eastl::vector::size_type Capacity() const + { + return m_data.capacity(); + } + + bool Empty() const + { + return m_data.empty(); + } + + void Clear() + { + m_data.clear(); + m_dataToSlots.clear(); + + for (IndexType i = 0; i < m_slots.size(); ++i) + { + const VersionType newVersion = m_slots[i].m_version + 1; + const IndexType nextFree = i + 1 < static_cast(m_slots.size()) + ? i + 1 + : std::numeric_limits::max(); + m_slots[i] = {.m_version = newVersion, .m_index = nextFree}; + } + + m_freeSlotHead = m_slots.empty() ? std::numeric_limits::max() : 0; + } + + void Reset() + { + m_data.clear(); + m_slots.clear(); + m_dataToSlots.clear(); + m_freeSlotHead = std::numeric_limits::max(); + } + + typename eastl::vector::iterator begin() + { + return m_data.begin(); + } + + typename eastl::vector::iterator end() + { + return m_data.end(); + } + + typename eastl::vector::const_iterator begin() const + { + return m_data.begin(); + } + + typename eastl::vector::const_iterator end() const + { + return m_data.end(); + } + + typename eastl::vector::const_iterator cbegin() const + { + return m_data.cbegin(); + } + + typename eastl::vector::const_iterator cend() const + { + return m_data.cend(); + } + + ~SlotMap() = default; + + SlotMap& operator=(const SlotMap& p_slotMap) = default; + SlotMap& operator=(SlotMap&& p_slotMap) = default; + + private: + eastl::vector m_data; + eastl::vector m_dataToSlots; + eastl::vector m_slots; + + IndexType m_freeSlotHead; +}; +} // namespace Bigfoot #endif diff --git a/Bigfoot/Sources/System/Include/System/Log/EASTLFormatters.hpp b/Bigfoot/Sources/Utils/Include/Utils/Log/EASTLFormatters.hpp similarity index 100% rename from Bigfoot/Sources/System/Include/System/Log/EASTLFormatters.hpp rename to Bigfoot/Sources/Utils/Include/Utils/Log/EASTLFormatters.hpp diff --git a/Bigfoot/Sources/System/Include/System/Log/Log.fbs b/Bigfoot/Sources/Utils/Include/Utils/Log/Log.fbs similarity index 100% rename from Bigfoot/Sources/System/Include/System/Log/Log.fbs rename to Bigfoot/Sources/Utils/Include/Utils/Log/Log.fbs diff --git a/Bigfoot/Sources/System/Include/System/Log/Log.hpp b/Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp similarity index 98% rename from Bigfoot/Sources/System/Include/System/Log/Log.hpp rename to Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp index 63943f1..2e158a6 100644 --- a/Bigfoot/Sources/System/Include/System/Log/Log.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp @@ -4,13 +4,12 @@ * \author Romain BOULLARD * \date October 2025 *********************************************************************/ -#ifndef BIGFOOT_SYSTEM_LOG_HPP -#define BIGFOOT_SYSTEM_LOG_HPP -#include +#ifndef BIGFOOT_UTILS_LOG_HPP +#define BIGFOOT_UTILS_LOG_HPP +#include #if defined BIGFOOT_NOT_OPTIMIZED -#include - +#include #include #include diff --git a/Bigfoot/Sources/System/Include/System/Log/Log_generated.hpp b/Bigfoot/Sources/Utils/Include/Utils/Log/Log_generated.hpp similarity index 100% rename from Bigfoot/Sources/System/Include/System/Log/Log_generated.hpp rename to Bigfoot/Sources/Utils/Include/Utils/Log/Log_generated.hpp diff --git a/Bigfoot/Sources/System/Include/System/Log/TargetLogger_generated.hpp.in b/Bigfoot/Sources/Utils/Include/Utils/Log/TargetLogger_generated.hpp.in similarity index 94% rename from Bigfoot/Sources/System/Include/System/Log/TargetLogger_generated.hpp.in rename to Bigfoot/Sources/Utils/Include/Utils/Log/TargetLogger_generated.hpp.in index fbfa751..7487db3 100644 --- a/Bigfoot/Sources/System/Include/System/Log/TargetLogger_generated.hpp.in +++ b/Bigfoot/Sources/Utils/Include/Utils/Log/TargetLogger_generated.hpp.in @@ -6,7 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_@LOGGER_FILENAME_UPPER@_GENERATED_HPP #define BIGFOOT_@LOGGER_FILENAME_UPPER@_GENERATED_HPP -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED diff --git a/Bigfoot/Sources/System/Include/System/Profiler.hpp b/Bigfoot/Sources/Utils/Include/Utils/Profiler.hpp similarity index 96% rename from Bigfoot/Sources/System/Include/System/Profiler.hpp rename to Bigfoot/Sources/Utils/Include/Utils/Profiler.hpp index 0c02d30..2553d62 100644 --- a/Bigfoot/Sources/System/Include/System/Profiler.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Profiler.hpp @@ -4,8 +4,8 @@ * \author Romain BOULLARD * \date October 2025 *********************************************************************/ -#ifndef BIGFOOT_CONCAT_PROFILER_HPP -#define BIGFOOT_CONCAT_PROFILER_HPP +#ifndef BIGFOOT_UTILS_PROFILER_HPP +#define BIGFOOT_UTILS_PROFILER_HPP #ifdef TRACY #include diff --git a/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp b/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp new file mode 100644 index 0000000..1d8c95e --- /dev/null +++ b/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp @@ -0,0 +1,56 @@ +/********************************************************************* + * \file UtilsAssertHandler.hpp + * + * \author Romain BOULLARD + * \date May 2026 + *********************************************************************/ +#ifndef BIGFOOT_UTILS_UTILSASSERTHANDLER_HPP +#define BIGFOOT_UTILS_UTILSASSERTHANDLER_HPP +#include +#include + +#include + +#if defined BIGFOOT_NOT_OPTIMIZED +#include + +#include +#include +#include + +namespace Bigfoot +{ +class UtilsAssertHandler +{ + public: + UtilsAssertHandler() = delete; + + UtilsAssertHandler(const UtilsAssertHandler& p_handler) = delete; + UtilsAssertHandler(UtilsAssertHandler&& p_handler) = delete; + + ~UtilsAssertHandler() = delete; + + /** + * Handle an assertion. + * + * \param p_location Location of the assertion. + * \param p_format Format string for the assertion message. + * \param p_args Arguments for the format string. + */ + template + static void Handle(const std::source_location& p_location, std::format_string p_format, ARGS&&... p_args) + { + BIGFOOT_LOG_FATAL(UTILS_LOGGER, + "Assert: {} (File:{}, Line:{}, Function:{}\n", + std::format(p_format, std::forward(p_args)...), + p_location.file_name(), + p_location.line(), + p_location.function_name()); + } + + UtilsAssertHandler& operator=(const UtilsAssertHandler& p_handler) = delete; + UtilsAssertHandler& operator=(UtilsAssertHandler&& p_handler) = delete; +}; +} // namespace Bigfoot +#endif +#endif diff --git a/Bigfoot/Tests/System/Include/SystemTests/SystemTestsLogger_generated.hpp b/Bigfoot/Sources/Utils/Include/Utils/UtilsLogger_generated.hpp similarity index 52% rename from Bigfoot/Tests/System/Include/SystemTests/SystemTestsLogger_generated.hpp rename to Bigfoot/Sources/Utils/Include/Utils/UtilsLogger_generated.hpp index abe35cd..0db2942 100644 --- a/Bigfoot/Tests/System/Include/SystemTests/SystemTestsLogger_generated.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/UtilsLogger_generated.hpp @@ -1,12 +1,12 @@ // AUTO-GENERATED DO NOT TOUCH /********************************************************************* - * \file SystemTestsLogger.generated.hpp + * \file UtilsLogger.generated.hpp * *********************************************************************/ -#ifndef BIGFOOT_SYSTEMTESTSLOGGER_GENERATED_HPP -#define BIGFOOT_SYSTEMTESTSLOGGER_GENERATED_HPP -#include +#ifndef BIGFOOT_UTILSLOGGER_GENERATED_HPP +#define BIGFOOT_UTILSLOGGER_GENERATED_HPP +#include #if defined BIGFOOT_NOT_OPTIMIZED @@ -15,7 +15,7 @@ namespace Bigfoot /* * Logger */ -inline Log::LoggerInfo SYSTEMTESTS_LOGGER {"SYSTEMTESTS_LOGGER", Flat::LogLevel::Trace}; +inline Log::LoggerInfo UTILS_LOGGER {"UTILS_LOGGER", Flat::LogLevel::Trace}; } // namespace Bigfoot #endif #endif diff --git a/Bigfoot/Sources/System/Log/Log.cpp b/Bigfoot/Sources/Utils/Log/Log.cpp similarity index 98% rename from Bigfoot/Sources/System/Log/Log.cpp rename to Bigfoot/Sources/Utils/Log/Log.cpp index 56c3715..ed70d1e 100644 --- a/Bigfoot/Sources/System/Log/Log.cpp +++ b/Bigfoot/Sources/Utils/Log/Log.cpp @@ -4,7 +4,7 @@ * \author Romain BOULLARD * \date October 2025 *********************************************************************/ -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED diff --git a/Bigfoot/Sources/System/MimallocImpl.cpp b/Bigfoot/Sources/Utils/MimallocImpl.cpp similarity index 99% rename from Bigfoot/Sources/System/MimallocImpl.cpp rename to Bigfoot/Sources/Utils/MimallocImpl.cpp index 35093e8..71fda4e 100644 --- a/Bigfoot/Sources/System/MimallocImpl.cpp +++ b/Bigfoot/Sources/Utils/MimallocImpl.cpp @@ -4,7 +4,7 @@ * \author Romain BOULLARD * \date October 2025 *********************************************************************/ -#include +#include #if defined BIGFOOT_WINDOWS #pragma comment(linker, "/include:mi_version") diff --git a/Bigfoot/Tests/Engine/Asset/Asset.cpp b/Bigfoot/Tests/Engine/Asset/Asset.cpp index b5166ed..a6e8c01 100644 --- a/Bigfoot/Tests/Engine/Asset/Asset.cpp +++ b/Bigfoot/Tests/Engine/Asset/Asset.cpp @@ -8,8 +8,7 @@ #include -#include - +#include #include #include diff --git a/Bigfoot/Tests/Engine/BigFile/BigFile.cpp b/Bigfoot/Tests/Engine/BigFile/BigFile.cpp index 0a9315f..13a9cfe 100644 --- a/Bigfoot/Tests/Engine/BigFile/BigFile.cpp +++ b/Bigfoot/Tests/Engine/BigFile/BigFile.cpp @@ -8,10 +8,10 @@ #include -#include #include #include +#include #include #include diff --git a/Bigfoot/Tests/System/CMakeLists.txt b/Bigfoot/Tests/System/CMakeLists.txt index b019c51..88b69d7 100644 --- a/Bigfoot/Tests/System/CMakeLists.txt +++ b/Bigfoot/Tests/System/CMakeLists.txt @@ -7,6 +7,4 @@ set(BigfootDependencies bigfoot_create_package_tests( "" - "${BigfootDependencies}") - -bigfoot_create_logger() \ No newline at end of file + "${BigfootDependencies}") \ No newline at end of file diff --git a/Bigfoot/Tests/Utils/CMakeLists.txt b/Bigfoot/Tests/Utils/CMakeLists.txt index d47ef5a..5101201 100644 --- a/Bigfoot/Tests/Utils/CMakeLists.txt +++ b/Bigfoot/Tests/Utils/CMakeLists.txt @@ -6,4 +6,6 @@ set(BigfootDependencies bigfoot_create_package_tests( "" - "${BigfootDependencies}") \ No newline at end of file + "${BigfootDependencies}") + +bigfoot_create_logger() \ No newline at end of file diff --git a/Bigfoot/Tests/Utils/Containers/SlotMap.cpp b/Bigfoot/Tests/Utils/Containers/SlotMap.cpp index 78c774b..1041791 100644 --- a/Bigfoot/Tests/Utils/Containers/SlotMap.cpp +++ b/Bigfoot/Tests/Utils/Containers/SlotMap.cpp @@ -13,7 +13,26 @@ namespace Bigfoot class SlotMapFixture: public ::testing::Test { protected: + SlotMap m_slotMap; }; +TEST_F(SlotMapFixture, Insert) +{ + const SlotMap::SlotKey firstKey = m_slotMap.Insert(64); + const SlotMap::SlotKey secondKey = m_slotMap.Insert(2); + const SlotMap::SlotKey thirdKey = m_slotMap.Insert(42); + m_slotMap.Remove(secondKey); + m_slotMap.Remove(firstKey); + + const SlotMap::SlotKey fourthKey = m_slotMap.Insert(3); + const SlotMap::SlotKey fifthKey = m_slotMap.Insert(65); + + EXPECT_EQ(m_slotMap.Get(firstKey), nullptr); + EXPECT_EQ(m_slotMap.Get(secondKey), nullptr); + EXPECT_EQ(*m_slotMap.Get(thirdKey), 42); + EXPECT_EQ(*m_slotMap.Get(fourthKey), 3); + EXPECT_EQ(*m_slotMap.Get(fifthKey), 65); + EXPECT_EQ(m_slotMap.Get(SlotMap::SlotKey {}), nullptr); +} } // namespace Bigfoot diff --git a/Bigfoot/Tests/Utils/Include/UtilsTests/UtilsTestsLogger_generated.hpp b/Bigfoot/Tests/Utils/Include/UtilsTests/UtilsTestsLogger_generated.hpp new file mode 100644 index 0000000..12c70fb --- /dev/null +++ b/Bigfoot/Tests/Utils/Include/UtilsTests/UtilsTestsLogger_generated.hpp @@ -0,0 +1,21 @@ +// AUTO-GENERATED DO NOT TOUCH + +/********************************************************************* + * \file UtilsTestsLogger.generated.hpp + * + *********************************************************************/ +#ifndef BIGFOOT_UTILSTESTSLOGGER_GENERATED_HPP +#define BIGFOOT_UTILSTESTSLOGGER_GENERATED_HPP +#include + +#if defined BIGFOOT_NOT_OPTIMIZED + +namespace Bigfoot +{ +/* + * Logger + */ +inline Log::LoggerInfo UTILSTESTS_LOGGER {"UTILSTESTS_LOGGER", Flat::LogLevel::Trace}; +} // namespace Bigfoot +#endif +#endif diff --git a/Bigfoot/Tests/System/Log/Log.cpp b/Bigfoot/Tests/Utils/Log/Log.cpp similarity index 74% rename from Bigfoot/Tests/System/Log/Log.cpp rename to Bigfoot/Tests/Utils/Log/Log.cpp index 49a2e21..353de07 100644 --- a/Bigfoot/Tests/System/Log/Log.cpp +++ b/Bigfoot/Tests/Utils/Log/Log.cpp @@ -4,11 +4,11 @@ * \author Romain BOULLARD * \date December 2022 *********************************************************************/ -#include +#include #include -#include +#include #if defined BIGFOOT_NOT_OPTIMIZED @@ -21,7 +21,7 @@ class LogFixture: public ::testing::Test protected: void SetUp() override { - SYSTEMTESTS_LOGGER = {"UTILSTESTS_LOGGER", Flat::LogLevel::Trace}; + UTILSTESTS_LOGGER = {"UTILSTESTS_LOGGER", Flat::LogLevel::Trace}; } static constexpr Flat::LogLevel QuillLogLevelToLogLevel(const quill::LogLevel p_level) @@ -54,18 +54,18 @@ class LogFixture: public ::testing::Test TEST_F(LogFixture, RegisterLogger_ShouldRegisterTheLogger) { - const quill::Logger* logger = m_log.RegisterLogger(SYSTEMTESTS_LOGGER); + const quill::Logger* logger = m_log.RegisterLogger(UTILSTESTS_LOGGER); EXPECT_TRUE(logger); - EXPECT_EQ(logger, m_log.GetLogger(SYSTEMTESTS_LOGGER)); - EXPECT_EQ(logger->get_logger_name(), SYSTEMTESTS_LOGGER.m_name); - EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), SYSTEMTESTS_LOGGER.m_level); + EXPECT_EQ(logger, m_log.GetLogger(UTILSTESTS_LOGGER)); + EXPECT_EQ(logger->get_logger_name(), UTILSTESTS_LOGGER.m_name); + EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), UTILSTESTS_LOGGER.m_level); } /****************************************************************************************/ TEST_F(LogFixture, GetLogger_ShouldReturnNullptrIfTheLoggerDoesNotExist) { - EXPECT_FALSE(m_log.GetLogger(SYSTEMTESTS_LOGGER)); + EXPECT_FALSE(m_log.GetLogger(UTILSTESTS_LOGGER)); } /****************************************************************************************/ @@ -73,17 +73,17 @@ TEST_F(LogFixture, GetLogger_ShouldReturnNullptrIfTheLoggerDoesNotExist) TEST_F(LogFixture, GetLogger_ShouldReturnTheLoggerIfItExists) { [[maybe_unused]] - const quill::Logger* logger = m_log.RegisterLogger(SYSTEMTESTS_LOGGER); - EXPECT_TRUE(m_log.GetLogger(SYSTEMTESTS_LOGGER)); + const quill::Logger* logger = m_log.RegisterLogger(UTILSTESTS_LOGGER); + EXPECT_TRUE(m_log.GetLogger(UTILSTESTS_LOGGER)); } /****************************************************************************************/ TEST_F(LogFixture, ChangeLoggerLogLevel_ShouldChangeTheLoggerLogLevel) { - const quill::Logger* logger = m_log.RegisterLogger(SYSTEMTESTS_LOGGER); + const quill::Logger* logger = m_log.RegisterLogger(UTILSTESTS_LOGGER); - m_log.ChangeLoggerLogLevel(SYSTEMTESTS_LOGGER, Flat::LogLevel::Critical); + m_log.ChangeLoggerLogLevel(UTILSTESTS_LOGGER, Flat::LogLevel::Critical); EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), Flat::LogLevel::Critical); } @@ -92,7 +92,7 @@ TEST_F(LogFixture, ChangeLoggerLogLevel_ShouldChangeTheLoggerLogLevel) TEST_F(LogFixture, LogDebug) { Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_DEBUG(SYSTEMTESTS_LOGGER, "Hello"); + BIGFOOT_LOG_DEBUG(UTILSTESTS_LOGGER, "Hello"); } /****************************************************************************************/ @@ -100,7 +100,7 @@ TEST_F(LogFixture, LogDebug) TEST_F(LogFixture, LogTrace) { Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_TRACE(SYSTEMTESTS_LOGGER, "Hello"); + BIGFOOT_LOG_TRACE(UTILSTESTS_LOGGER, "Hello"); } /****************************************************************************************/ @@ -108,7 +108,7 @@ TEST_F(LogFixture, LogTrace) TEST_F(LogFixture, LogInfo) { Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_INFO(SYSTEMTESTS_LOGGER, "Hello"); + BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "Hello"); } /****************************************************************************************/ @@ -116,7 +116,7 @@ TEST_F(LogFixture, LogInfo) TEST_F(LogFixture, LogWarn) { Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_WARN(SYSTEMTESTS_LOGGER, "Hello"); + BIGFOOT_LOG_WARN(UTILSTESTS_LOGGER, "Hello"); } /****************************************************************************************/ @@ -124,7 +124,7 @@ TEST_F(LogFixture, LogWarn) TEST_F(LogFixture, LogError) { Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_ERROR(SYSTEMTESTS_LOGGER, "Hello"); + BIGFOOT_LOG_ERROR(UTILSTESTS_LOGGER, "Hello"); } /****************************************************************************************/ @@ -132,7 +132,7 @@ TEST_F(LogFixture, LogError) TEST_F(LogFixture, LogFatal) { Singleton::Lifetime singletonLifetime; - BIGFOOT_LOG_FATAL(SYSTEMTESTS_LOGGER, "Hello"); + BIGFOOT_LOG_FATAL(UTILSTESTS_LOGGER, "Hello"); } } // namespace Bigfoot #endif diff --git a/CMake/Utils.cmake b/CMake/Utils.cmake index 5d47e94..f70c70b 100644 --- a/CMake/Utils.cmake +++ b/CMake/Utils.cmake @@ -2,7 +2,7 @@ function(bigfoot_create_logger) set(LOGGER_FILENAME ${PROJECT_NAME}Logger) string(TOUPPER ${PROJECT_NAME}_Logger LOGGER_NAME) string(TOUPPER ${LOGGER_FILENAME} LOGGER_FILENAME_UPPER) - configure_file( ${CMAKE_SOURCE_DIR}/Bigfoot/Sources/System/Include/System/Log/TargetLogger_generated.hpp.in + configure_file( ${CMAKE_SOURCE_DIR}/Bigfoot/Sources/Utils/Include/Utils/Log/TargetLogger_generated.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/Include/${PROJECT_NAME}/${LOGGER_FILENAME}_generated.hpp @ONLY) endfunction()