diff --git a/.clang-tidy b/.clang-tidy index d28ed7a..025a0bd 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,9 +11,12 @@ Checks: > portability-*, -modernize-use-trailing-return-type, + -modernize-use-auto, -readability-avoid-const-params-in-decls, -cppcoreguidelines-macro-usage, - -cppcoreguidelines-avoid-do-while + -cppcoreguidelines-avoid-do-while, + -cppcoreguidelines-pro-bounds-avoid-unchecked-container-access, + -cppcoreguidelines-pro-bounds-pointer-arithmetic ExcludeHeaderFilterRegex: '_generated.*' diff --git a/Bigfoot/Sources/Engine/Asset/AssetBase.cpp b/Bigfoot/Sources/Engine/Asset/AssetBase.cpp index dcdd941..17a34b4 100644 --- a/Bigfoot/Sources/Engine/Asset/AssetBase.cpp +++ b/Bigfoot/Sources/Engine/Asset/AssetBase.cpp @@ -40,14 +40,7 @@ eastl::vector AssetBase::HardReferenceVisitor::GetUUIDs() const { eastl::vector uuids; uuids.reserve(m_uuids.size()); - - std::transform(m_uuids.begin(), - m_uuids.end(), - eastl::back_inserter(uuids), - [](const UUID& p_uuid) - { - return p_uuid; - }); + std::copy(m_uuids.begin(), m_uuids.end(), eastl::back_inserter(uuids)); return uuids; } diff --git a/Bigfoot/Sources/Engine/Asset/AssetContainer.cpp b/Bigfoot/Sources/Engine/Asset/AssetContainer.cpp index 0f160e6..5a94c2e 100644 --- a/Bigfoot/Sources/Engine/Asset/AssetContainer.cpp +++ b/Bigfoot/Sources/Engine/Asset/AssetContainer.cpp @@ -128,10 +128,10 @@ void AssetContainerBase::QueueForRemoval(const UUID& p_uuid) void AssetContainerBase::CancelRemoval(const UUID& p_uuid) { - const auto it = eastl::find(m_pendingRemovalUuids.begin(), m_pendingRemovalUuids.end(), p_uuid); - if (it != m_pendingRemovalUuids.end()) + auto* const pendingIt = eastl::find(m_pendingRemovalUuids.begin(), m_pendingRemovalUuids.end(), p_uuid); + if (pendingIt != m_pendingRemovalUuids.end()) { - m_pendingRemovalUuids.erase_unsorted(it); + m_pendingRemovalUuids.erase_unsorted(pendingIt); } } @@ -160,29 +160,29 @@ bool AssetContainerBase::IsMarkedForRemove(const UUID& p_uuid) AssetContainerBase::Entry* AssetContainerBase::FindEntry(const UUID& p_uuid) { - const auto it = m_uuidToEntry.find(p_uuid); - return it != m_uuidToEntry.end() ? &it->second : nullptr; + const auto entryIt = m_uuidToEntry.find(p_uuid); + return entryIt != m_uuidToEntry.end() ? &entryIt->second : nullptr; } /****************************************************************************************/ const AssetContainerBase::Entry* AssetContainerBase::FindEntry(const UUID& p_uuid) const { - const auto it = m_uuidToEntry.find(p_uuid); - return it != m_uuidToEntry.end() ? &it->second : nullptr; + const auto entryIt = m_uuidToEntry.find(p_uuid); + return entryIt != m_uuidToEntry.end() ? &entryIt->second : nullptr; } /****************************************************************************************/ AssetContainerBase::Entry& AssetContainerBase::GetOrCreateEntry(const UUID& p_uuid) { - auto [it, inserted] = m_uuidToEntry.try_emplace(p_uuid); + auto [entryIt, inserted] = m_uuidToEntry.try_emplace(p_uuid); if (inserted) { - it->second.m_handleSlotKey = m_handles.Insert(this, p_uuid); - it->second.m_handle = m_handles.Get(it->second.m_handleSlotKey); + entryIt->second.m_handleSlotKey = m_handles.Insert(this, p_uuid); + entryIt->second.m_handle = m_handles.Get(entryIt->second.m_handleSlotKey); } - return it->second; + return entryIt->second; } } // namespace Bigfoot diff --git a/Bigfoot/Sources/Engine/BigFile/BigFile.cpp b/Bigfoot/Sources/Engine/BigFile/BigFile.cpp index 0333252..c3efdee 100644 --- a/Bigfoot/Sources/Engine/BigFile/BigFile.cpp +++ b/Bigfoot/Sources/Engine/BigFile/BigFile.cpp @@ -164,15 +164,15 @@ eastl::vector> BigFile::GetAssetFlatbuffers(const eastl static_cast>(assetRequest.Get(0))}; const UUID uuid {rawUUID}; - const auto it = uuidToIndices.find(uuid); + const auto indicesIt = uuidToIndices.find(uuid); ASSERT(EngineAssertHandler, - it != uuidToIndices.end(), + indicesIt != uuidToIndices.end(), "Returned UUID {} not found in requested UUIDs", uuid); const eastl::span flatbuffer = assetRequest.Get(1); - for (const std::size_t index: it->second) + for (const std::size_t index: indicesIt->second) { flatbuffers[index].assign(flatbuffer.begin(), flatbuffer.end()); } @@ -260,16 +260,16 @@ eastl::vector> BigFile::GetAssetsHardReferences(eastl::span< static_cast>(hardReferencesRequest.Get(0))}; const UUID ownerUUID {rawOwnerUUID}; - const auto it = uuidToIndices.find(ownerUUID); + const auto indicesIt = uuidToIndices.find(ownerUUID); ASSERT(EngineAssertHandler, - it != uuidToIndices.end(), + indicesIt != uuidToIndices.end(), "Returned UUID {} not found in requested UUIDs", ownerUUID); const std::span rawHardReference { static_cast>(hardReferencesRequest.Get(1))}; - for (const std::size_t index: it->second) + for (const std::size_t index: indicesIt->second) { hardReferences[index].emplace_back(rawHardReference); } @@ -356,16 +356,16 @@ eastl::vector> BigFile::GetAssetsTime(const static_cast>(timeRequest.Get(0))}; const UUID uuid {rawUUID}; - const auto it = uuidToIndices.find(uuid); + const auto indicesIt = uuidToIndices.find(uuid); ASSERT(EngineAssertHandler, - it != uuidToIndices.end(), + indicesIt != uuidToIndices.end(), "Returned UUID {} not found in requested UUIDs", uuid); const AssetTime assetTime {.m_creationTime = Time {static_cast(timeRequest.Get(1))}, .m_modificationTime = Time {static_cast(timeRequest.Get(2))}}; - for (const std::size_t index: it->second) + for (const std::size_t index: indicesIt->second) { times[index] = assetTime; } @@ -401,6 +401,7 @@ void BigFile::SaveAssetFlatbuffer(const UUID& p_uuid, deleteHardReferencesRequest.Execute(); constexpr std::size_t HARDREF_PARAMS_PER_ROW = 2; + constexpr std::size_t HARDREF_PLACEHOLDER_RESERVE_CHARS_PER_ROW = 8; const std::size_t maxHardRefRowsPerStatement = static_cast( sqlite3_limit(m_db, SQLITE_LIMIT_VARIABLE_NUMBER, -1)) / HARDREF_PARAMS_PER_ROW; @@ -410,7 +411,7 @@ void BigFile::SaveAssetFlatbuffer(const UUID& p_uuid, const std::size_t chunkSize = eastl::min(maxHardRefRowsPerStatement, p_hardReferences.size() - chunkStart); eastl::string hardReferencePlaceholders; - hardReferencePlaceholders.reserve(chunkSize * 8); + hardReferencePlaceholders.reserve(chunkSize * HARDREF_PLACEHOLDER_RESERVE_CHARS_PER_ROW); for (std::size_t i = 0; i < chunkSize; ++i) { if (i > 0) @@ -455,6 +456,8 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span p_uuids, BeginTransaction(); constexpr std::size_t METADATA_PARAMS_PER_ROW = 4; + constexpr std::size_t METADATA_PLACEHOLDER_RESERVE_CHARS_PER_ROW = 14; + constexpr std::size_t ASSET_PLACEHOLDER_RESERVE_CHARS_PER_ROW = 8; const std::size_t maxRowsPerStatement = static_cast( sqlite3_limit(m_db, SQLITE_LIMIT_VARIABLE_NUMBER, -1)) / METADATA_PARAMS_PER_ROW; @@ -464,7 +467,7 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span p_uuids, const std::size_t chunkSize = eastl::min(maxRowsPerStatement, p_uuids.size() - chunkStart); eastl::string metadataPlaceholders; - metadataPlaceholders.reserve(chunkSize * 14); + metadataPlaceholders.reserve(chunkSize * METADATA_PLACEHOLDER_RESERVE_CHARS_PER_ROW); for (std::size_t i = 0; i < chunkSize; ++i) { if (i > 0) @@ -487,7 +490,7 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span p_uuids, metadataRequest.Execute(); eastl::string assetPlaceholders; - assetPlaceholders.reserve(chunkSize * 8); + assetPlaceholders.reserve(chunkSize * ASSET_PLACEHOLDER_RESERVE_CHARS_PER_ROW); for (std::size_t i = 0; i < chunkSize; ++i) { if (i > 0) @@ -542,6 +545,7 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span p_uuids, } constexpr std::size_t HARDREF_PARAMS_PER_ROW = 2; + constexpr std::size_t HARDREF_PLACEHOLDER_RESERVE_CHARS_PER_ROW = 8; const std::size_t maxHardRefRowsPerStatement = static_cast( sqlite3_limit(m_db, SQLITE_LIMIT_VARIABLE_NUMBER, -1)) / HARDREF_PARAMS_PER_ROW; @@ -553,7 +557,7 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span p_uuids, hardReferencePairs.size() - hardRefChunkStart); eastl::string hardReferencePlaceholders; - hardReferencePlaceholders.reserve(hardRefChunkSize * 8); + hardReferencePlaceholders.reserve(hardRefChunkSize * HARDREF_PLACEHOLDER_RESERVE_CHARS_PER_ROW); for (std::size_t i = 0; i < hardRefChunkSize; ++i) { if (i > 0) @@ -601,7 +605,7 @@ BigFile::Request::Request(const BigFile& p_bigFile, const eastl::string_view p_r [[maybe_unused]] const int result = sqlite3_prepare_v2(m_db, p_request.data(), - static_cast(p_request.size()), + static_cast(p_request.size()), &m_statement, nullptr); CRITICAL_ASSERT(EngineAssertHandler, @@ -615,11 +619,11 @@ BigFile::Request::Request(const BigFile& p_bigFile, const eastl::string_view p_r void BigFile::Request::Bind(const std::uint32_t p_index, const std::int32_t p_value) { ASSERT(EngineAssertHandler, - (p_index >= 1) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), + (p_index >= 1U) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), "Invalid index for statement"); [[maybe_unused]] - const int result = sqlite3_bind_int(m_statement, p_index, p_value); + const int result = sqlite3_bind_int(m_statement, static_cast(p_index), p_value); ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db)); } @@ -628,11 +632,11 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const std::int32_t p_va void BigFile::Request::Bind(const std::uint32_t p_index, const std::uint32_t p_value) { ASSERT(EngineAssertHandler, - (p_index >= 1) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), + (p_index >= 1U) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), "Invalid index for statement"); [[maybe_unused]] - const int result = sqlite3_bind_int(m_statement, p_index, p_value); + const int result = sqlite3_bind_int(m_statement, static_cast(p_index), static_cast(p_value)); ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db)); } @@ -641,11 +645,11 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const std::uint32_t p_v void BigFile::Request::Bind(const std::uint32_t p_index, const std::int64_t p_value) { ASSERT(EngineAssertHandler, - (p_index >= 1) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), + (p_index >= 1U) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), "Invalid index for statement"); [[maybe_unused]] - const int result = sqlite3_bind_int64(m_statement, p_index, p_value); + const int result = sqlite3_bind_int64(m_statement, static_cast(p_index), p_value); ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db)); } @@ -654,11 +658,11 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const std::int64_t p_va void BigFile::Request::Bind(const std::uint32_t p_index, const std::uint64_t p_value) { ASSERT(EngineAssertHandler, - (p_index >= 1) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), + (p_index >= 1U) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), "Invalid index for statement"); [[maybe_unused]] - const int result = sqlite3_bind_int64(m_statement, p_index, std::bit_cast(p_value)); + const int result = sqlite3_bind_int64(m_statement, static_cast(p_index), std::bit_cast(p_value)); ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db)); } @@ -667,11 +671,11 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const std::uint64_t p_v void BigFile::Request::Bind(const std::uint32_t p_index, const float p_value) { ASSERT(EngineAssertHandler, - (p_index >= 1) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), + (p_index >= 1U) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), "Invalid index for statement"); [[maybe_unused]] - const int result = sqlite3_bind_double(m_statement, p_index, p_value); + const int result = sqlite3_bind_double(m_statement, static_cast(p_index), p_value); ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db)); } @@ -680,11 +684,11 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const float p_value) void BigFile::Request::Bind(const std::uint32_t p_index, const double p_value) { ASSERT(EngineAssertHandler, - (p_index >= 1) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), + (p_index >= 1U) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), "Invalid index for statement"); [[maybe_unused]] - const int result = sqlite3_bind_double(m_statement, p_index, p_value); + const int result = sqlite3_bind_double(m_statement, static_cast(p_index), p_value); ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db)); } @@ -693,14 +697,14 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const double p_value) void BigFile::Request::Bind(const std::uint32_t p_index, const eastl::string_view p_value, const CopyValue p_copy) { ASSERT(EngineAssertHandler, - (p_index >= 1) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), + (p_index >= 1U) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), "Invalid index for statement"); [[maybe_unused]] const int result = sqlite3_bind_text(m_statement, - p_index, + static_cast(p_index), p_value.data(), - static_cast(p_value.size()), + static_cast(p_value.size()), p_copy ? SQLITE_TRANSIENT : SQLITE_STATIC); ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db)); } @@ -712,14 +716,14 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const CopyValue p_copy) { ASSERT(EngineAssertHandler, - (p_index >= 1) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), + (p_index >= 1U) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), "Invalid index for statement"); [[maybe_unused]] const int result = sqlite3_bind_blob(m_statement, - p_index, + static_cast(p_index), p_value.data(), - static_cast(p_value.size()), + static_cast(p_value.size()), p_copy ? SQLITE_TRANSIENT : SQLITE_STATIC); ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db)); } @@ -760,66 +764,69 @@ BigFile::Request::Column::Column(const Request& p_request, const std::uint32_t p BigFile::Request::Column::operator std::int32_t() const { - return sqlite3_column_int(m_statement, m_index); + return sqlite3_column_int(m_statement, static_cast(m_index)); } /****************************************************************************************/ BigFile::Request::Column::operator std::uint32_t() const { - return sqlite3_column_int(m_statement, m_index); + return sqlite3_column_int(m_statement, static_cast(m_index)); } /****************************************************************************************/ BigFile::Request::Column::operator std::int64_t() const { - return sqlite3_column_int64(m_statement, m_index); + return sqlite3_column_int64(m_statement, static_cast(m_index)); } /****************************************************************************************/ BigFile::Request::Column::operator std::uint64_t() const { - return std::bit_cast(sqlite3_column_int64(m_statement, m_index)); + return std::bit_cast(sqlite3_column_int64(m_statement, static_cast(m_index))); } /****************************************************************************************/ BigFile::Request::Column::operator float() const { - return static_cast(sqlite3_column_double(m_statement, m_index)); + return static_cast(sqlite3_column_double(m_statement, static_cast(m_index))); } /****************************************************************************************/ BigFile::Request::Column::operator double() const { - return sqlite3_column_double(m_statement, m_index); + return sqlite3_column_double(m_statement, static_cast(m_index)); } /****************************************************************************************/ BigFile::Request::Column::operator eastl::string_view() const { - return eastl::string_view {reinterpret_cast(sqlite3_column_text(m_statement, m_index)), - static_cast(sqlite3_column_bytes(m_statement, m_index))}; + return eastl::string_view { + reinterpret_cast(sqlite3_column_text(m_statement, static_cast(m_index))), + static_cast(sqlite3_column_bytes(m_statement, static_cast(m_index)))}; } /****************************************************************************************/ BigFile::Request::Column::operator eastl::span() const { - return eastl::span {static_cast(sqlite3_column_blob(m_statement, m_index)), - static_cast(sqlite3_column_bytes(m_statement, m_index))}; + return eastl::span { + static_cast(sqlite3_column_blob(m_statement, static_cast(m_index))), + static_cast(sqlite3_column_bytes(m_statement, static_cast(m_index)))}; } /****************************************************************************************/ BigFile::Request::Column::operator std::span() const { - return std::span {static_cast(sqlite3_column_blob(m_statement, m_index)), - static_cast(sqlite3_column_bytes(m_statement, m_index))}; + return std::span { + static_cast(sqlite3_column_blob(m_statement, static_cast(m_index))), + static_cast(sqlite3_column_bytes(m_statement, static_cast(m_index)))}; } /****************************************************************************************/ diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp index 8cb03ab..09d0964 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp @@ -26,7 +26,7 @@ template class Asset: public AssetBase { public: - using FLAT_ASSET = typename ASSET::FLAT; + using FLAT_ASSET = ASSET::FLAT; /** * Constructor @@ -67,7 +67,7 @@ class Asset: public AssetBase * \return The asset */ [[nodiscard]] - const typename FLAT_ASSET::NativeTableType& GetAsset() const + const FLAT_ASSET::NativeTableType& GetAsset() const { return m_asset; } @@ -78,7 +78,7 @@ class Asset: public AssetBase * \return The asset */ [[nodiscard]] - typename FLAT_ASSET::NativeTableType& GetAsset() + FLAT_ASSET::NativeTableType& GetAsset() { return m_asset; } @@ -185,7 +185,7 @@ class Asset: public AssetBase /** * The asset */ - typename FLAT_ASSET::NativeTableType m_asset; + FLAT_ASSET::NativeTableType m_asset; /** * The asset header */ diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetBase.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetBase.hpp index 682d58f..661bb86 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetBase.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetBase.hpp @@ -54,13 +54,14 @@ class AssetBase [[nodiscard]] virtual eastl::vector Pack() const = 0; + AssetBase(const AssetBase& p_asset) = delete; + AssetBase& operator=(const AssetBase& p_asset) = delete; + protected: AssetBase() = default; - AssetBase(const AssetBase& p_asset) = delete; AssetBase(AssetBase&& p_asset) = default; - AssetBase& operator=(const AssetBase& p_asset) = delete; AssetBase& operator=(AssetBase&& p_asset) = default; class HardReferenceVisitor: public flatbuffers::IterationVisitor diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp index e607e1c..beeaef0 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp @@ -200,8 +200,12 @@ class AssetContainerBase [[nodiscard]] bool IsMarkedForRemove(const UUID& p_uuid); + AssetContainerBase& operator=(const AssetContainerBase& p_container) = delete; AssetContainerBase& operator=(AssetContainerBase&& p_container) = delete; + AssetContainerBase(const AssetContainerBase& p_container) = delete; + AssetContainerBase(AssetContainerBase&& p_container) = delete; + protected: struct Entry { @@ -223,8 +227,6 @@ class AssetContainerBase AssetContainerBase() = default; - AssetContainerBase(AssetContainerBase&& p_container) = delete; - /* * Finds an entry matching the Asset * @@ -352,7 +354,6 @@ class AssetContainer: public AssetContainerBase m_assets.Remove(p_key); } - private: /* * The assets */ diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp index 049c8f7..91e7078 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp @@ -99,6 +99,8 @@ class AssetLibrary AssetLibrary& operator=(const AssetLibrary& p_library) = default; AssetLibrary& operator=(AssetLibrary&& p_library) = delete; + ~AssetLibrary() = default; + private: // All the asset containers ankerl::unordered_dense::map m_assetContainers; diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetTypeID.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetTypeID.hpp index 6b82dc6..65f0125 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetTypeID.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetTypeID.hpp @@ -15,13 +15,10 @@ using AssetTypeID = std::uint64_t; /****************************************************************************************/ -namespace Flat -{ -namespace Bigfoot +namespace Flat::Bigfoot { struct AssetTypeID; -} -} // namespace Flat +} // namespace Flat::Bigfoot /****************************************************************************************/ diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/Reference.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/Reference.hpp index 4a8a9aa..e458112 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/Reference.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/Reference.hpp @@ -94,7 +94,9 @@ class ReferenceBase return m_uuid == p_reference.m_uuid; } - protected: + private: + friend DERIVED; + ReferenceBase() = default; ReferenceBase(const UUID& p_uuid): @@ -116,7 +118,6 @@ class ReferenceBase { } - private: /** * Get the associated handle container for the asset * Register the reference inside the handle @@ -152,7 +153,6 @@ class ReferenceBase } } - private: /** * The UUID */ diff --git a/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp b/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp index 675ee8f..0ec41d2 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp @@ -60,7 +60,7 @@ class BigFile: public DataAccessor */ void Clear(); - ~BigFile(); + ~BigFile() override; /** * Get an Asset flatbuffer @@ -369,14 +369,14 @@ class BigFile: public DataAccessor /* * The statement */ - sqlite3_stmt* m_statement; + sqlite3_stmt* m_statement = nullptr; }; private: /** * The BigFile DB */ - sqlite3* m_db; + sqlite3* m_db = nullptr; }; #endif } // namespace Bigfoot diff --git a/Bigfoot/Sources/Engine/Include/Engine/EngineAssertHandler.hpp b/Bigfoot/Sources/Engine/Include/Engine/EngineAssertHandler.hpp index acd1598..f16a3a3 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/EngineAssertHandler.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/EngineAssertHandler.hpp @@ -10,7 +10,7 @@ #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED namespace Bigfoot { diff --git a/Bigfoot/Sources/Engine/Include/Engine/Sasquatch/Sasquatch.hpp b/Bigfoot/Sources/Engine/Include/Engine/Sasquatch/Sasquatch.hpp index 47f06dc..734e5bd 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Sasquatch/Sasquatch.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Sasquatch/Sasquatch.hpp @@ -95,7 +95,7 @@ class SasquatchWriter SasquatchWriter& operator=(SasquatchWriter&& p_writer) = delete; private: - static constexpr std::uint64_t PREFETCH_BYTES = 4 * 1024 * 1024; + static constexpr std::uint64_t PREFETCH_BYTES = 4ULL * 1024 * 1024; /** * The number of assets expected @@ -105,7 +105,7 @@ class SasquatchWriter /** * How far into m_file has already been prefetched */ - std::size_t m_prefetchedUpTo; + std::size_t m_prefetchedUpTo = 0; /** * Current write position in the data region @@ -145,6 +145,7 @@ class Sasquatch: public DataAccessor * * \return The header */ + [[nodiscard]] const SasquatchHeader& GetHeader() const; /** diff --git a/Bigfoot/Sources/Engine/Include/Engine/SerializationManager/SerializationManager.hpp b/Bigfoot/Sources/Engine/Include/Engine/SerializationManager/SerializationManager.hpp index 3f6a29a..9ebec1d 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/SerializationManager/SerializationManager.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/SerializationManager/SerializationManager.hpp @@ -28,7 +28,7 @@ void LoadAsset(const UUID& p_uuid); */ void LoadAssets(const eastl::span p_uuids); -#if defined BIGFOOT_TOOLMODE +#ifdef BIGFOOT_TOOLMODE /** * Save an Asset * Fails without saving if a cyclic dependency is detected starting from this asset diff --git a/Bigfoot/Sources/Engine/Sasquatch/Sasquatch.cpp b/Bigfoot/Sources/Engine/Sasquatch/Sasquatch.cpp index 1ed6a21..dc0632e 100644 --- a/Bigfoot/Sources/Engine/Sasquatch/Sasquatch.cpp +++ b/Bigfoot/Sources/Engine/Sasquatch/Sasquatch.cpp @@ -19,10 +19,9 @@ SasquatchWriter::SasquatchWriter(const File& p_file, const std::size_t p_totalFlatbufferBytes, const std::size_t p_totalHardReferencesBytes): m_assetCount(p_assetCount), - m_prefetchedUpTo(0), - m_currentDataOffset(sizeof(SasquatchHeader) + m_assetCount * sizeof(SasquatchEntry)), + m_currentDataOffset(sizeof(SasquatchHeader) + (m_assetCount * sizeof(SasquatchEntry))), m_file(p_file, - sizeof(SasquatchHeader) + m_assetCount * sizeof(SasquatchEntry) + p_totalFlatbufferBytes + + sizeof(SasquatchHeader) + (m_assetCount * sizeof(SasquatchEntry)) + p_totalFlatbufferBytes + p_totalHardReferencesBytes) { m_entries.reserve(m_assetCount); @@ -68,11 +67,11 @@ void SasquatchWriter::WriteAsset(const UUID& p_uuid, const eastl::span data = m_file.GetData(); ASSERT(EngineAssertHandler, - offset + p_flatbuffer.size() + p_hardReferences.size() * UUID::UUID_BYTE_SIZE <= data.size(), + offset + p_flatbuffer.size() + (p_hardReferences.size() * UUID::UUID_BYTE_SIZE) <= data.size(), "SasquatchWriter can only write {} bytes", data.size()); - const std::size_t writeEnd = offset + p_flatbuffer.size() + p_hardReferences.size() * UUID::UUID_BYTE_SIZE; + const std::size_t writeEnd = offset + p_flatbuffer.size() + (p_hardReferences.size() * UUID::UUID_BYTE_SIZE); if (writeEnd > m_prefetchedUpTo) { const std::size_t prefetchEnd = std::min(writeEnd + PREFETCH_BYTES, data.size()); @@ -92,7 +91,7 @@ void SasquatchWriter::WriteAsset(const UUID& p_uuid, for (std::uint32_t i = 0; i < p_hardReferences.size(); ++i) { const std::span rawUUID = p_hardReferences[i].ToBytes(); - std::memcpy(data.data() + entry.m_hardReferencesOffset + i * UUID::UUID_BYTE_SIZE, + std::memcpy(data.data() + entry.m_hardReferencesOffset + (static_cast(i) * UUID::UUID_BYTE_SIZE), rawUUID.data(), UUID::UUID_BYTE_SIZE); } @@ -129,11 +128,11 @@ Sasquatch::Sasquatch(const File& p_file): SasquatchHeader::VERSION); CRITICAL_ASSERT(EngineAssertHandler, - data.size() >= sizeof(SasquatchHeader) + m_header.m_assetCount * sizeof(SasquatchEntry), + data.size() >= sizeof(SasquatchHeader) + (m_header.m_assetCount * sizeof(SasquatchEntry)), "Sasquatch file {} index is truncated (got {} / expected at least {})", p_file.GetPath(), data.size(), - sizeof(SasquatchHeader) + m_header.m_assetCount * sizeof(SasquatchEntry)); + sizeof(SasquatchHeader) + (m_header.m_assetCount * sizeof(SasquatchEntry))); eastl::vector entries(m_header.m_assetCount); if (!entries.empty()) @@ -168,15 +167,15 @@ const SasquatchHeader& Sasquatch::GetHeader() const eastl::vector Sasquatch::GetAssetFlatbuffer(const UUID& p_uuid) const { - const auto it = m_entries.find(p_uuid); - if (it == m_entries.end()) + const auto entryIt = m_entries.find(p_uuid); + if (entryIt == m_entries.end()) { return {}; } const eastl::span data = m_file.GetData(); - const eastl::span bytes {data.data() + it->second.m_assetOffset, - static_cast(it->second.m_assetSize)}; + const eastl::span bytes {data.data() + entryIt->second.m_assetOffset, + static_cast(entryIt->second.m_assetSize)}; return eastl::vector {bytes.begin(), bytes.end()}; } @@ -201,15 +200,15 @@ eastl::vector Sasquatch::GetAssetHardReferences(const UUID& p_uuid) const { eastl::vector hardReferences; - const auto it = m_entries.find(p_uuid); - if (it == m_entries.end()) + const auto entryIt = m_entries.find(p_uuid); + if (entryIt == m_entries.end()) { return hardReferences; } const eastl::span data = m_file.GetData(); - const eastl::span bytes {data.data() + it->second.m_hardReferencesOffset, - static_cast(it->second.m_hardReferencesSize)}; + const eastl::span bytes {data.data() + entryIt->second.m_hardReferencesOffset, + static_cast(entryIt->second.m_hardReferencesSize)}; const std::size_t hardReferenceCount = bytes.size() / UUID::UUID_BYTE_SIZE; hardReferences.reserve(hardReferenceCount); @@ -217,7 +216,7 @@ eastl::vector Sasquatch::GetAssetHardReferences(const UUID& p_uuid) const for (std::size_t i = 0; i < hardReferenceCount; ++i) { std::array rawUUID; - std::memcpy(rawUUID.data(), bytes.data() + i * UUID::UUID_BYTE_SIZE, UUID::UUID_BYTE_SIZE); + std::memcpy(rawUUID.data(), bytes.data() + (i * UUID::UUID_BYTE_SIZE), UUID::UUID_BYTE_SIZE); hardReferences.emplace_back(rawUUID); } @@ -261,7 +260,7 @@ void Sasquatch::SaveAssetFlatbuffers([[maybe_unused]] const eastl::span p_uuids) AssetContainerBase* container = g_activeAssetLibrary->GetAssetContainer( flatbuffers::UnPack(*asset->header()->type_id())); + CRITICAL_ASSERT(EngineAssertHandler, + container != nullptr, + "No AssetContainer registered for asset {}", + wave[i]); std::ignore = container->Insert(flatbuffer); } } @@ -118,7 +122,7 @@ void LoadAsset(const UUID& p_uuid) /****************************************************************************************/ -#if defined BIGFOOT_TOOLMODE +#ifdef BIGFOOT_TOOLMODE /* * Finds the cyclic dependencies that may exist in Assets * @@ -183,6 +187,7 @@ eastl::vector FindCyclicDependencies(const eastl::span p_uuids bool SaveAsset(const UUID& p_uuid) { AssetContainerBase* container = g_activeAssetLibrary->GetAssetContainer(p_uuid); + CRITICAL_ASSERT(EngineAssertHandler, container != nullptr, "No AssetContainer registered for asset {}", p_uuid); const AssetBase* asset = container->AcquireContainerHandle(p_uuid)->GetAsset(); const eastl::vector flatbuffer = asset->Pack(); @@ -217,6 +222,7 @@ bool SaveAssets(const eastl::span p_uuids) for (const UUID& uuid: p_uuids) { AssetContainerBase* container = g_activeAssetLibrary->GetAssetContainer(uuid); + CRITICAL_ASSERT(EngineAssertHandler, container != nullptr, "No AssetContainer registered for asset {}", uuid); const AssetBase* asset = container->AcquireContainerHandle(uuid)->GetAsset(); const eastl::vector flatbuffer = asset->Pack(); diff --git a/Bigfoot/Sources/System/File/File.cpp b/Bigfoot/Sources/System/File/File.cpp index 66dbc96..b82c669 100644 --- a/Bigfoot/Sources/System/File/File.cpp +++ b/Bigfoot/Sources/System/File/File.cpp @@ -112,8 +112,8 @@ void File::Delete() const /****************************************************************************************/ -File::File(const std::filesystem::path& p_path): - m_path(p_path), +File::File(std::filesystem::path p_path): + m_path(std::move(p_path)), m_pathString(m_path.string().c_str()) { } diff --git a/Bigfoot/Sources/System/File/MemoryMappedFile.cpp b/Bigfoot/Sources/System/File/MemoryMappedFile.cpp index 245cdfd..190b968 100644 --- a/Bigfoot/Sources/System/File/MemoryMappedFile.cpp +++ b/Bigfoot/Sources/System/File/MemoryMappedFile.cpp @@ -10,7 +10,7 @@ #include -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS #include #elif defined BIGFOOT_LINUX #include @@ -26,7 +26,7 @@ MemoryMappedFile::MemoryMappedFile(const File& p_file) const File absoluteFile = p_file.ToAbsolute(); const eastl::string_view path = absoluteFile.GetPath(); -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS m_fileHandle = CreateFileA(path.data(), GENERIC_READ, FILE_SHARE_READ, @@ -78,7 +78,7 @@ MemoryMappedFile::MemoryMappedFile(const File& p_file) MemoryMappedFile::~MemoryMappedFile() { -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS if (m_data != nullptr) { [[maybe_unused]] @@ -133,7 +133,7 @@ WritableMemoryMappedFile::WritableMemoryMappedFile(const File& p_file, const std const File absoluteFile = p_file.ToAbsolute(); const eastl::string_view path = absoluteFile.GetPath(); -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS m_fileHandle = CreateFileA(path.data(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); CRITICAL_ASSERT(SystemAssertHandler, m_fileHandle != INVALID_HANDLE_VALUE, "Failed to create file {}", path); @@ -169,7 +169,7 @@ WritableMemoryMappedFile::WritableMemoryMappedFile(const File& p_file, const std WritableMemoryMappedFile::~WritableMemoryMappedFile() { -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS if (m_data != nullptr) { [[maybe_unused]] @@ -220,7 +220,7 @@ eastl::span WritableMemoryMappedFile::GetData() const void WritableMemoryMappedFile::Prefetch(const std::size_t p_offset, const std::size_t p_size) const { -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS WIN32_MEMORY_RANGE_ENTRY range {.VirtualAddress = m_data + p_offset, .NumberOfBytes = p_size}; [[maybe_unused]] const BOOL prefetched = PrefetchVirtualMemory(GetCurrentProcess(), 1, &range, 0); diff --git a/Bigfoot/Sources/System/Include/System/File/File.hpp b/Bigfoot/Sources/System/Include/System/File/File.hpp index 5ef2d42..aae0d40 100644 --- a/Bigfoot/Sources/System/Include/System/File/File.hpp +++ b/Bigfoot/Sources/System/Include/System/File/File.hpp @@ -112,7 +112,7 @@ class File * * \param p_path The path */ - File(const std::filesystem::path& p_path); + File(std::filesystem::path p_path); /** * The path diff --git a/Bigfoot/Sources/System/Include/System/File/MemoryMappedFile.hpp b/Bigfoot/Sources/System/Include/System/File/MemoryMappedFile.hpp index 84576f2..326f6d2 100644 --- a/Bigfoot/Sources/System/Include/System/File/MemoryMappedFile.hpp +++ b/Bigfoot/Sources/System/Include/System/File/MemoryMappedFile.hpp @@ -47,7 +47,7 @@ class MemoryMappedFile MemoryMappedFile& operator=(MemoryMappedFile&& p_file) = delete; private: -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS /** * Handle to the file */ @@ -118,7 +118,7 @@ class WritableMemoryMappedFile WritableMemoryMappedFile& operator=(WritableMemoryMappedFile&& p_file) = delete; private: -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS /** * Handle to the file */ diff --git a/Bigfoot/Sources/System/Include/System/SystemAssertHandler.hpp b/Bigfoot/Sources/System/Include/System/SystemAssertHandler.hpp index f0bb121..d10732d 100644 --- a/Bigfoot/Sources/System/Include/System/SystemAssertHandler.hpp +++ b/Bigfoot/Sources/System/Include/System/SystemAssertHandler.hpp @@ -10,7 +10,7 @@ #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED namespace Bigfoot { diff --git a/Bigfoot/Sources/System/Include/System/Time/Time.hpp b/Bigfoot/Sources/System/Include/System/Time/Time.hpp index 0c68759..03709ad 100644 --- a/Bigfoot/Sources/System/Include/System/Time/Time.hpp +++ b/Bigfoot/Sources/System/Include/System/Time/Time.hpp @@ -65,13 +65,10 @@ class Time /****************************************************************************************/ -namespace Flat -{ -namespace Bigfoot +namespace Flat::Bigfoot { struct Time; -} -} // namespace Flat +} // namespace Flat::Bigfoot /****************************************************************************************/ diff --git a/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp b/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp index 3880c4c..42c57f1 100644 --- a/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp +++ b/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp @@ -121,12 +121,12 @@ struct std::hash template<> struct fmt::formatter { - constexpr auto parse(format_parse_context& ctx) + static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - auto format(const Bigfoot::UUID& p_uuid, format_context& ctx) const + static auto format(const Bigfoot::UUID& p_uuid, format_context& ctx) { return fmt::format_to(ctx.out(), "{}", p_uuid.ToString().c_str()); } @@ -159,13 +159,10 @@ struct quill::Codec: quill::DeferredFormatCodec /****************************************************************************************/ -namespace Flat -{ -namespace Bigfoot +namespace Flat::Bigfoot { struct UUID; -} -} // namespace Flat +} // namespace Flat::Bigfoot /****************************************************************************************/ diff --git a/Bigfoot/Sources/Tools/Executables/SasquatchBaker/main.cpp b/Bigfoot/Sources/Tools/Executables/SasquatchBaker/main.cpp index b36d07f..d4539c0 100644 --- a/Bigfoot/Sources/Tools/Executables/SasquatchBaker/main.cpp +++ b/Bigfoot/Sources/Tools/Executables/SasquatchBaker/main.cpp @@ -25,20 +25,21 @@ int main(int argc, char** argv) std::string bigFilePath; std::string outputPath; - auto cli = lyra::help(showHelp) | - lyra::opt(bigFilePath, "bigfile")["-b"]["--bigfile"]("The BigFile to bake (must exist)").required() | - lyra::opt(outputPath, "output")["-o"]["--output"]("The Sasquatch file to write").required(); + const auto& cli = lyra::help(showHelp) | + lyra::opt(bigFilePath, "bigfile")["-b"]["--bigfile"]("The BigFile to bake (must exist)") + .required() | + lyra::opt(outputPath, "output")["-o"]["--output"]("The Sasquatch file to write").required(); const lyra::parse_result result = cli.parse({argc, argv}); if (!result) { - std::cerr << result.message() << "\n\n" << cli << std::endl; + std::cerr << result.message() << "\n\n" << cli << '\n'; return 1; } if (showHelp) { - std::cout << cli << std::endl; + std::cout << cli << '\n'; return 0; } diff --git a/Bigfoot/Sources/Tools/SasquatchBaker/Include/SasquatchBaker/SasquatchBakerAssertHandler.hpp b/Bigfoot/Sources/Tools/SasquatchBaker/Include/SasquatchBaker/SasquatchBakerAssertHandler.hpp index fbde209..b3b4aad 100644 --- a/Bigfoot/Sources/Tools/SasquatchBaker/Include/SasquatchBaker/SasquatchBakerAssertHandler.hpp +++ b/Bigfoot/Sources/Tools/SasquatchBaker/Include/SasquatchBaker/SasquatchBakerAssertHandler.hpp @@ -10,7 +10,7 @@ #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED namespace Bigfoot { diff --git a/Bigfoot/Sources/Utils/Include/Utils/Algorithm/Graph.hpp b/Bigfoot/Sources/Utils/Include/Utils/Algorithm/Graph.hpp index 40a2947..8734c60 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Algorithm/Graph.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Algorithm/Graph.hpp @@ -67,11 +67,11 @@ bool LayeredTopologicalSort(const ankerl::unordered_dense::mapsecond + 1]; + ++adjacencyOffsets[nodeIt->second + 1]; } } @@ -93,10 +93,10 @@ bool LayeredTopologicalSort(const ankerl::unordered_dense::mapsecond]++] = index; + adjacency[cursor[nodeIt->second]++] = index; } } } diff --git a/Bigfoot/Sources/Utils/Include/Utils/Assert/Assert.hpp b/Bigfoot/Sources/Utils/Include/Utils/Assert/Assert.hpp index 2181e09..2da6ee6 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Assert/Assert.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Assert/Assert.hpp @@ -9,7 +9,7 @@ #include #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED #include @@ -19,11 +19,11 @@ #include #include -#if defined BIGFOOT_LINUX +#ifdef BIGFOOT_LINUX #include #endif -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS #define BREAK \ do \ { \ diff --git a/Bigfoot/Sources/Utils/Include/Utils/Assert/AssertHandler.hpp b/Bigfoot/Sources/Utils/Include/Utils/Assert/AssertHandler.hpp index e8b4b1d..e772d71 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Assert/AssertHandler.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Assert/AssertHandler.hpp @@ -9,7 +9,7 @@ #include #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED #include diff --git a/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp b/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp index ba7ff18..be8074f 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp @@ -28,7 +28,7 @@ class SlotMapKey private: static constexpr std::uint32_t VERSION_BIT_COUNT = sizeof(VersionType) * std::numeric_limits::digits; static constexpr std::uint32_t INDEX_BIT_COUNT = sizeof(IndexType) * std::numeric_limits::digits; - static_assert(VERSION_BIT_COUNT + INDEX_BIT_COUNT <= 64, + static_assert(VERSION_BIT_COUNT + INDEX_BIT_COUNT <= std::numeric_limits::digits, "We cant construct a 64 bit key from the given Version and Index types!"); static constexpr std::uint64_t INDEX_MASK = (static_cast(1) << INDEX_BIT_COUNT) - 1; @@ -115,10 +115,10 @@ class DenseSlotMap public: using SlotMapKey = SLOT_MAP_KEY_TYPE; - using iterator = typename eastl::vector::iterator; - using const_iterator = typename eastl::vector::const_iterator; - using reverse_iterator = typename eastl::vector::reverse_iterator; - using const_reverse_iterator = typename eastl::vector::const_reverse_iterator; + using iterator = eastl::vector::iterator; + using const_iterator = eastl::vector::const_iterator; + using reverse_iterator = eastl::vector::reverse_iterator; + using const_reverse_iterator = eastl::vector::const_reverse_iterator; /** * Check if the map has the key @@ -402,7 +402,6 @@ class DenseSlotMap m_freeListHead = p_key.GetIndex(); } - private: /** * The actual storage for our data */ @@ -431,12 +430,13 @@ class DenseSlotMap template> class StableSlotMap { - private: + public: static constexpr std::size_t PAGE_SIZE = 64; + private: struct AlignedSlot { - alignas(T) std::byte m_bytes[sizeof(T)]; + alignas(T) eastl::array m_bytes; }; struct Page @@ -467,7 +467,7 @@ class StableSlotMap T* Get(const std::size_t p_offset) { ASSERT(UtilsAssertHandler, m_occupied[p_offset], "Requesting a dead data!"); - return std::launder(reinterpret_cast(m_data[p_offset].m_bytes)); + return std::launder(reinterpret_cast(m_data[p_offset].m_bytes.data())); } /** @@ -479,7 +479,7 @@ class StableSlotMap const T* Get(const std::size_t p_offset) const { ASSERT(UtilsAssertHandler, m_occupied[p_offset], "Requesting a dead data!"); - return std::launder(reinterpret_cast(m_data[p_offset].m_bytes)); + return std::launder(reinterpret_cast(m_data[p_offset].m_bytes.data())); } /** @@ -527,7 +527,8 @@ class StableSlotMap IteratorImpl() = default; // Allows an iterator to be implicitly used as a const_iterator. - template>> + template + requires std::is_same_v IteratorImpl(const IteratorImpl& p_other): m_map(p_other.m_map), m_pageIt(p_other.m_pageIt), @@ -777,7 +778,7 @@ class StableSlotMap Page* const page = GetPageAt(pageIndex); const std::size_t offsetInPage = GetDataOffset(key); - new (page->m_data[offsetInPage].m_bytes) T(std::forward(p_args)...); + new (page->m_data[offsetInPage].m_bytes.data()) T(std::forward(p_args)...); page->m_occupied.set(offsetInPage); return key; @@ -835,7 +836,7 @@ class StableSlotMap { std::destroy_at(page->Get(offset)); - const std::size_t keyIndex = pageIndex * PAGE_SIZE + offset; + const std::size_t keyIndex = (pageIndex * PAGE_SIZE) + offset; RecycleKey(SlotMapKey {m_keys[keyIndex].GetVersion(), static_cast(keyIndex)}); } page->m_occupied.reset(); @@ -870,9 +871,9 @@ class StableSlotMap [[nodiscard]] iterator begin() { - iterator it {this}; - it.SeekFirstFrom(m_pages.begin()); - return it; + iterator result {this}; + result.SeekFirstFrom(m_pages.begin()); + return result; } [[nodiscard]] @@ -884,9 +885,9 @@ class StableSlotMap [[nodiscard]] const_iterator begin() const { - const_iterator it {this}; - it.SeekFirstFrom(m_pages.begin()); - return it; + const_iterator result {this}; + result.SeekFirstFrom(m_pages.begin()); + return result; } [[nodiscard]] @@ -1024,7 +1025,6 @@ class StableSlotMap return m_pages[p_pageIndex].get(); } - private: /** * The pages */ diff --git a/Bigfoot/Sources/Utils/Include/Utils/Log/EASTLFormatters.hpp b/Bigfoot/Sources/Utils/Include/Utils/Log/EASTLFormatters.hpp index be5492e..153e15f 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Log/EASTLFormatters.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Log/EASTLFormatters.hpp @@ -8,7 +8,7 @@ #define BIGFOOT_UTILS_LOG_EASTLFORMATTERS_HPP #include -#if defined(BIGFOOT_NOT_OPTIMIZED) +#ifdef BIGFOOT_NOT_OPTIMIZED #include #endif @@ -24,27 +24,27 @@ template<> struct fmt::formatter { - constexpr auto parse(format_parse_context& ctx) + static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - auto format(const eastl::string& p_string, format_context& ctx) const + static auto format(const eastl::string& p_string, format_context& ctx) { return fmt::format_to(ctx.out(), "{}", p_string.c_str()); } }; -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED template<> struct fmtquill::formatter { - constexpr auto parse(format_parse_context& ctx) + static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - auto format(const eastl::string& p_string, format_context& ctx) const + static auto format(const eastl::string& p_string, format_context& ctx) { return fmtquill::format_to(ctx.out(), "{}", p_string.c_str()); } @@ -56,27 +56,27 @@ struct fmtquill::formatter template<> struct fmt::formatter { - constexpr auto parse(format_parse_context& ctx) + static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - auto format(const eastl::string_view& p_stringView, format_context& ctx) const + static auto format(const eastl::string_view& p_stringView, format_context& ctx) { return fmt::format_to(ctx.out(), "{}", p_stringView.data()); } }; -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED template<> struct fmtquill::formatter { - constexpr auto parse(format_parse_context& ctx) + static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - auto format(const eastl::string_view& p_stringView, format_context& ctx) const + static auto format(const eastl::string_view& p_stringView, format_context& ctx) { return fmtquill::format_to(ctx.out(), "{}", p_stringView.data()); } @@ -141,7 +141,7 @@ struct fmt::formatter> } }; -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED #include template diff --git a/Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp b/Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp index c7180aa..5a77d0e 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Log/Log.hpp @@ -8,7 +8,7 @@ #define BIGFOOT_UTILS_LOG_LOG_HPP #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED #include #include @@ -23,7 +23,7 @@ #include #include #include -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS #pragma warning(default: 4702) #endif @@ -61,7 +61,7 @@ class Log * * \param p_loggerInfo The logger to unregister */ - void UnregisterLogger(const LoggerInfo& p_loggerInfo); + static void UnregisterLogger(const LoggerInfo& p_loggerInfo); /** * Register a logger. @@ -84,7 +84,7 @@ class Log * Flush all the loggers * */ - void Flush(); + static void Flush(); ~Log(); diff --git a/Bigfoot/Sources/Utils/Include/Utils/Log/LogMacros.hpp b/Bigfoot/Sources/Utils/Include/Utils/Log/LogMacros.hpp index 08d3a10..2ec7a1f 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Log/LogMacros.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Log/LogMacros.hpp @@ -9,7 +9,7 @@ #include #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED #define BIGFOOT_FLUSH_LOG \ do \ { \ @@ -111,7 +111,7 @@ #define BIGFOOT_LOG_FATAL(loggerName, fmt, ...) #endif -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED #define BIGFOOT_LOG_DEBUG_IF(condition, loggerName, fmt, ...) \ do \ { \ diff --git a/Bigfoot/Sources/Utils/Include/Utils/TargetMacros.h b/Bigfoot/Sources/Utils/Include/Utils/TargetMacros.h index fceadb8..e067fe2 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/TargetMacros.h +++ b/Bigfoot/Sources/Utils/Include/Utils/TargetMacros.h @@ -7,15 +7,15 @@ #ifndef BIGFOOT_UTILS_TARGETMACROS_H #define BIGFOOT_UTILS_TARGETMACROS_H -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS #define BIGFOOT_WINDOWS_OR_LINUX(p_windows, p_linux) p_windows #endif -#if defined BIGFOOT_LINUX +#ifdef BIGFOOT_LINUX #define BIGFOOT_WINDOWS_OR_LINUX(p_windows, p_linux) p_linux #endif -#if defined BIGFOOT_WINDOWS +#ifdef BIGFOOT_WINDOWS #define BIGFOOT_ALWAYS_INLINE [[msvc::forceinline]] #elif defined BIGFOOT_LINUX #define BIGFOOT_ALWAYS_INLINE [[gnu::always_inline]] inline @@ -33,13 +33,13 @@ #define BIGFOOT_OPTIMIZED_OR_NOT(p_optimized, p_notOptimized) p_notOptimized #endif -#if defined BIGFOOT_TOOLMODE +#ifdef BIGFOOT_TOOLMODE #define BIGFOOT_TOOLMODE_ONLY(...) __VA_ARGS__ #define BIGFOOT_GAME_ONLY(...) #define BIGFOOT_GAME_OR_TOOLMODE(p_game, p_toolmode) p_toolmode #endif -#if defined BIGFOOT_GAME +#ifdef BIGFOOT_GAME #define BIGFOOT_TOOLMODE_ONLY(...) #define BIGFOOT_GAME_ONLY(...) __VA_ARGS__ #define BIGFOOT_GAME_OR_TOOLMODE(p_game, p_toolmode) p_game diff --git a/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp b/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp index 507889b..05825f4 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp @@ -9,7 +9,7 @@ #include #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED namespace Bigfoot { diff --git a/Bigfoot/Tests/Engine/Asset/AssetContainer.cpp b/Bigfoot/Tests/Engine/Asset/AssetContainer.cpp index 4d2eea2..d63e076 100644 --- a/Bigfoot/Tests/Engine/Asset/AssetContainer.cpp +++ b/Bigfoot/Tests/Engine/Asset/AssetContainer.cpp @@ -24,7 +24,7 @@ class ContainerHandleFixture: public ::testing::Test AssetContainer m_containerA; UUID m_uuid; - ContainerHandle* m_handle; + ContainerHandle* m_handle = nullptr; }; /****************************************************************************************/ diff --git a/Bigfoot/Tests/Engine/Asset/Reference.cpp b/Bigfoot/Tests/Engine/Asset/Reference.cpp index 31bb444..2732bc0 100644 --- a/Bigfoot/Tests/Engine/Asset/Reference.cpp +++ b/Bigfoot/Tests/Engine/Asset/Reference.cpp @@ -66,7 +66,7 @@ class ReferenceTypeNameGenerator { public: template - static std::string GetName(int) + static std::string GetName([[maybe_unused]] int p_index) { if constexpr (std::is_same_v>) { diff --git a/Bigfoot/Tests/Engine/DataAccessor/DataAccessor.cpp b/Bigfoot/Tests/Engine/DataAccessor/DataAccessor.cpp index f68d222..0171a40 100644 --- a/Bigfoot/Tests/Engine/DataAccessor/DataAccessor.cpp +++ b/Bigfoot/Tests/Engine/DataAccessor/DataAccessor.cpp @@ -26,7 +26,7 @@ class DataAccessorFixture: public ::testing::Test } DataAccessorMock m_accessor; - DataAccessor* m_original; + DataAccessor* m_original = nullptr; }; /****************************************************************************************/ diff --git a/Bigfoot/Tests/Engine/SerializationManager/SerializationManager.cpp b/Bigfoot/Tests/Engine/SerializationManager/SerializationManager.cpp index 2af0736..570605e 100644 --- a/Bigfoot/Tests/Engine/SerializationManager/SerializationManager.cpp +++ b/Bigfoot/Tests/Engine/SerializationManager/SerializationManager.cpp @@ -9,7 +9,7 @@ #include #include -#if defined BIGFOOT_TOOLMODE +#ifdef BIGFOOT_TOOLMODE #include #include @@ -114,7 +114,7 @@ class SerializationManagerFixture: public ::testing::Test */ void Populate(const eastl::vector& p_assets) { -#if defined BIGFOOT_TOOLMODE +#ifdef BIGFOOT_TOOLMODE m_bigFile.emplace(File {BIGFILE_ENGINETESTS_LOCATION}); m_bigFile->Clear(); @@ -200,7 +200,7 @@ class SerializationManagerFixture: public ::testing::Test UUID m_multiRootBUUID; eastl::vector m_multiRootBFlatbuffer; -#if defined BIGFOOT_TOOLMODE +#ifdef BIGFOOT_TOOLMODE eastl::optional m_bigFile; #elif defined BIGFOOT_GAME eastl::optional m_sasquatch; diff --git a/Bigfoot/Tests/System/UUID/UUID.cpp b/Bigfoot/Tests/System/UUID/UUID.cpp index bb6c26d..6d116e8 100644 --- a/Bigfoot/Tests/System/UUID/UUID.cpp +++ b/Bigfoot/Tests/System/UUID/UUID.cpp @@ -175,10 +175,10 @@ TEST_F(UUIDFixture, GeneratingFiveMillionUniqueID) TEST_F(UUIDFixture, ToBytes_ShouldGiveBackTheRawDataOfTheID) { - std::span d = m_d.ToBytes(); + std::span idBytes = m_d.ToBytes(); std::span raw = m_raw; - EXPECT_THAT(d, ::testing::ElementsAreArray(raw)); + EXPECT_THAT(idBytes, ::testing::ElementsAreArray(raw)); } /****************************************************************************************/ diff --git a/Bigfoot/Tests/Utils/Assert/Assert.cpp b/Bigfoot/Tests/Utils/Assert/Assert.cpp index ad11a53..d9b9ef9 100644 --- a/Bigfoot/Tests/Utils/Assert/Assert.cpp +++ b/Bigfoot/Tests/Utils/Assert/Assert.cpp @@ -8,7 +8,7 @@ #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED #include diff --git a/Bigfoot/Tests/Utils/Assert/AssertHandler.cpp b/Bigfoot/Tests/Utils/Assert/AssertHandler.cpp index 5645a9f..c267eef 100644 --- a/Bigfoot/Tests/Utils/Assert/AssertHandler.cpp +++ b/Bigfoot/Tests/Utils/Assert/AssertHandler.cpp @@ -11,7 +11,7 @@ #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED #include #include @@ -26,7 +26,7 @@ namespace Bigfoot class AssertHandlerFixture: public ::testing::Test { protected: - std::string ReadFileSinkContent() + static std::string ReadFileSinkContent() { Singleton::GetInstance().Flush(); diff --git a/Bigfoot/Tests/Utils/Containers/SlotMap.cpp b/Bigfoot/Tests/Utils/Containers/SlotMap.cpp index b767e80..b46b8c8 100644 --- a/Bigfoot/Tests/Utils/Containers/SlotMap.cpp +++ b/Bigfoot/Tests/Utils/Containers/SlotMap.cpp @@ -71,8 +71,16 @@ TEST_F(SlotMapKeyFixture, GetIndex_ShouldReturnTheIndex) class SlotMapValueMock { public: + SlotMapValueMock() = default; virtual ~SlotMapValueMock() = default; + + SlotMapValueMock(const SlotMapValueMock&) = delete; + SlotMapValueMock(SlotMapValueMock&&) = delete; + virtual void Destruct() = 0; + + SlotMapValueMock& operator=(const SlotMapValueMock&) = delete; + SlotMapValueMock& operator=(SlotMapValueMock&&) = delete; }; class SlotMapValue @@ -120,7 +128,7 @@ class SlotMapFixture: public ::testing::Test MOCK_METHOD(void, Destruct, (), (override)); }; - using SlotMapKey = typename SLOTMAP::SlotMapKey; + using SlotMapKey = SLOTMAP::SlotMapKey; std::unique_ptr m_mock; SLOTMAP m_slotMap; @@ -142,7 +150,7 @@ class SlotMapNameGenerator { public: template - static std::string GetName(int) + static std::string GetName([[maybe_unused]] int p_index) { if constexpr (std::is_same_v>>) { @@ -159,11 +167,14 @@ using SlotMapTypes = ::testing::Types>>; TYPED_TEST_SUITE(SlotMapFixture, SlotMapTypes, SlotMapNameGenerator); +// DenseSlotMap has no notion of pages, so the shared TYPED_TEST bodies below can't reference TypeParam::PAGE_SIZE +constexpr std::uint32_t PAGE_SIZE = StableSlotMap>::PAGE_SIZE; + /****************************************************************************************/ TYPED_TEST(SlotMapFixture, Has_ReturnTrueIfSlotMapHasTheKey) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey key = this->m_slotMap.Insert(42); EXPECT_TRUE(this->m_slotMap.Has(key)); @@ -173,7 +184,7 @@ TYPED_TEST(SlotMapFixture, Has_ReturnTrueIfSlotMapHasTheKey) TYPED_TEST(SlotMapFixture, Has_ReturnFalseIfSlotMapDoesNotHaveTheKey) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; std::ignore = this->m_slotMap.Insert(42); EXPECT_FALSE(this->m_slotMap.Has(SlotMapKey {1, 23})); @@ -183,7 +194,7 @@ TYPED_TEST(SlotMapFixture, Has_ReturnFalseIfSlotMapDoesNotHaveTheKey) TYPED_TEST(SlotMapFixture, Has_ReturnFalseForStaleKey) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey staleKey = this->m_slotMap.Insert(42); this->m_slotMap.Remove(staleKey); @@ -196,7 +207,7 @@ TYPED_TEST(SlotMapFixture, Has_ReturnFalseForStaleKey) TYPED_TEST(SlotMapFixture, Size_ShouldReturnTheSizeOfTheSlotMap) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; EXPECT_EQ(this->m_slotMap.Size(), 0); const SlotMapKey key1 = this->m_slotMap.Insert(42); @@ -212,7 +223,7 @@ TYPED_TEST(SlotMapFixture, Size_ShouldReturnTheSizeOfTheSlotMap) TYPED_TEST(SlotMapFixture, Empty_ShouldReturnTrueIfTheSlotMapIsEmpty) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; EXPECT_TRUE(this->m_slotMap.Empty()); const SlotMapKey key1 = this->m_slotMap.Insert(42); @@ -226,7 +237,7 @@ TYPED_TEST(SlotMapFixture, Empty_ShouldReturnTrueIfTheSlotMapIsEmpty) TYPED_TEST(SlotMapFixture, Empty_ShouldReturnFalseIfTheSlotMapIsNotEmpty) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey key1 = this->m_slotMap.Insert(42); EXPECT_FALSE(this->m_slotMap.Empty()); @@ -248,7 +259,7 @@ TYPED_TEST(SlotMapFixture, Insert_ShouldReturnAValidSlotKey) TYPED_TEST(SlotMapFixture, Insert_ShouldRecycleIndicesWhenPossible) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey key1 = this->m_slotMap.Insert(42); const SlotMapKey key2 = this->m_slotMap.Insert(69); @@ -270,7 +281,7 @@ TYPED_TEST(SlotMapFixture, Insert_ShouldRecycleIndicesWhenPossible) TYPED_TEST(SlotMapFixture, Get_ShouldReturnTheValue) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey key = this->m_slotMap.Insert(42); EXPECT_EQ(*this->m_slotMap.Get(key), 42); @@ -281,7 +292,7 @@ TYPED_TEST(SlotMapFixture, Get_ShouldReturnTheValue) TYPED_TEST(SlotMapFixture, Get_ShouldNullptrIfTheValueIsNotInMap) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey key {1, 0}; EXPECT_EQ(this->m_slotMap.Get(key), nullptr); @@ -292,7 +303,7 @@ TYPED_TEST(SlotMapFixture, Get_ShouldNullptrIfTheValueIsNotInMap) TYPED_TEST(SlotMapFixture, Get_ShouldReturnNullptrForStaleKey) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey staleKey = this->m_slotMap.Insert(42); this->m_slotMap.Remove(staleKey); @@ -306,7 +317,7 @@ TYPED_TEST(SlotMapFixture, Get_ShouldReturnNullptrForStaleKey) TYPED_TEST(SlotMapFixture, Remove_ShouldRemoveTheValue) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey key = this->m_slotMap.Insert(42); EXPECT_TRUE(this->m_slotMap.Has(key)); @@ -320,7 +331,7 @@ TYPED_TEST(SlotMapFixture, Remove_ShouldRemoveTheValue) TYPED_TEST(SlotMapFixture, Remove_ShouldBeANoOpForStaleKey) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey staleKey = this->m_slotMap.Insert(42); this->m_slotMap.Remove(staleKey); @@ -337,7 +348,7 @@ TYPED_TEST(SlotMapFixture, Remove_ShouldBeANoOpForStaleKey) TYPED_TEST(SlotMapFixture, Remove_ExhaustingAllVersionsOfKeyMarksItDeadForGood) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; for (typename SlotMapKey::VersionType version = 0; version < SlotMapKey::MAX_VERSION; ++version) { @@ -356,7 +367,7 @@ TYPED_TEST(SlotMapFixture, Remove_ExhaustingAllVersionsOfKeyMarksItDeadForGood) TYPED_TEST(SlotMapFixture, Reset_ShouldClearTheMapAndOldKeysAreValid) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey key1 = this->m_slotMap.Insert(42); const SlotMapKey key2 = this->m_slotMap.Insert(69); @@ -378,7 +389,7 @@ TYPED_TEST(SlotMapFixture, Reset_ShouldClearTheMapAndOldKeysAreValid) TYPED_TEST(SlotMapFixture, Clear_ShouldClearTheMapAndOldKeysAreInvalid) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const SlotMapKey key1 = this->m_slotMap.Insert(42); const SlotMapKey key2 = this->m_slotMap.Insert(69); @@ -398,23 +409,31 @@ TYPED_TEST(SlotMapFixture, Clear_ShouldClearTheMapAndOldKeysAreInvalid) /****************************************************************************************/ -TYPED_TEST(SlotMapFixture, Iterator) +TYPED_TEST(SlotMapFixture, Iterator_ShouldTraverseInInsertionOrder) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; EXPECT_EQ(this->m_slotMap.begin(), this->m_slotMap.end()); std::ignore = this->m_slotMap.Insert(1); - const SlotMapKey key2 = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(2); std::ignore = this->m_slotMap.Insert(3); - // Forward traversal follows insertion order std::uint32_t expected = 1; for (auto it = this->m_slotMap.begin(); it != this->m_slotMap.end(); ++it) { EXPECT_EQ(*it, expected); ++expected; } +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, Iterator_ShouldSupportPreAndPostIncrementDecrement) +{ + std::ignore = this->m_slotMap.Insert(1); + std::ignore = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(3); // Pre-increment advances and returns *this auto preIt = this->m_slotMap.begin(); @@ -441,8 +460,18 @@ TYPED_TEST(SlotMapFixture, Iterator) const auto postDecrementResult = postDecIt--; EXPECT_EQ(*postDecrementResult, 3); EXPECT_EQ(*postDecIt, 2); +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, Iterator_ShouldSkipRemovedSlotsDuringTraversal) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + std::ignore = this->m_slotMap.Insert(1); + const SlotMapKey key2 = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(3); - // Removed slots are skipped during traversal this->m_slotMap.Remove(key2); std::size_t count = 0; @@ -454,38 +483,66 @@ TYPED_TEST(SlotMapFixture, Iterator) } EXPECT_EQ(count, 2); EXPECT_EQ(sum, 4); +} - // Multi-page traversal: StableSlotMap's PAGE_SIZE is 64, so 100 elements force it to span pages - this->m_slotMap.Reset(); +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, Iterator_ShouldTraverseAcrossMultiplePages) +{ + // StableSlotMap's PAGE_SIZE is 64, so 100 elements force it to span pages + using SlotMapKey = TestFixture::SlotMapKey; constexpr std::uint32_t elementCount = 100; - eastl::array keys; for (std::uint32_t value = 0; value < elementCount; ++value) { - keys[value] = this->m_slotMap.Insert(value); + std::ignore = this->m_slotMap.Insert(value); } - expected = 0; + std::uint32_t expected = 0; for (const std::uint32_t value: this->m_slotMap) { EXPECT_EQ(value, expected); ++expected; } EXPECT_EQ(expected, elementCount); +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, Iterator_ShouldCrossThePageBoundaryForwardAndBackward) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + std::ignore = this->m_slotMap.Insert(value); + } - // Explicitly cross the page boundary (index 63 -> 64) forward and backward auto boundaryIt = this->m_slotMap.begin(); - for (std::uint32_t step = 0; step < 63; ++step) + for (std::uint32_t step = 0; step < PAGE_SIZE - 1; ++step) { ++boundaryIt; } - EXPECT_EQ(*boundaryIt, 63); + EXPECT_EQ(*boundaryIt, PAGE_SIZE - 1); ++boundaryIt; - EXPECT_EQ(*boundaryIt, 64); + EXPECT_EQ(*boundaryIt, PAGE_SIZE); --boundaryIt; - EXPECT_EQ(*boundaryIt, 63); + EXPECT_EQ(*boundaryIt, PAGE_SIZE - 1); +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, Iterator_ShouldSupportPreAndPostIncrementDecrementAcrossTheBoundary) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + std::ignore = this->m_slotMap.Insert(value); + } - // Pre/post-increment/decrement across the boundary auto preBoundaryIt = this->m_slotMap.begin(); auto& preBoundaryIncrementResult = ++preBoundaryIt; EXPECT_EQ(&preBoundaryIncrementResult, &preBoundaryIt); @@ -507,70 +564,97 @@ TYPED_TEST(SlotMapFixture, Iterator) const auto postBoundaryDecrementResult = postBoundaryDecIt--; EXPECT_EQ(*postBoundaryDecrementResult, 99); EXPECT_EQ(*postBoundaryDecIt, 98); +} - // Remove elements straddling the boundary and check the holes are skipped - this->m_slotMap.Remove(keys[63]); - this->m_slotMap.Remove(keys[64]); +/****************************************************************************************/ - count = 0; +TYPED_TEST(SlotMapFixture, Iterator_ShouldSkipHolesStraddlingThePageBoundary) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + eastl::array keys; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + keys[value] = this->m_slotMap.Insert(value); + } + + this->m_slotMap.Remove(keys[PAGE_SIZE - 1]); + this->m_slotMap.Remove(keys[PAGE_SIZE]); + + std::size_t count = 0; for (const std::uint32_t value: this->m_slotMap) { - EXPECT_NE(value, 63); - EXPECT_NE(value, 64); + EXPECT_NE(value, PAGE_SIZE - 1); + EXPECT_NE(value, PAGE_SIZE); ++count; } EXPECT_EQ(count, elementCount - 2); +} +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, Iterator_ShouldSkipAFullyEmptyLeadingPage) +{ // A fully empty leading page must be skipped by begin()/SeekFirstFrom - this->m_slotMap.Reset(); + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; eastl::array leadingKeys; for (std::uint32_t value = 0; value < elementCount; ++value) { leadingKeys[value] = this->m_slotMap.Insert(value); } - for (std::uint32_t value = 0; value < 64; ++value) + for (std::uint32_t value = 0; value < PAGE_SIZE; ++value) { this->m_slotMap.Remove(leadingKeys[value]); } - count = 0; - sum = 0; + std::size_t count = 0; + std::uint32_t sum = 0; for (const std::uint32_t value: this->m_slotMap) { ++count; sum += value; } - EXPECT_EQ(count, elementCount - 64); - EXPECT_EQ(sum, 2934u); // 64 + 65 + ... + 99 + EXPECT_EQ(count, elementCount - PAGE_SIZE); + EXPECT_EQ(sum, 2934U); // 64 + 65 + ... + 99 +} +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, Iterator_ShouldSkipAFullyEmptyTrailingPage) +{ // A fully empty trailing page must be skipped when retreating past it - this->m_slotMap.Reset(); + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; eastl::array trailingKeys; for (std::uint32_t value = 0; value < elementCount; ++value) { trailingKeys[value] = this->m_slotMap.Insert(value); } - for (std::uint32_t value = 64; value < elementCount; ++value) + for (std::uint32_t value = PAGE_SIZE; value < elementCount; ++value) { this->m_slotMap.Remove(trailingKeys[value]); } - count = 0; - sum = 0; + std::size_t count = 0; + std::uint32_t sum = 0; for (const std::uint32_t value: this->m_slotMap) { ++count; sum += value; } - EXPECT_EQ(count, 64u); - EXPECT_EQ(sum, 2016u); // 0 + 1 + ... + 63 + EXPECT_EQ(count, PAGE_SIZE); + EXPECT_EQ(sum, 2016U); // 0 + 1 + ... + 63 } /****************************************************************************************/ -TYPED_TEST(SlotMapFixture, ConstIterator) +TYPED_TEST(SlotMapFixture, ConstIterator_ShouldTraverseInInsertionOrder) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const TypeParam& constMap = this->m_slotMap; @@ -579,7 +663,7 @@ TYPED_TEST(SlotMapFixture, ConstIterator) EXPECT_EQ(constMap.begin(), constMap.end()); std::ignore = this->m_slotMap.Insert(1); - const SlotMapKey key2 = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(2); std::ignore = this->m_slotMap.Insert(3); std::uint32_t expected = 1; @@ -595,6 +679,15 @@ TYPED_TEST(SlotMapFixture, ConstIterator) EXPECT_EQ(*it, expected); ++expected; } +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstIterator_ShouldSupportPreAndPostIncrementDecrement) +{ + std::ignore = this->m_slotMap.Insert(1); + std::ignore = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(3); // Pre-increment advances and returns *this auto preIt = this->m_slotMap.cbegin(); @@ -621,6 +714,19 @@ TYPED_TEST(SlotMapFixture, ConstIterator) const auto postDecrementResult = postDecIt--; EXPECT_EQ(*postDecrementResult, 3); EXPECT_EQ(*postDecIt, 2); +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstIterator_ShouldSkipRemovedSlotsDuringTraversal) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + const TypeParam& constMap = this->m_slotMap; + + std::ignore = this->m_slotMap.Insert(1); + const SlotMapKey key2 = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(3); // Removed slots are skipped identically through cbegin()/cend() and the const-object overloads this->m_slotMap.Remove(key2); @@ -644,38 +750,66 @@ TYPED_TEST(SlotMapFixture, ConstIterator) } EXPECT_EQ(count, 2); EXPECT_EQ(sum, 4); +} - // Multi-page traversal: StableSlotMap's PAGE_SIZE is 64, so 100 elements force it to span pages - this->m_slotMap.Reset(); +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstIterator_ShouldTraverseAcrossMultiplePages) +{ + // StableSlotMap's PAGE_SIZE is 64, so 100 elements force it to span pages + using SlotMapKey = TestFixture::SlotMapKey; constexpr std::uint32_t elementCount = 100; - eastl::array keys; for (std::uint32_t value = 0; value < elementCount; ++value) { - keys[value] = this->m_slotMap.Insert(value); + std::ignore = this->m_slotMap.Insert(value); } - expected = 0; + std::uint32_t expected = 0; for (auto it = this->m_slotMap.cbegin(); it != this->m_slotMap.cend(); ++it) { EXPECT_EQ(*it, expected); ++expected; } EXPECT_EQ(expected, elementCount); +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstIterator_ShouldCrossThePageBoundaryForwardAndBackward) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + std::ignore = this->m_slotMap.Insert(value); + } - // Explicitly cross the page boundary (index 63 -> 64) forward and backward auto boundaryIt = this->m_slotMap.cbegin(); - for (std::uint32_t step = 0; step < 63; ++step) + for (std::uint32_t step = 0; step < PAGE_SIZE - 1; ++step) { ++boundaryIt; } - EXPECT_EQ(*boundaryIt, 63); + EXPECT_EQ(*boundaryIt, PAGE_SIZE - 1); ++boundaryIt; - EXPECT_EQ(*boundaryIt, 64); + EXPECT_EQ(*boundaryIt, PAGE_SIZE); --boundaryIt; - EXPECT_EQ(*boundaryIt, 63); + EXPECT_EQ(*boundaryIt, PAGE_SIZE - 1); +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstIterator_ShouldSupportPreAndPostIncrementDecrementAcrossTheBoundary) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + std::ignore = this->m_slotMap.Insert(value); + } - // Pre/post-increment/decrement across the boundary auto preBoundaryIt = this->m_slotMap.cbegin(); auto& preBoundaryIncrementResult = ++preBoundaryIt; EXPECT_EQ(&preBoundaryIncrementResult, &preBoundaryIt); @@ -697,84 +831,119 @@ TYPED_TEST(SlotMapFixture, ConstIterator) const auto postBoundaryDecrementResult = postBoundaryDecIt--; EXPECT_EQ(*postBoundaryDecrementResult, 99); EXPECT_EQ(*postBoundaryDecIt, 98); +} - // Remove elements straddling the boundary and check the holes are skipped - this->m_slotMap.Remove(keys[63]); - this->m_slotMap.Remove(keys[64]); +/****************************************************************************************/ - count = 0; +TYPED_TEST(SlotMapFixture, ConstIterator_ShouldSkipHolesStraddlingThePageBoundary) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + eastl::array keys; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + keys[value] = this->m_slotMap.Insert(value); + } + + this->m_slotMap.Remove(keys[PAGE_SIZE - 1]); + this->m_slotMap.Remove(keys[PAGE_SIZE]); + + std::size_t count = 0; for (auto it = this->m_slotMap.cbegin(); it != this->m_slotMap.cend(); ++it) { - EXPECT_NE(*it, 63); - EXPECT_NE(*it, 64); + EXPECT_NE(*it, PAGE_SIZE - 1); + EXPECT_NE(*it, PAGE_SIZE); ++count; } EXPECT_EQ(count, elementCount - 2); +} +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstIterator_ShouldSkipAFullyEmptyLeadingPage) +{ // A fully empty leading page must be skipped by cbegin()/SeekFirstFrom - this->m_slotMap.Reset(); + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; eastl::array leadingKeys; for (std::uint32_t value = 0; value < elementCount; ++value) { leadingKeys[value] = this->m_slotMap.Insert(value); } - for (std::uint32_t value = 0; value < 64; ++value) + for (std::uint32_t value = 0; value < PAGE_SIZE; ++value) { this->m_slotMap.Remove(leadingKeys[value]); } - count = 0; - sum = 0; + std::size_t count = 0; + std::uint32_t sum = 0; for (auto it = this->m_slotMap.cbegin(); it != this->m_slotMap.cend(); ++it) { ++count; sum += *it; } - EXPECT_EQ(count, elementCount - 64); - EXPECT_EQ(sum, 2934u); // 64 + 65 + ... + 99 + EXPECT_EQ(count, elementCount - PAGE_SIZE); + EXPECT_EQ(sum, 2934U); // 64 + 65 + ... + 99 +} +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstIterator_ShouldSkipAFullyEmptyTrailingPage) +{ // A fully empty trailing page must be skipped when retreating past it - this->m_slotMap.Reset(); + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; eastl::array trailingKeys; for (std::uint32_t value = 0; value < elementCount; ++value) { trailingKeys[value] = this->m_slotMap.Insert(value); } - for (std::uint32_t value = 64; value < elementCount; ++value) + for (std::uint32_t value = PAGE_SIZE; value < elementCount; ++value) { this->m_slotMap.Remove(trailingKeys[value]); } - count = 0; - sum = 0; + std::size_t count = 0; + std::uint32_t sum = 0; for (auto it = this->m_slotMap.cbegin(); it != this->m_slotMap.cend(); ++it) { ++count; sum += *it; } - EXPECT_EQ(count, 64u); - EXPECT_EQ(sum, 2016u); // 0 + 1 + ... + 63 + EXPECT_EQ(count, PAGE_SIZE); + EXPECT_EQ(sum, 2016U); // 0 + 1 + ... + 63 } /****************************************************************************************/ -TYPED_TEST(SlotMapFixture, ReverseIterator) +TYPED_TEST(SlotMapFixture, ReverseIterator_ShouldTraverseInReverseInsertionOrder) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; EXPECT_EQ(this->m_slotMap.rbegin(), this->m_slotMap.rend()); std::ignore = this->m_slotMap.Insert(1); - const SlotMapKey key2 = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(2); std::ignore = this->m_slotMap.Insert(3); - // Reverse traversal mirrors insertion order std::uint32_t expected = 3; for (auto it = this->m_slotMap.rbegin(); it != this->m_slotMap.rend(); ++it) { EXPECT_EQ(*it, expected); --expected; } +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ReverseIterator_ShouldSupportPreAndPostIncrementDecrement) +{ + std::ignore = this->m_slotMap.Insert(1); + std::ignore = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(3); // Pre-increment advances and returns *this auto preIt = this->m_slotMap.rbegin(); @@ -801,8 +970,18 @@ TYPED_TEST(SlotMapFixture, ReverseIterator) const auto postDecrementResult = postDecIt--; EXPECT_EQ(*postDecrementResult, 1); EXPECT_EQ(*postDecIt, 2); +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ReverseIterator_ShouldSkipRemovedSlotsDuringTraversal) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + std::ignore = this->m_slotMap.Insert(1); + const SlotMapKey key2 = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(3); - // Removed slots are skipped during traversal this->m_slotMap.Remove(key2); std::size_t count = 0; @@ -814,36 +993,65 @@ TYPED_TEST(SlotMapFixture, ReverseIterator) } EXPECT_EQ(count, 2); EXPECT_EQ(sum, 4); +} - // Multi-page traversal: StableSlotMap's PAGE_SIZE is 64, so 100 elements force it to span pages - this->m_slotMap.Reset(); +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ReverseIterator_ShouldTraverseAcrossMultiplePages) +{ + // StableSlotMap's PAGE_SIZE is 64, so 100 elements force it to span pages + using SlotMapKey = TestFixture::SlotMapKey; constexpr std::uint32_t elementCount = 100; - eastl::array keys; for (std::uint32_t value = 0; value < elementCount; ++value) { - keys[value] = this->m_slotMap.Insert(value); + std::ignore = this->m_slotMap.Insert(value); } - expected = elementCount - 1; + std::uint32_t expected = elementCount - 1; for (auto it = this->m_slotMap.rbegin(); it != this->m_slotMap.rend(); ++it) { EXPECT_EQ(*it, expected); --expected; } +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ReverseIterator_ShouldCrossThePageBoundaryForwardAndBackward) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + std::ignore = this->m_slotMap.Insert(value); + } // Explicitly cross the page boundary (value 64 -> 63) forward and backward auto boundaryIt = this->m_slotMap.rbegin(); - while (*boundaryIt != 64) + while (*boundaryIt != PAGE_SIZE) { ++boundaryIt; } ++boundaryIt; - EXPECT_EQ(*boundaryIt, 63); + EXPECT_EQ(*boundaryIt, PAGE_SIZE - 1); --boundaryIt; - EXPECT_EQ(*boundaryIt, 64); + EXPECT_EQ(*boundaryIt, PAGE_SIZE); +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ReverseIterator_ShouldSupportPreAndPostIncrementDecrementAcrossTheBoundary) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + std::ignore = this->m_slotMap.Insert(value); + } - // Pre/post-increment/decrement across the boundary auto preBoundaryIt = this->m_slotMap.rbegin(); auto& preBoundaryIncrementResult = ++preBoundaryIt; EXPECT_EQ(&preBoundaryIncrementResult, &preBoundaryIt); @@ -865,70 +1073,97 @@ TYPED_TEST(SlotMapFixture, ReverseIterator) const auto postBoundaryDecrementResult = postBoundaryDecIt--; EXPECT_EQ(*postBoundaryDecrementResult, 0); EXPECT_EQ(*postBoundaryDecIt, 1); +} - // Remove elements straddling the boundary and check the holes are skipped - this->m_slotMap.Remove(keys[63]); - this->m_slotMap.Remove(keys[64]); +/****************************************************************************************/ - count = 0; +TYPED_TEST(SlotMapFixture, ReverseIterator_ShouldSkipHolesStraddlingThePageBoundary) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + eastl::array keys; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + keys[value] = this->m_slotMap.Insert(value); + } + + this->m_slotMap.Remove(keys[PAGE_SIZE - 1]); + this->m_slotMap.Remove(keys[PAGE_SIZE]); + + std::size_t count = 0; for (auto it = this->m_slotMap.rbegin(); it != this->m_slotMap.rend(); ++it) { - EXPECT_NE(*it, 63); - EXPECT_NE(*it, 64); + EXPECT_NE(*it, PAGE_SIZE - 1); + EXPECT_NE(*it, PAGE_SIZE); ++count; } EXPECT_EQ(count, elementCount - 2); +} +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ReverseIterator_ShouldSkipAFullyEmptyLeadingPage) +{ // A fully empty leading page must be skipped when retreating past it (rend() side) - this->m_slotMap.Reset(); + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; eastl::array leadingKeys; for (std::uint32_t value = 0; value < elementCount; ++value) { leadingKeys[value] = this->m_slotMap.Insert(value); } - for (std::uint32_t value = 0; value < 64; ++value) + for (std::uint32_t value = 0; value < PAGE_SIZE; ++value) { this->m_slotMap.Remove(leadingKeys[value]); } - count = 0; - sum = 0; + std::size_t count = 0; + std::uint32_t sum = 0; for (auto it = this->m_slotMap.rbegin(); it != this->m_slotMap.rend(); ++it) { ++count; sum += *it; } - EXPECT_EQ(count, elementCount - 64); - EXPECT_EQ(sum, 2934u); // 64 + 65 + ... + 99 + EXPECT_EQ(count, elementCount - PAGE_SIZE); + EXPECT_EQ(sum, 2934U); // 64 + 65 + ... + 99 +} +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ReverseIterator_ShouldSkipAFullyEmptyTrailingPage) +{ // A fully empty trailing page must be skipped by rbegin()/SeekLastFrom - this->m_slotMap.Reset(); + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; eastl::array trailingKeys; for (std::uint32_t value = 0; value < elementCount; ++value) { trailingKeys[value] = this->m_slotMap.Insert(value); } - for (std::uint32_t value = 64; value < elementCount; ++value) + for (std::uint32_t value = PAGE_SIZE; value < elementCount; ++value) { this->m_slotMap.Remove(trailingKeys[value]); } - count = 0; - sum = 0; + std::size_t count = 0; + std::uint32_t sum = 0; for (auto it = this->m_slotMap.rbegin(); it != this->m_slotMap.rend(); ++it) { ++count; sum += *it; } - EXPECT_EQ(count, 64u); - EXPECT_EQ(sum, 2016u); // 0 + 1 + ... + 63 + EXPECT_EQ(count, PAGE_SIZE); + EXPECT_EQ(sum, 2016U); // 0 + 1 + ... + 63 } /****************************************************************************************/ -TYPED_TEST(SlotMapFixture, ConstReverseIterator) +TYPED_TEST(SlotMapFixture, ConstReverseIterator_ShouldTraverseInReverseInsertionOrder) { - using SlotMapKey = typename TestFixture::SlotMapKey; + using SlotMapKey = TestFixture::SlotMapKey; const TypeParam& constMap = this->m_slotMap; @@ -938,7 +1173,7 @@ TYPED_TEST(SlotMapFixture, ConstReverseIterator) EXPECT_EQ(constMap.rbegin(), constMap.rend()); std::ignore = this->m_slotMap.Insert(1); - const SlotMapKey key2 = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(2); std::ignore = this->m_slotMap.Insert(3); std::uint32_t expected = 3; @@ -954,6 +1189,15 @@ TYPED_TEST(SlotMapFixture, ConstReverseIterator) EXPECT_EQ(*it, expected); --expected; } +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstReverseIterator_ShouldSupportPreAndPostIncrementDecrement) +{ + std::ignore = this->m_slotMap.Insert(1); + std::ignore = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(3); // Pre-increment advances and returns *this auto preIt = this->m_slotMap.crbegin(); @@ -980,6 +1224,19 @@ TYPED_TEST(SlotMapFixture, ConstReverseIterator) const auto postDecrementResult = postDecIt--; EXPECT_EQ(*postDecrementResult, 1); EXPECT_EQ(*postDecIt, 2); +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstReverseIterator_ShouldSkipRemovedSlotsDuringTraversal) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + const TypeParam& constMap = this->m_slotMap; + + std::ignore = this->m_slotMap.Insert(1); + const SlotMapKey key2 = this->m_slotMap.Insert(2); + std::ignore = this->m_slotMap.Insert(3); // Removed slots are skipped identically through crbegin()/crend() and the const-object overloads this->m_slotMap.Remove(key2); @@ -1003,36 +1260,64 @@ TYPED_TEST(SlotMapFixture, ConstReverseIterator) } EXPECT_EQ(count, 2); EXPECT_EQ(sum, 4); +} - // Multi-page traversal: StableSlotMap's PAGE_SIZE is 64, so 100 elements force it to span pages - this->m_slotMap.Reset(); +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstReverseIterator_ShouldTraverseAcrossMultiplePages) +{ + // StableSlotMap's PAGE_SIZE is 64, so 100 elements force it to span pages + using SlotMapKey = TestFixture::SlotMapKey; constexpr std::uint32_t elementCount = 100; - eastl::array keys; for (std::uint32_t value = 0; value < elementCount; ++value) { - keys[value] = this->m_slotMap.Insert(value); + std::ignore = this->m_slotMap.Insert(value); } - expected = elementCount - 1; + std::uint32_t expected = elementCount - 1; for (auto it = this->m_slotMap.crbegin(); it != this->m_slotMap.crend(); ++it) { EXPECT_EQ(*it, expected); --expected; } +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstReverseIterator_ShouldCrossThePageBoundaryForwardAndBackward) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + std::ignore = this->m_slotMap.Insert(value); + } - // Explicitly cross the page boundary (value 64 -> 63) forward and backward auto boundaryIt = this->m_slotMap.crbegin(); - while (*boundaryIt != 64) + while (*boundaryIt != PAGE_SIZE) { ++boundaryIt; } ++boundaryIt; - EXPECT_EQ(*boundaryIt, 63); + EXPECT_EQ(*boundaryIt, PAGE_SIZE - 1); --boundaryIt; - EXPECT_EQ(*boundaryIt, 64); + EXPECT_EQ(*boundaryIt, PAGE_SIZE); +} + +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstReverseIterator_ShouldSupportPreAndPostIncrementDecrementAcrossTheBoundary) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + std::ignore = this->m_slotMap.Insert(value); + } - // Pre/post-increment/decrement across the boundary auto preBoundaryIt = this->m_slotMap.crbegin(); auto& preBoundaryIncrementResult = ++preBoundaryIt; EXPECT_EQ(&preBoundaryIncrementResult, &preBoundaryIt); @@ -1054,63 +1339,90 @@ TYPED_TEST(SlotMapFixture, ConstReverseIterator) const auto postBoundaryDecrementResult = postBoundaryDecIt--; EXPECT_EQ(*postBoundaryDecrementResult, 0); EXPECT_EQ(*postBoundaryDecIt, 1); +} - // Remove elements straddling the boundary and check the holes are skipped - this->m_slotMap.Remove(keys[63]); - this->m_slotMap.Remove(keys[64]); +/****************************************************************************************/ - count = 0; +TYPED_TEST(SlotMapFixture, ConstReverseIterator_ShouldSkipHolesStraddlingThePageBoundary) +{ + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; + eastl::array keys; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + keys[value] = this->m_slotMap.Insert(value); + } + + this->m_slotMap.Remove(keys[PAGE_SIZE - 1]); + this->m_slotMap.Remove(keys[PAGE_SIZE]); + + std::size_t count = 0; for (auto it = this->m_slotMap.crbegin(); it != this->m_slotMap.crend(); ++it) { - EXPECT_NE(*it, 63); - EXPECT_NE(*it, 64); + EXPECT_NE(*it, PAGE_SIZE - 1); + EXPECT_NE(*it, PAGE_SIZE); ++count; } EXPECT_EQ(count, elementCount - 2); +} +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstReverseIterator_ShouldSkipAFullyEmptyLeadingPage) +{ // A fully empty leading page must be skipped when retreating past it (crend() side) - this->m_slotMap.Reset(); + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; eastl::array leadingKeys; for (std::uint32_t value = 0; value < elementCount; ++value) { leadingKeys[value] = this->m_slotMap.Insert(value); } - for (std::uint32_t value = 0; value < 64; ++value) + for (std::uint32_t value = 0; value < PAGE_SIZE; ++value) { this->m_slotMap.Remove(leadingKeys[value]); } - count = 0; - sum = 0; + std::size_t count = 0; + std::uint32_t sum = 0; for (auto it = this->m_slotMap.crbegin(); it != this->m_slotMap.crend(); ++it) { ++count; sum += *it; } - EXPECT_EQ(count, elementCount - 64); - EXPECT_EQ(sum, 2934u); // 64 + 65 + ... + 99 + EXPECT_EQ(count, elementCount - PAGE_SIZE); + EXPECT_EQ(sum, 2934U); // 64 + 65 + ... + 99 +} +/****************************************************************************************/ + +TYPED_TEST(SlotMapFixture, ConstReverseIterator_ShouldSkipAFullyEmptyTrailingPage) +{ // A fully empty trailing page must be skipped by crbegin()/SeekLastFrom - this->m_slotMap.Reset(); + using SlotMapKey = TestFixture::SlotMapKey; + + constexpr std::uint32_t elementCount = 100; eastl::array trailingKeys; for (std::uint32_t value = 0; value < elementCount; ++value) { trailingKeys[value] = this->m_slotMap.Insert(value); } - for (std::uint32_t value = 64; value < elementCount; ++value) + for (std::uint32_t value = PAGE_SIZE; value < elementCount; ++value) { this->m_slotMap.Remove(trailingKeys[value]); } - count = 0; - sum = 0; + std::size_t count = 0; + std::uint32_t sum = 0; for (auto it = this->m_slotMap.crbegin(); it != this->m_slotMap.crend(); ++it) { ++count; sum += *it; } - EXPECT_EQ(count, 64u); - EXPECT_EQ(sum, 2016u); // 0 + 1 + ... + 63 + EXPECT_EQ(count, PAGE_SIZE); + EXPECT_EQ(sum, 2016U); // 0 + 1 + ... + 63 } /****************************************************************************************/ diff --git a/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp b/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp index fab5e17..5070fc7 100644 --- a/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp +++ b/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp @@ -85,11 +85,11 @@ TEST_F(EASTLFormattersFixture, FormatsNestedVectors) /****************************************************************************************/ -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED class EASTLFormattersLogFixture: public ::testing::Test { protected: - std::string ReadFileSinkContent() + static std::string ReadFileSinkContent() { Singleton::GetInstance().Flush(); diff --git a/Bigfoot/Tests/Utils/Log/Log.cpp b/Bigfoot/Tests/Utils/Log/Log.cpp index afd1a92..7bfedeb 100644 --- a/Bigfoot/Tests/Utils/Log/Log.cpp +++ b/Bigfoot/Tests/Utils/Log/Log.cpp @@ -10,7 +10,7 @@ #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED #include diff --git a/Bigfoot/Tests/Utils/Log/LogMacros.cpp b/Bigfoot/Tests/Utils/Log/LogMacros.cpp index 9a0981c..50f5640 100644 --- a/Bigfoot/Tests/Utils/Log/LogMacros.cpp +++ b/Bigfoot/Tests/Utils/Log/LogMacros.cpp @@ -10,7 +10,7 @@ #include -#if defined BIGFOOT_NOT_OPTIMIZED +#ifdef BIGFOOT_NOT_OPTIMIZED #include #include @@ -24,7 +24,7 @@ namespace Bigfoot class LogMacrosFixture: public ::testing::Test { protected: - std::string ReadFileSinkContent() + static std::string ReadFileSinkContent() { Singleton::GetInstance().Flush();