From 8392245b103b6036f0ace3e415a2054d9d2fe52e Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Tue, 1 Sep 2026 15:05:25 +0200 Subject: [PATCH] Reduce back and forth between std and eastl --- Bigfoot/Benchmarks/Engine/BigFile/BigFile.cpp | 8 +- .../Benchmarks/Engine/Sasquatch/Sasquatch.cpp | 4 +- .../SerializationManager.cpp | 8 +- .../Tools/SasquatchBaker/SasquatchBaker.cpp | 2 +- Bigfoot/Sources/Engine/BigFile/BigFile.cpp | 85 ++++++++++--------- .../Engine/Include/Engine/BigFile/BigFile.hpp | 10 +++ .../System/Include/System/UUID/UUID.hpp | 7 +- Bigfoot/Sources/System/UUID/UUID.cpp | 5 +- .../Tools/SasquatchBaker/SasquatchBaker.cpp | 2 +- .../Utils/Include/Utils/Assert/Assert.hpp | 12 ++- .../Sources/Utils/Include/Utils/Format.hpp | 31 +++++++ .../Sources/Utils/Include/Utils/Version.hpp | 7 +- Bigfoot/Sources/Utils/Version.cpp | 4 +- Bigfoot/Tests/System/UUID/UUID.cpp | 6 +- Bigfoot/Tests/Utils/Assert/AssertHandler.cpp | 15 ++-- Bigfoot/Tests/Utils/Format.cpp | 48 +++++++++++ Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp | 11 +-- Bigfoot/Tests/Utils/Log/LogMacros.cpp | 18 ++-- Bigfoot/Tests/Utils/Version.cpp | 6 +- 19 files changed, 194 insertions(+), 95 deletions(-) create mode 100644 Bigfoot/Sources/Utils/Include/Utils/Format.hpp create mode 100644 Bigfoot/Tests/Utils/Format.cpp diff --git a/Bigfoot/Benchmarks/Engine/BigFile/BigFile.cpp b/Bigfoot/Benchmarks/Engine/BigFile/BigFile.cpp index 7831ff2..db46a6f 100644 --- a/Bigfoot/Benchmarks/Engine/BigFile/BigFile.cpp +++ b/Bigfoot/Benchmarks/Engine/BigFile/BigFile.cpp @@ -95,12 +95,12 @@ class BigFileFixture: public benchmark::Fixture for (std::uint32_t i = 0; i < ASSET_COUNT; ++i) { BenchmarkAsset asset; - asset.SetName(asset.GetHeader().uuid.ToString().c_str()); + asset.SetName(asset.GetHeader().uuid.ToString()); asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB}); for (std::uint32_t j = 0; j < REFS_PER_ASSET; ++j) { BenchmarkAssetReferred assetReferred; - assetReferred.SetName(assetReferred.GetHeader().uuid.ToString().c_str()); + assetReferred.SetName(assetReferred.GetHeader().uuid.ToString()); asset.GetAsset().refs.emplace_back(assetReferred.GetHeader().uuid); } @@ -237,7 +237,7 @@ BENCHMARK_DEFINE_F(BigFileFixture, SaveAssetFlatbuffer)(benchmark::State& state) { state.PauseTiming(); BenchmarkAsset asset; - asset.SetName(asset.GetHeader().uuid.ToString().c_str()); + asset.SetName(asset.GetHeader().uuid.ToString()); asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB}); for (std::uint32_t j = 0; j < REFS_PER_ASSET; ++j) { @@ -278,7 +278,7 @@ BENCHMARK_DEFINE_F(BigFileFixture, SaveAssetFlatbuffers)(benchmark::State& state for (std::size_t i = 0; i < batchSize; ++i) { BenchmarkAsset asset; - asset.SetName(asset.GetHeader().uuid.ToString().c_str()); + asset.SetName(asset.GetHeader().uuid.ToString()); asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB}); for (std::uint32_t j = 0; j < REFS_PER_ASSET; ++j) { diff --git a/Bigfoot/Benchmarks/Engine/Sasquatch/Sasquatch.cpp b/Bigfoot/Benchmarks/Engine/Sasquatch/Sasquatch.cpp index 4014a18..ec5be5e 100644 --- a/Bigfoot/Benchmarks/Engine/Sasquatch/Sasquatch.cpp +++ b/Bigfoot/Benchmarks/Engine/Sasquatch/Sasquatch.cpp @@ -97,12 +97,12 @@ class SasquatchFixture: public benchmark::Fixture for (std::uint32_t i = 0; i < ASSET_COUNT; ++i) { BenchmarkAsset asset; - asset.SetName(asset.GetHeader().uuid.ToString().c_str()); + asset.SetName(asset.GetHeader().uuid.ToString()); asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB}); for (std::uint32_t j = 0; j < REFS_PER_ASSET; ++j) { BenchmarkAssetReferred assetReferred; - assetReferred.SetName(assetReferred.GetHeader().uuid.ToString().c_str()); + assetReferred.SetName(assetReferred.GetHeader().uuid.ToString()); asset.GetAsset().refs.emplace_back(assetReferred.GetHeader().uuid); } diff --git a/Bigfoot/Benchmarks/Engine/SerializationManager/SerializationManager.cpp b/Bigfoot/Benchmarks/Engine/SerializationManager/SerializationManager.cpp index fe52aef..93541c6 100644 --- a/Bigfoot/Benchmarks/Engine/SerializationManager/SerializationManager.cpp +++ b/Bigfoot/Benchmarks/Engine/SerializationManager/SerializationManager.cpp @@ -176,14 +176,14 @@ class SerializationManagerFixture: public benchmark::Fixture for (std::uint32_t i = 0; i < ROOT_ASSET_COUNT; ++i) { BenchmarkAsset root; - root.SetName(root.GetHeader().uuid.ToString().c_str()); + root.SetName(root.GetHeader().uuid.ToString()); root.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB}); std::size_t totalBytes = 0; for (std::uint32_t j = 0; j < REFS_PER_ROOT; ++j) { BenchmarkAssetReferred leaf; - leaf.SetName(leaf.GetHeader().uuid.ToString().c_str()); + leaf.SetName(leaf.GetHeader().uuid.ToString()); root.GetAsset().refs.emplace_back(leaf.GetHeader().uuid); @@ -318,7 +318,7 @@ BENCHMARK_DEFINE_F(SerializationManagerFixture, SaveAsset)(benchmark::State& sta { state.PauseTiming(); auto* asset = CreateAsset(); - asset->SetName(asset->GetHeader().uuid.ToString().c_str()); + asset->SetName(asset->GetHeader().uuid.ToString()); asset->GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB}); for (std::uint32_t j = 0; j < REFS_PER_ROOT; ++j) { @@ -360,7 +360,7 @@ BENCHMARK_DEFINE_F(SerializationManagerFixture, SaveAssets)(benchmark::State& st for (std::size_t i = 0; i < batchSize; ++i) { auto* asset = CreateAsset(); - asset->SetName(asset->GetHeader().uuid.ToString().c_str()); + asset->SetName(asset->GetHeader().uuid.ToString()); asset->GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB}); for (std::uint32_t j = 0; j < REFS_PER_ROOT; ++j) { diff --git a/Bigfoot/Benchmarks/Tools/SasquatchBaker/SasquatchBaker.cpp b/Bigfoot/Benchmarks/Tools/SasquatchBaker/SasquatchBaker.cpp index d08a912..f28a69d 100644 --- a/Bigfoot/Benchmarks/Tools/SasquatchBaker/SasquatchBaker.cpp +++ b/Bigfoot/Benchmarks/Tools/SasquatchBaker/SasquatchBaker.cpp @@ -44,7 +44,7 @@ class SasquatchBakerFixture: public benchmark::Fixture for (std::uint32_t i = 0; i < ASSET_COUNT; ++i) { BenchmarkAsset asset; - asset.SetName(asset.GetHeader().uuid.ToString().c_str()); + asset.SetName(asset.GetHeader().uuid.ToString()); asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB}); const eastl::vector flatbuffer = asset.Pack(); diff --git a/Bigfoot/Sources/Engine/BigFile/BigFile.cpp b/Bigfoot/Sources/Engine/BigFile/BigFile.cpp index 5df338b..0333252 100644 --- a/Bigfoot/Sources/Engine/BigFile/BigFile.cpp +++ b/Bigfoot/Sources/Engine/BigFile/BigFile.cpp @@ -8,8 +8,9 @@ #include +#include + #include -#include namespace Bigfoot { @@ -149,9 +150,9 @@ eastl::vector> BigFile::GetAssetFlatbuffers(const eastl placeholders += "?"; } - const std::string sql = fmt::format("SELECT UUID, Asset FROM Asset WHERE UUID IN ({});", placeholders); + const eastl::string sql = Format("SELECT UUID, Asset FROM Asset WHERE UUID IN ({});", placeholders); - BigFile::Request assetRequest {*this, sql.c_str()}; + BigFile::Request assetRequest {*this, sql}; for (std::size_t i = 0; i < chunkSize; ++i) { assetRequest.Bind(static_cast(i + 1), distinctUUIDs[chunkStart + i].ToBytes()); @@ -159,9 +160,9 @@ eastl::vector> BigFile::GetAssetFlatbuffers(const eastl while (assetRequest.Step()) { - const eastl::span rawUUID = - static_cast>(assetRequest.Get(0)); - const UUID uuid {std::span {rawUUID.begin(), rawUUID.end()}}; + const std::span rawUUID { + static_cast>(assetRequest.Get(0))}; + const UUID uuid {rawUUID}; const auto it = uuidToIndices.find(uuid); ASSERT(EngineAssertHandler, @@ -191,9 +192,9 @@ eastl::vector BigFile::GetAssetHardReferences(const UUID& p_uuid) const eastl::vector hardReferences; while (hardReferencesRequest.Step()) { - const eastl::span rawUUID = static_cast>( - hardReferencesRequest.Get(0)); - hardReferences.emplace_back(std::span(rawUUID.begin(), rawUUID.end())); + const std::span rawUUID { + static_cast>(hardReferencesRequest.Get(0))}; + hardReferences.emplace_back(rawUUID); } return hardReferences; @@ -244,10 +245,10 @@ eastl::vector> BigFile::GetAssetsHardReferences(eastl::span< placeholders += "?"; } - const std::string sql = fmt::format("SELECT UUID, HardReference FROM AssetHardReference WHERE UUID IN ({});", - placeholders); + const eastl::string sql = Format("SELECT UUID, HardReference FROM AssetHardReference WHERE UUID IN ({});", + placeholders); - BigFile::Request hardReferencesRequest {*this, sql.c_str()}; + BigFile::Request hardReferencesRequest {*this, sql}; for (std::size_t i = 0; i < chunkSize; ++i) { hardReferencesRequest.Bind(static_cast(i + 1), distinctUUIDs[chunkStart + i].ToBytes()); @@ -255,10 +256,9 @@ eastl::vector> BigFile::GetAssetsHardReferences(eastl::span< while (hardReferencesRequest.Step()) { - const eastl::span rawOwnerUUID = - static_cast>(hardReferencesRequest.Get(0)); - const UUID ownerUUID { - std::span {rawOwnerUUID.begin(), rawOwnerUUID.end()}}; + const std::span rawOwnerUUID { + static_cast>(hardReferencesRequest.Get(0))}; + const UUID ownerUUID {rawOwnerUUID}; const auto it = uuidToIndices.find(ownerUUID); ASSERT(EngineAssertHandler, @@ -266,14 +266,12 @@ eastl::vector> BigFile::GetAssetsHardReferences(eastl::span< "Returned UUID {} not found in requested UUIDs", ownerUUID); - const eastl::span rawHardReference = - static_cast>(hardReferencesRequest.Get(1)); + const std::span rawHardReference { + static_cast>(hardReferencesRequest.Get(1))}; for (const std::size_t index: it->second) { - hardReferences[index].emplace_back( - std::span {rawHardReference.begin(), - rawHardReference.end()}); + hardReferences[index].emplace_back(rawHardReference); } } } @@ -342,11 +340,11 @@ eastl::vector> BigFile::GetAssetsTime(const placeholders += "?"; } - const std::string sql = fmt::format( + const eastl::string sql = Format( "SELECT UUID, CreateTime, ModificationTime FROM AssetMetadata WHERE UUID IN ({});", placeholders); - BigFile::Request timeRequest {*this, sql.c_str()}; + BigFile::Request timeRequest {*this, sql}; for (std::size_t i = 0; i < chunkSize; ++i) { timeRequest.Bind(static_cast(i + 1), distinctUUIDs[chunkStart + i].ToBytes()); @@ -354,9 +352,9 @@ eastl::vector> BigFile::GetAssetsTime(const while (timeRequest.Step()) { - const eastl::span rawUUID = - static_cast>(timeRequest.Get(0)); - const UUID uuid {std::span {rawUUID.begin(), rawUUID.end()}}; + const std::span rawUUID { + static_cast>(timeRequest.Get(0))}; + const UUID uuid {rawUUID}; const auto it = uuidToIndices.find(uuid); ASSERT(EngineAssertHandler, @@ -422,12 +420,11 @@ void BigFile::SaveAssetFlatbuffer(const UUID& p_uuid, hardReferencePlaceholders += "(?, ?)"; } - const std::string hardReferenceSQL = fmt::format( - "INSERT INTO AssetHardReference (UUID, HardReference) VALUES {} " - "ON CONFLICT(UUID, HardReference) DO NOTHING;", - hardReferencePlaceholders); + const eastl::string hardReferenceSQL = Format("INSERT INTO AssetHardReference (UUID, HardReference) VALUES {} " + "ON CONFLICT(UUID, HardReference) DO NOTHING;", + hardReferencePlaceholders); - BigFile::Request hardReferenceRequest {*this, hardReferenceSQL.c_str()}; + BigFile::Request hardReferenceRequest {*this, hardReferenceSQL}; std::uint32_t bindIndex = 1; for (std::size_t i = 0; i < chunkSize; ++i) { @@ -477,11 +474,11 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span p_uuids, metadataPlaceholders += "(?)"; } - const std::string metadataSQL = fmt::format( + const eastl::string metadataSQL = Format( "INSERT INTO AssetMetadata (UUID) VALUES {} ON CONFLICT(UUID) DO NOTHING;", metadataPlaceholders); - BigFile::Request metadataRequest {*this, metadataSQL.c_str()}; + BigFile::Request metadataRequest {*this, metadataSQL}; std::uint32_t metadataBindIndex = 1; for (std::size_t i = 0; i < chunkSize; ++i) { @@ -500,11 +497,11 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span p_uuids, assetPlaceholders += "(?, ?)"; } - const std::string assetSQL = fmt::format( + const eastl::string assetSQL = Format( "INSERT INTO Asset (UUID, Asset) VALUES {} ON CONFLICT(UUID) DO UPDATE SET Asset = excluded.Asset;", assetPlaceholders); - BigFile::Request assetRequest {*this, assetSQL.c_str()}; + BigFile::Request assetRequest {*this, assetSQL}; std::uint32_t assetBindIndex = 1; for (std::size_t i = 0; i < chunkSize; ++i) { @@ -525,10 +522,10 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span p_uuids, deleteInPlaceholders += "?"; } - const std::string deleteHardReferencesSQL = fmt::format("DELETE FROM AssetHardReference WHERE UUID IN ({});", - deleteInPlaceholders); + const eastl::string deleteHardReferencesSQL = Format("DELETE FROM AssetHardReference WHERE UUID IN ({});", + deleteInPlaceholders); - BigFile::Request deleteHardReferencesRequest {*this, deleteHardReferencesSQL.c_str()}; + BigFile::Request deleteHardReferencesRequest {*this, deleteHardReferencesSQL}; for (std::size_t i = 0; i < chunkSize; ++i) { deleteHardReferencesRequest.Bind(static_cast(i + 1), p_uuids[chunkStart + i].ToBytes()); @@ -566,12 +563,12 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span p_uuids, hardReferencePlaceholders += "(?, ?)"; } - const std::string hardReferenceSQL = fmt::format( + const eastl::string hardReferenceSQL = Format( "INSERT INTO AssetHardReference (UUID, HardReference) VALUES {} " "ON CONFLICT(UUID, HardReference) DO NOTHING;", hardReferencePlaceholders); - BigFile::Request hardReferenceRequest {*this, hardReferenceSQL.c_str()}; + BigFile::Request hardReferenceRequest {*this, hardReferenceSQL}; std::uint32_t bindIndex = 1; for (std::size_t i = 0; i < hardRefChunkSize; ++i) { @@ -819,6 +816,14 @@ BigFile::Request::Column::operator eastl::span() const /****************************************************************************************/ +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))}; +} + +/****************************************************************************************/ + BigFile::Request::Column BigFile::Request::Get(const std::uint32_t p_index) const { ASSERT(EngineAssertHandler, diff --git a/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp b/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp index 3225d18..675ee8f 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp @@ -15,8 +15,11 @@ #include #include +#include #include +#include + namespace Bigfoot { #ifdef BIGFOOT_TOOLMODE @@ -325,6 +328,13 @@ class BigFile: public DataAccessor */ operator eastl::span() const; + /* + * Get value as a blob + * + * \return The value + */ + operator std::span() const; + private: /* * The statement diff --git a/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp b/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp index a625eeb..3880c4c 100644 --- a/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp +++ b/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp @@ -6,6 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_SYSTEM_UUID_UUID_HPP #define BIGFOOT_SYSTEM_UUID_UUID_HPP +#include #include #include #include @@ -52,7 +53,7 @@ class UUID * \return A string representing the UUID */ [[nodiscard]] - std::string ToString() const; + eastl::string ToString() const; operator bool() const; @@ -127,7 +128,7 @@ struct fmt::formatter auto format(const Bigfoot::UUID& p_uuid, format_context& ctx) const { - return fmt::format_to(ctx.out(), "{}", p_uuid.ToString()); + return fmt::format_to(ctx.out(), "{}", p_uuid.ToString().c_str()); } }; @@ -146,7 +147,7 @@ struct fmtquill::formatter auto format(const Bigfoot::UUID& p_uuid, format_context& ctx) const { - return fmtquill::format_to(ctx.out(), "{}", p_uuid.ToString()); + return fmtquill::format_to(ctx.out(), "{}", p_uuid.ToString().c_str()); } }; diff --git a/Bigfoot/Sources/System/UUID/UUID.cpp b/Bigfoot/Sources/System/UUID/UUID.cpp index a69347d..9c7ada1 100644 --- a/Bigfoot/Sources/System/UUID/UUID.cpp +++ b/Bigfoot/Sources/System/UUID/UUID.cpp @@ -50,9 +50,10 @@ std::span UUID::ToBytes() const /****************************************************************************************/ -std::string UUID::ToString() const +eastl::string UUID::ToString() const { - return uuids::to_string(m_uuid); + const std::string uuid = uuids::to_string(m_uuid); + return eastl::string {uuid.data(), uuid.size()}; } /****************************************************************************************/ diff --git a/Bigfoot/Sources/Tools/SasquatchBaker/SasquatchBaker.cpp b/Bigfoot/Sources/Tools/SasquatchBaker/SasquatchBaker.cpp index 9293392..97f6ea2 100644 --- a/Bigfoot/Sources/Tools/SasquatchBaker/SasquatchBaker.cpp +++ b/Bigfoot/Sources/Tools/SasquatchBaker/SasquatchBaker.cpp @@ -47,7 +47,7 @@ void Bake(const BigFile& p_bigFile, const File& p_outputFile) BigFile::Request request {p_bigFile, "SELECT UUID FROM Asset;"}; while (request.Step()) { - const eastl::span rawUUID = request.Get(0); + const std::span rawUUID = request.Get(0); ASSERT(SasquatchBakerAssertHandler, rawUUID.size() == UUID::UUID_BYTE_SIZE, diff --git a/Bigfoot/Sources/Utils/Include/Utils/Assert/Assert.hpp b/Bigfoot/Sources/Utils/Include/Utils/Assert/Assert.hpp index d3364c1..2181e09 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Assert/Assert.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Assert/Assert.hpp @@ -11,9 +11,10 @@ #if defined BIGFOOT_NOT_OPTIMIZED +#include + #include #include -#include #include #include @@ -84,24 +85,21 @@ BIGFOOT_ALWAYS_INLINE void CriticalAssertCheck(const bool p_condition, ::Bigfoot::AssertCheck((p_assert), \ [&] \ { \ - return eastl::string { \ - fmt::format(p_message __VA_OPT__(, ) __VA_ARGS__).c_str()}; \ + return ::Bigfoot::Format(p_message __VA_OPT__(, ) __VA_ARGS__); \ }) #define SOFT_ASSERT(HANDLER, p_assert, p_message, ...) \ ::Bigfoot::AssertCheck((p_assert), \ [&] \ { \ - return eastl::string { \ - fmt::format(p_message __VA_OPT__(, ) __VA_ARGS__).c_str()}; \ + return ::Bigfoot::Format(p_message __VA_OPT__(, ) __VA_ARGS__); \ }) #define CRITICAL_ASSERT(HANDLER, p_assert, p_message, ...) \ ::Bigfoot::CriticalAssertCheck((p_assert), \ [&] \ { \ - return eastl::string { \ - fmt::format(p_message __VA_OPT__(, ) __VA_ARGS__).c_str()}; \ + return ::Bigfoot::Format(p_message __VA_OPT__(, ) __VA_ARGS__); \ }) #else diff --git a/Bigfoot/Sources/Utils/Include/Utils/Format.hpp b/Bigfoot/Sources/Utils/Include/Utils/Format.hpp new file mode 100644 index 0000000..65474be --- /dev/null +++ b/Bigfoot/Sources/Utils/Include/Utils/Format.hpp @@ -0,0 +1,31 @@ +/********************************************************************* + * \file Format.hpp + * + * \author Romain BOULLARD + * \date September 2026 + *********************************************************************/ +#ifndef BIGFOOT_UTILS_FORMAT_HPP +#define BIGFOOT_UTILS_FORMAT_HPP +#include +#include + +#include + +namespace Bigfoot +{ +/** + * Format a string, like fmt::format, but returning an eastl::string instead of a std::string. + * + * \param p_format The format string + * \param p_args The arguments for the format string + * \return The formatted eastl::string + */ +template +eastl::string Format(fmt::format_string p_format, ARGS&&... p_args) +{ + fmt::memory_buffer buffer; + fmt::format_to(std::back_inserter(buffer), p_format, std::forward(p_args)...); + return eastl::string {buffer.data(), buffer.size()}; +} +} // namespace Bigfoot +#endif diff --git a/Bigfoot/Sources/Utils/Include/Utils/Version.hpp b/Bigfoot/Sources/Utils/Include/Utils/Version.hpp index bae34fe..804c54e 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Version.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Version.hpp @@ -7,12 +7,13 @@ #ifndef BIGFOOT_UTILS_VERSION_HPP #define BIGFOOT_UTILS_VERSION_HPP #include +#include #include +#include #include #include -#include namespace Bigfoot { @@ -99,7 +100,7 @@ class Version * \return The string */ [[nodiscard]] - std::string ToString() const; + eastl::string ToString() const; [[nodiscard]] constexpr auto operator<=>(const Version& p_version) const = default; @@ -126,7 +127,7 @@ struct fmt::formatter template auto format(const Bigfoot::Version& p_version, FormatContext& p_context) const { - return fmt::format_to(p_context.out(), "{}", p_version.ToString()); + return fmt::format_to(p_context.out(), "{}", p_version.ToString().c_str()); } }; #endif diff --git a/Bigfoot/Sources/Utils/Version.cpp b/Bigfoot/Sources/Utils/Version.cpp index 4778e02..465538a 100644 --- a/Bigfoot/Sources/Utils/Version.cpp +++ b/Bigfoot/Sources/Utils/Version.cpp @@ -8,8 +8,8 @@ namespace Bigfoot { -std::string Version::ToString() const +eastl::string Version::ToString() const { - return fmt::format("{}.{}.{}", GetMajor(), GetMinor(), GetPatch()); + return Format("{}.{}.{}", GetMajor(), GetMinor(), GetPatch()); } } // namespace Bigfoot diff --git a/Bigfoot/Tests/System/UUID/UUID.cpp b/Bigfoot/Tests/System/UUID/UUID.cpp index 39480f3..bb6c26d 100644 --- a/Bigfoot/Tests/System/UUID/UUID.cpp +++ b/Bigfoot/Tests/System/UUID/UUID.cpp @@ -8,6 +8,8 @@ #include +#include + #include #include #include @@ -203,7 +205,7 @@ TEST_F(UUIDFixture, UnPack_ShouldGiveBackTheOriginalUUID) TEST_F(UUIDFixture, FormatsUUID) { - EXPECT_EQ(fmt::format("{}", m_b), m_b.ToString()); - EXPECT_EQ(fmt::format("{}", UUID::NULL_UUID), "00000000-0000-0000-0000-000000000000"); + EXPECT_STREQ(Format("{}", m_b).c_str(), m_b.ToString().c_str()); + EXPECT_STREQ(Format("{}", UUID::NULL_UUID).c_str(), "00000000-0000-0000-0000-000000000000"); } } // namespace Bigfoot diff --git a/Bigfoot/Tests/Utils/Assert/AssertHandler.cpp b/Bigfoot/Tests/Utils/Assert/AssertHandler.cpp index 3c19238..5645a9f 100644 --- a/Bigfoot/Tests/Utils/Assert/AssertHandler.cpp +++ b/Bigfoot/Tests/Utils/Assert/AssertHandler.cpp @@ -6,34 +6,34 @@ *********************************************************************/ #include +#include #include #include #if defined BIGFOOT_NOT_OPTIMIZED -#include -#include #include #include #include #include #include +#include namespace Bigfoot { class AssertHandlerFixture: public ::testing::Test { protected: - eastl::string ReadFileSinkContent() + std::string ReadFileSinkContent() { Singleton::GetInstance().Flush(); std::ifstream file {std::string {Log::FILE_SINK_PATH.data()}}; std::stringstream buffer; buffer << file.rdbuf(); - return eastl::string {buffer.str().c_str()}; + return buffer.str(); } }; @@ -42,10 +42,9 @@ class AssertHandlerFixture: public ::testing::Test TEST_F(AssertHandlerFixture, Handle_ShouldLogAFatalMessageContainingTheGivenMessage) { constexpr std::source_location location = std::source_location::current(); - AssertHandler::Handle(location, - eastl::string {fmt::format("Something went wrong: {}", 42).c_str()}); + AssertHandler::Handle(location, Format("Something went wrong: {}", 42)); - EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Something went wrong: 42")); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr("Something went wrong: 42")); } /****************************************************************************************/ @@ -55,7 +54,7 @@ TEST_F(AssertHandlerFixture, Handle_ShouldLogAFatalMessageContainingTheSourceLoc constexpr std::source_location location = std::source_location::current(); AssertHandler::Handle(location, "Doesn't matter"); - const std::string content {ReadFileSinkContent().c_str()}; + const std::string content = ReadFileSinkContent(); EXPECT_THAT(content, ::testing::HasSubstr(location.file_name())); EXPECT_THAT(content, ::testing::HasSubstr(location.function_name())); } diff --git a/Bigfoot/Tests/Utils/Format.cpp b/Bigfoot/Tests/Utils/Format.cpp new file mode 100644 index 0000000..4faccf6 --- /dev/null +++ b/Bigfoot/Tests/Utils/Format.cpp @@ -0,0 +1,48 @@ +/********************************************************************* + * \file Format.cpp + * + * \author Romain BOULLARD + * \date September 2026 + *********************************************************************/ +#include + +#include +#include + +namespace Bigfoot +{ +TEST(Format, ShouldReturnAnEastlString) +{ + const eastl::string result = Format("Hello"); + EXPECT_STREQ(result.c_str(), "Hello"); +} + +/****************************************************************************************/ + +TEST(Format, ShouldFormatASingleArgument) +{ + EXPECT_STREQ(Format("Value: {}", 42).c_str(), "Value: 42"); +} + +/****************************************************************************************/ + +TEST(Format, ShouldFormatMultipleArguments) +{ + EXPECT_STREQ(Format("{} + {} = {}", 1, 2, 3).c_str(), "1 + 2 = 3"); +} + +/****************************************************************************************/ + +TEST(Format, ShouldReturnAnEmptyStringForAnEmptyFormat) +{ + EXPECT_STREQ(Format("").c_str(), ""); +} + +/****************************************************************************************/ + +TEST(Format, ShouldFormatAStringLongerThanTheSmallStringOptimizationBuffer) +{ + const eastl::string expected(256, 'a'); + EXPECT_STREQ(Format("{}", expected.c_str()).c_str(), expected.c_str()); +} +} // namespace Bigfoot diff --git a/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp b/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp index edf4a10..fab5e17 100644 --- a/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp +++ b/Bigfoot/Tests/Utils/Log/EASTLFormatters.cpp @@ -20,6 +20,7 @@ #include #include +#include namespace Bigfoot { @@ -88,14 +89,14 @@ TEST_F(EASTLFormattersFixture, FormatsNestedVectors) class EASTLFormattersLogFixture: public ::testing::Test { protected: - eastl::string ReadFileSinkContent() + std::string ReadFileSinkContent() { Singleton::GetInstance().Flush(); std::ifstream file {std::string {Log::FILE_SINK_PATH.data()}}; std::stringstream buffer; buffer << file.rdbuf(); - return eastl::string {buffer.str().c_str()}; + return buffer.str(); } }; @@ -105,7 +106,7 @@ TEST_F(EASTLFormattersLogFixture, LogsEastlStringArgument) { const eastl::string value = "Hello EASTL string"; BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value); - EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello EASTL string")); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr("Hello EASTL string")); } /****************************************************************************************/ @@ -114,7 +115,7 @@ TEST_F(EASTLFormattersLogFixture, LogsEmptyVectorArgument) { const eastl::vector value; BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value); - EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("[]")); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr("[]")); } /****************************************************************************************/ @@ -123,7 +124,7 @@ TEST_F(EASTLFormattersLogFixture, LogsVectorArgumentWithCommaSeparators) { const eastl::vector value {"a", "b", "c"}; BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value); - EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("[a, b, c]")); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr("[a, b, c]")); } #endif } // namespace Bigfoot diff --git a/Bigfoot/Tests/Utils/Log/LogMacros.cpp b/Bigfoot/Tests/Utils/Log/LogMacros.cpp index d2240c6..9a0981c 100644 --- a/Bigfoot/Tests/Utils/Log/LogMacros.cpp +++ b/Bigfoot/Tests/Utils/Log/LogMacros.cpp @@ -12,26 +12,26 @@ #if defined BIGFOOT_NOT_OPTIMIZED -#include #include #include #include #include +#include namespace Bigfoot { class LogMacrosFixture: public ::testing::Test { protected: - eastl::string ReadFileSinkContent() + std::string ReadFileSinkContent() { Singleton::GetInstance().Flush(); std::ifstream file {std::string {Log::FILE_SINK_PATH.data()}}; std::stringstream buffer; buffer << file.rdbuf(); - return eastl::string {buffer.str().c_str()}; + return buffer.str(); } }; @@ -40,7 +40,7 @@ class LogMacrosFixture: public ::testing::Test TEST_F(LogMacrosFixture, LogDebug) { BIGFOOT_LOG_DEBUG(UTILSTESTS_LOGGER, "Hello Debug"); - EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Debug")); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr("Hello Debug")); } /****************************************************************************************/ @@ -48,7 +48,7 @@ TEST_F(LogMacrosFixture, LogDebug) TEST_F(LogMacrosFixture, LogTrace) { BIGFOOT_LOG_TRACE(UTILSTESTS_LOGGER, "Hello Trace"); - EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Trace")); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr("Hello Trace")); } /****************************************************************************************/ @@ -56,7 +56,7 @@ TEST_F(LogMacrosFixture, LogTrace) TEST_F(LogMacrosFixture, LogInfo) { BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "Hello Info"); - EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Info")); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr("Hello Info")); } /****************************************************************************************/ @@ -64,7 +64,7 @@ TEST_F(LogMacrosFixture, LogInfo) TEST_F(LogMacrosFixture, LogWarn) { BIGFOOT_LOG_WARN(UTILSTESTS_LOGGER, "Hello Warn"); - EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Warn")); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr("Hello Warn")); } /****************************************************************************************/ @@ -72,7 +72,7 @@ TEST_F(LogMacrosFixture, LogWarn) TEST_F(LogMacrosFixture, LogError) { BIGFOOT_LOG_ERROR(UTILSTESTS_LOGGER, "Hello Error"); - EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Error")); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr("Hello Error")); } /****************************************************************************************/ @@ -80,7 +80,7 @@ TEST_F(LogMacrosFixture, LogError) TEST_F(LogMacrosFixture, LogFatal) { BIGFOOT_LOG_FATAL(UTILSTESTS_LOGGER, "Hello Fatal"); - EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Fatal")); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr("Hello Fatal")); } } // namespace Bigfoot #endif diff --git a/Bigfoot/Tests/Utils/Version.cpp b/Bigfoot/Tests/Utils/Version.cpp index 7c9998b..34feb36 100644 --- a/Bigfoot/Tests/Utils/Version.cpp +++ b/Bigfoot/Tests/Utils/Version.cpp @@ -6,6 +6,8 @@ *********************************************************************/ #include +#include + #include namespace Bigfoot @@ -75,7 +77,7 @@ TEST_F(VersionFixture, Comparisons) TEST_F(VersionFixture, FormatsVersion) { - EXPECT_EQ(fmt::format("{}", m_detailed), "1.2.3"); - EXPECT_EQ(fmt::format("{}", m_combined), "1.2.3"); + EXPECT_STREQ(Format("{}", m_detailed).c_str(), "1.2.3"); + EXPECT_STREQ(Format("{}", m_combined).c_str(), "1.2.3"); } } // namespace Bigfoot