Reduce back and forth between std and eastl
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 47s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 28s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 52s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 34s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m16s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 42s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 26s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 45s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 28s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m12s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 59s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m17s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 59s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 1m0s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m24s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m6s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 35s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 25s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 53s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 42s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 46s
sonarqube ERROR
Bigfoot / Sonarqube (pull_request) Failing after 4m45s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 52s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 59s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 49s
Bigfoot / Clang Format Checks (push) Successful in 9s

This commit is contained in:
2026-09-01 15:05:25 +02:00
parent a3652c9888
commit 8392245b10
19 changed files with 194 additions and 95 deletions
@@ -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)
{
@@ -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);
}
@@ -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<BenchmarkAsset>();
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<BenchmarkAsset>();
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)
{
@@ -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<std::byte> flatbuffer = asset.Pack();
+45 -40
View File
@@ -8,8 +8,9 @@
#include <Engine/EngineAssertHandler.hpp>
#include <Utils/Format.hpp>
#include <EASTL/algorithm.h>
#include <fmt/format.h>
namespace Bigfoot
{
@@ -149,9 +150,9 @@ eastl::vector<eastl::vector<std::byte>> 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<std::uint32_t>(i + 1), distinctUUIDs[chunkStart + i].ToBytes());
@@ -159,9 +160,9 @@ eastl::vector<eastl::vector<std::byte>> BigFile::GetAssetFlatbuffers(const eastl
while (assetRequest.Step())
{
const eastl::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID =
static_cast<eastl::span<const std::byte>>(assetRequest.Get(0));
const UUID uuid {std::span<const std::byte, UUID::UUID_BYTE_SIZE> {rawUUID.begin(), rawUUID.end()}};
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID {
static_cast<std::span<const std::byte>>(assetRequest.Get(0))};
const UUID uuid {rawUUID};
const auto it = uuidToIndices.find(uuid);
ASSERT(EngineAssertHandler,
@@ -191,9 +192,9 @@ eastl::vector<UUID> BigFile::GetAssetHardReferences(const UUID& p_uuid) const
eastl::vector<UUID> hardReferences;
while (hardReferencesRequest.Step())
{
const eastl::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID = static_cast<eastl::span<const std::byte>>(
hardReferencesRequest.Get(0));
hardReferences.emplace_back(std::span<const std::byte, UUID::UUID_BYTE_SIZE>(rawUUID.begin(), rawUUID.end()));
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID {
static_cast<std::span<const std::byte>>(hardReferencesRequest.Get(0))};
hardReferences.emplace_back(rawUUID);
}
return hardReferences;
@@ -244,10 +245,10 @@ eastl::vector<eastl::vector<UUID>> 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<std::uint32_t>(i + 1), distinctUUIDs[chunkStart + i].ToBytes());
@@ -255,10 +256,9 @@ eastl::vector<eastl::vector<UUID>> BigFile::GetAssetsHardReferences(eastl::span<
while (hardReferencesRequest.Step())
{
const eastl::span<const std::byte, UUID::UUID_BYTE_SIZE> rawOwnerUUID =
static_cast<eastl::span<const std::byte>>(hardReferencesRequest.Get(0));
const UUID ownerUUID {
std::span<const std::byte, UUID::UUID_BYTE_SIZE> {rawOwnerUUID.begin(), rawOwnerUUID.end()}};
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawOwnerUUID {
static_cast<std::span<const std::byte>>(hardReferencesRequest.Get(0))};
const UUID ownerUUID {rawOwnerUUID};
const auto it = uuidToIndices.find(ownerUUID);
ASSERT(EngineAssertHandler,
@@ -266,14 +266,12 @@ eastl::vector<eastl::vector<UUID>> BigFile::GetAssetsHardReferences(eastl::span<
"Returned UUID {} not found in requested UUIDs",
ownerUUID);
const eastl::span<const std::byte, UUID::UUID_BYTE_SIZE> rawHardReference =
static_cast<eastl::span<const std::byte>>(hardReferencesRequest.Get(1));
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawHardReference {
static_cast<std::span<const std::byte>>(hardReferencesRequest.Get(1))};
for (const std::size_t index: it->second)
{
hardReferences[index].emplace_back(
std::span<const std::byte, UUID::UUID_BYTE_SIZE> {rawHardReference.begin(),
rawHardReference.end()});
hardReferences[index].emplace_back(rawHardReference);
}
}
}
@@ -342,11 +340,11 @@ eastl::vector<eastl::optional<BigFile::AssetTime>> 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<std::uint32_t>(i + 1), distinctUUIDs[chunkStart + i].ToBytes());
@@ -354,9 +352,9 @@ eastl::vector<eastl::optional<BigFile::AssetTime>> BigFile::GetAssetsTime(const
while (timeRequest.Step())
{
const eastl::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID =
static_cast<eastl::span<const std::byte>>(timeRequest.Get(0));
const UUID uuid {std::span<const std::byte, UUID::UUID_BYTE_SIZE> {rawUUID.begin(), rawUUID.end()}};
const std::span<const std::byte, UUID::UUID_BYTE_SIZE> rawUUID {
static_cast<std::span<const std::byte>>(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<const UUID> 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<const UUID> 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<const UUID> 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<std::uint32_t>(i + 1), p_uuids[chunkStart + i].ToBytes());
@@ -566,12 +563,12 @@ void BigFile::SaveAssetFlatbuffers(const eastl::span<const UUID> 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 std::byte>() const
/****************************************************************************************/
BigFile::Request::Column::operator std::span<const std::byte>() const
{
return std::span<const std::byte> {static_cast<const std::byte*>(sqlite3_column_blob(m_statement, m_index)),
static_cast<std::size_t>(sqlite3_column_bytes(m_statement, m_index))};
}
/****************************************************************************************/
BigFile::Request::Column BigFile::Request::Get(const std::uint32_t p_index) const
{
ASSERT(EngineAssertHandler,
@@ -15,8 +15,11 @@
#include <EASTL/optional.h>
#include <EASTL/span.h>
#include <EASTL/string_view.h>
#include <sqlite3.h>
#include <span>
namespace Bigfoot
{
#ifdef BIGFOOT_TOOLMODE
@@ -325,6 +328,13 @@ class BigFile: public DataAccessor
*/
operator eastl::span<const std::byte>() const;
/*
* Get value as a blob
*
* \return The value
*/
operator std::span<const std::byte>() const;
private:
/*
* The statement
@@ -6,6 +6,7 @@
*********************************************************************/
#ifndef BIGFOOT_SYSTEM_UUID_UUID_HPP
#define BIGFOOT_SYSTEM_UUID_UUID_HPP
#include <EASTL/string.h>
#include <ankerl/unordered_dense.h>
#include <fmt/format.h>
#include <uuid.h>
@@ -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<Bigfoot::UUID>
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<Bigfoot::UUID>
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());
}
};
+3 -2
View File
@@ -50,9 +50,10 @@ std::span<const std::byte, UUID::UUID_BYTE_SIZE> 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()};
}
/****************************************************************************************/
@@ -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<const std::byte> rawUUID = request.Get(0);
const std::span<const std::byte> rawUUID = request.Get(0);
ASSERT(SasquatchBakerAssertHandler,
rawUUID.size() == UUID::UUID_BYTE_SIZE,
@@ -11,9 +11,10 @@
#if defined BIGFOOT_NOT_OPTIMIZED
#include <Utils/Format.hpp>
#include <EASTL/fixed_function.h>
#include <EASTL/string.h>
#include <fmt/format.h>
#include <cstdlib>
#include <source_location>
@@ -84,24 +85,21 @@ BIGFOOT_ALWAYS_INLINE void CriticalAssertCheck(const bool p_condition,
::Bigfoot::AssertCheck<HANDLER>((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<HANDLER>((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<HANDLER>((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
@@ -0,0 +1,31 @@
/*********************************************************************
* \file Format.hpp
*
* \author Romain BOULLARD
* \date September 2026
*********************************************************************/
#ifndef BIGFOOT_UTILS_FORMAT_HPP
#define BIGFOOT_UTILS_FORMAT_HPP
#include <EASTL/string.h>
#include <fmt/format.h>
#include <iterator>
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<typename... ARGS>
eastl::string Format(fmt::format_string<ARGS...> p_format, ARGS&&... p_args)
{
fmt::memory_buffer buffer;
fmt::format_to(std::back_inserter(buffer), p_format, std::forward<ARGS>(p_args)...);
return eastl::string {buffer.data(), buffer.size()};
}
} // namespace Bigfoot
#endif
@@ -7,12 +7,13 @@
#ifndef BIGFOOT_UTILS_VERSION_HPP
#define BIGFOOT_UTILS_VERSION_HPP
#include <Utils/Caster.hpp>
#include <Utils/Format.hpp>
#include <Utils/TargetMacros.h>
#include <EASTL/string.h>
#include <fmt/format.h>
#include <cstdint>
#include <string>
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<Bigfoot::Version>
template<typename FormatContext>
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
+2 -2
View File
@@ -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
+4 -2
View File
@@ -8,6 +8,8 @@
#include <System/UUID/UUID_generated.hpp>
#include <Utils/Format.hpp>
#include <ankerl/unordered_dense.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -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
+7 -8
View File
@@ -6,34 +6,34 @@
*********************************************************************/
#include <Utils/Assert/AssertHandler.hpp>
#include <Utils/Format.hpp>
#include <Utils/Singleton.hpp>
#include <UtilsTests/UtilsTestsLogger_generated.hpp>
#if defined BIGFOOT_NOT_OPTIMIZED
#include <EASTL/string.h>
#include <fmt/format.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <fstream>
#include <source_location>
#include <sstream>
#include <string>
namespace Bigfoot
{
class AssertHandlerFixture: public ::testing::Test
{
protected:
eastl::string ReadFileSinkContent()
std::string ReadFileSinkContent()
{
Singleton<Log>::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<UTILSTESTS_LOGGER>::Handle(location,
eastl::string {fmt::format("Something went wrong: {}", 42).c_str()});
AssertHandler<UTILSTESTS_LOGGER>::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<UTILSTESTS_LOGGER>::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()));
}
+48
View File
@@ -0,0 +1,48 @@
/*********************************************************************
* \file Format.cpp
*
* \author Romain BOULLARD
* \date September 2026
*********************************************************************/
#include <Utils/Format.hpp>
#include <EASTL/string.h>
#include <gtest/gtest.h>
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
+6 -5
View File
@@ -20,6 +20,7 @@
#include <fstream>
#include <sstream>
#include <string>
namespace Bigfoot
{
@@ -88,14 +89,14 @@ TEST_F(EASTLFormattersFixture, FormatsNestedVectors)
class EASTLFormattersLogFixture: public ::testing::Test
{
protected:
eastl::string ReadFileSinkContent()
std::string ReadFileSinkContent()
{
Singleton<Log>::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<int> 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<eastl::string> 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
+9 -9
View File
@@ -12,26 +12,26 @@
#if defined BIGFOOT_NOT_OPTIMIZED
#include <EASTL/string.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <fstream>
#include <sstream>
#include <string>
namespace Bigfoot
{
class LogMacrosFixture: public ::testing::Test
{
protected:
eastl::string ReadFileSinkContent()
std::string ReadFileSinkContent()
{
Singleton<Log>::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
+4 -2
View File
@@ -6,6 +6,8 @@
*********************************************************************/
#include <Utils/Version.hpp>
#include <Utils/Format.hpp>
#include <gtest/gtest.h>
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