From a343d655984481029c9df2e5251bbc3d9cdb46ad Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sat, 16 May 2026 17:39:58 +0200 Subject: [PATCH] Maintenance --- .../System/Include/System/UUID/UUID.hpp | 24 +++++++++++++++---- Bigfoot/Sources/System/UUID/UUID.cpp | 18 +++++++++++--- .../Sources/Utils/Include/Utils/Version.hpp | 17 ++++++++++--- Bigfoot/Sources/Utils/Version.cpp | 2 +- Bigfoot/Tests/Engine/BigFile/BigFile.cpp | 16 ++++++------- Bigfoot/Tests/System/UUID/UUID.cpp | 16 ++++++------- Bigfoot/Tests/Utils/Version.cpp | 12 +++++----- 7 files changed, 71 insertions(+), 34 deletions(-) diff --git a/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp b/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp index ba1f655..1b0dfa9 100644 --- a/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp +++ b/Bigfoot/Sources/System/Include/System/UUID/UUID.hpp @@ -34,19 +34,33 @@ class UUID UUID(const UUID& p_uuid) = default; UUID(UUID&& p_uuid) noexcept = default; + /** + * Gets the raw bytes of a UUID + * + * \return A view to the raw bytes + */ + [[nodiscard]] + std::span ToBytes() const; + + /** + * Gets the string representation of a UUID + * + * \return A string representing the UUID + */ + [[nodiscard]] + std::string ToString() const; + ~UUID() = default; - operator std::span() const; - operator std::string() const; operator bool() const; UUID& operator=(const UUID& p_uuid) = default; UUID& operator=(UUID&& p_uuid) noexcept = default; [[nodiscard]] - bool operator==(const UUID& p_uuid) const = default; + bool operator==(const UUID& p_uuid) const; [[nodiscard]] - bool operator<(const UUID& p_uuid) const = default; + bool operator<(const UUID& p_uuid) const; private: /** @@ -130,7 +144,7 @@ struct fmtquill::formatter auto format(const Bigfoot::UUID& p_uuid, format_context& ctx) const { - return fmtquill::format_to(ctx.out(), "{}", static_cast(p_uuid)); + return fmtquill::format_to(ctx.out(), "{}", p_uuid.ToString()); } }; diff --git a/Bigfoot/Sources/System/UUID/UUID.cpp b/Bigfoot/Sources/System/UUID/UUID.cpp index 8c63dda..a69347d 100644 --- a/Bigfoot/Sources/System/UUID/UUID.cpp +++ b/Bigfoot/Sources/System/UUID/UUID.cpp @@ -43,14 +43,14 @@ UUID::UUID(const std::span p_raw) /****************************************************************************************/ -UUID::operator std::span() const +std::span UUID::ToBytes() const { return m_uuid.as_bytes(); } /****************************************************************************************/ -UUID::operator std::string() const +std::string UUID::ToString() const { return uuids::to_string(m_uuid); } @@ -62,6 +62,18 @@ UUID::operator bool() const return *this != NULL_UUID; } +bool UUID::operator==(const UUID& p_uuid) const +{ + return m_uuid == p_uuid.m_uuid; +} + +/****************************************************************************************/ + +bool UUID::operator<(const UUID& p_uuid) const +{ + return m_uuid < p_uuid.m_uuid; +} + /****************************************************************************************/ std::mt19937 UUID::GetRandomGenerator() @@ -87,7 +99,7 @@ namespace flatbuffers { Flat::Bigfoot::UUID Pack(const Bigfoot::UUID& p_uuid) { - const std::span bytes = p_uuid; + const std::span bytes = p_uuid.ToBytes(); return Flat::Bigfoot::UUID { std::span {reinterpret_cast(bytes.data()), bytes.size()}}; diff --git a/Bigfoot/Sources/Utils/Include/Utils/Version.hpp b/Bigfoot/Sources/Utils/Include/Utils/Version.hpp index 3560dce..40a3481 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Version.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Version.hpp @@ -86,13 +86,24 @@ class Version return static_cast(m_combined & mask); } + /** + * Gets the raw Version + * + * \return the raw version + */ [[nodiscard]] - constexpr operator std::uint32_t() const + constexpr std::uint32_t Raw() const { return m_combined; } - operator std::string() const; + /** + * Gets the string representation of the Version + * + * \return The string + */ + [[nodiscard]] + std::string ToString() const; constexpr Version& operator=(const Version& p_version) = default; constexpr Version& operator=(Version&& p_version) = default; @@ -123,7 +134,7 @@ struct std::formatter template auto format(const Bigfoot::Version& p_version, FormatContext& p_context) const { - return std::format_to(p_context.out(), "{}", static_cast(p_version)); + return std::format_to(p_context.out(), "{}", p_version.ToString()); } }; #endif diff --git a/Bigfoot/Sources/Utils/Version.cpp b/Bigfoot/Sources/Utils/Version.cpp index d7176fd..6423659 100644 --- a/Bigfoot/Sources/Utils/Version.cpp +++ b/Bigfoot/Sources/Utils/Version.cpp @@ -8,7 +8,7 @@ namespace Bigfoot { -Version::operator std::string() const +std::string Version::ToString() const { return std::format("{}.{}.{}", GetMajor(), GetMinor(), GetPatch()); } diff --git a/Bigfoot/Tests/Engine/BigFile/BigFile.cpp b/Bigfoot/Tests/Engine/BigFile/BigFile.cpp index 99cf21b..19f2c31 100644 --- a/Bigfoot/Tests/Engine/BigFile/BigFile.cpp +++ b/Bigfoot/Tests/Engine/BigFile/BigFile.cpp @@ -53,37 +53,37 @@ TEST_F(BigFileFixture, BigFileManipulation) BigFile::Request assetHeaderRequest { m_bigFile, "INSERT INTO AssetHeader (UUID, Name, TypeID, TypeName) VALUES(?, ?, ?, ?)"}; - assetHeaderRequest.Bind(1, static_cast>(uuid)); + assetHeaderRequest.Bind(1, uuid.ToBytes()); assetHeaderRequest.Bind(2, "Test"); assetHeaderRequest.Bind(3, typeIDRef); assetHeaderRequest.Bind(4, "TypeTest"); BigFile::Request assetRequest {m_bigFile, "INSERT INTO Asset (UUID, Asset) VALUES(?, ?)"}; - assetRequest.Bind(1, static_cast>(uuid)); + assetRequest.Bind(1, uuid.ToBytes()); assetRequest.Bind(2, blob); BigFile::Request assetHeaderRequest2 { m_bigFile, "INSERT INTO AssetHeader (UUID, Name, TypeID, TypeName) VALUES(?, ?, ?, ?)"}; - assetHeaderRequest2.Bind(1, static_cast>(uuid2)); + assetHeaderRequest2.Bind(1, uuid2.ToBytes()); assetHeaderRequest2.Bind(2, "Test2"); assetHeaderRequest2.Bind(3, typeIDRef); assetHeaderRequest2.Bind(4, "TypeTest"); BigFile::Request assetRequest2 {m_bigFile, "INSERT INTO Asset (UUID, Asset) VALUES(?, ?)"}; - assetRequest2.Bind(1, static_cast>(uuid2)); + assetRequest2.Bind(1, uuid2.ToBytes()); assetRequest2.Bind(2, blob3); BigFile::Request assetHeaderRequest3 { m_bigFile, "INSERT INTO AssetHeader (UUID, Name, TypeID, TypeName) VALUES(?, ?, ?, ?)"}; - assetHeaderRequest3.Bind(1, static_cast>(uuid3)); + assetHeaderRequest3.Bind(1, uuid3.ToBytes()); assetHeaderRequest3.Bind(2, "Test3"); assetHeaderRequest3.Bind(3, typeIDRef); assetHeaderRequest3.Bind(4, "TypeTest"); BigFile::Request assetRequest3 {m_bigFile, "INSERT INTO Asset (UUID, Asset) VALUES(?, ?)"}; - assetRequest3.Bind(1, static_cast>(uuid3)); + assetRequest3.Bind(1, uuid3.ToBytes()); assetRequest3.Bind(2, blob4); m_bigFile.BeginTransaction(); @@ -108,7 +108,7 @@ TEST_F(BigFileFixture, BigFileManipulation) { BigFile::Request updateAsset {m_bigFile, "UPDATE Asset SET Asset = ? WHERE UUID = ?"}; updateAsset.Bind(1, blob2); - updateAsset.Bind(2, static_cast>(uuid)); + updateAsset.Bind(2, uuid.ToBytes()); m_bigFile.BeginTransaction(); std::uint32_t updateAssetChangedCount = updateAsset.Execute(); @@ -120,7 +120,7 @@ TEST_F(BigFileFixture, BigFileManipulation) BigFile::Request request { m_bigFile, "SELECT Name, TypeID, TypeName, CreateTime, ModificationTime FROM AssetHeader WHERE UUID = ?"}; - request.Bind(1, static_cast>(uuid)); + request.Bind(1, uuid.ToBytes()); const bool get = request.Step(); EXPECT_TRUE(get); diff --git a/Bigfoot/Tests/System/UUID/UUID.cpp b/Bigfoot/Tests/System/UUID/UUID.cpp index 5e5b8fa..debfccf 100644 --- a/Bigfoot/Tests/System/UUID/UUID.cpp +++ b/Bigfoot/Tests/System/UUID/UUID.cpp @@ -43,13 +43,13 @@ class UUIDFixture: public ::testing::Test TEST_F(UUIDFixture, DumpingRawAndConstructAnUUIDWithItShouldGiveTheSameUUID) { - std::span raw = m_a; + std::span raw = m_a.ToBytes(); EXPECT_EQ(m_a, UUID {raw}); - raw = m_b; + raw = m_b.ToBytes(); EXPECT_EQ(m_b, UUID {raw}); - raw = m_d; + raw = m_d.ToBytes(); EXPECT_EQ(m_d, UUID {raw}); } @@ -57,21 +57,21 @@ TEST_F(UUIDFixture, DumpingRawAndConstructAnUUIDWithItShouldGiveTheSameUUID) TEST_F(UUIDFixture, ValidIDFromStringShouldBeEqualToString) { - EXPECT_EQ(static_cast(m_b), "47183823-2574-4bfd-b411-99ed177d3e43"); + EXPECT_EQ(m_b.ToString(), "47183823-2574-4bfd-b411-99ed177d3e43"); } /****************************************************************************************/ TEST_F(UUIDFixture, InvalidIDFromStringShouldNotBeEqualToString) { - EXPECT_NE(static_cast(m_c), "4bfd-b411-99ed177d3e43"); + EXPECT_NE(m_c.ToString(), "4bfd-b411-99ed177d3e43"); } /****************************************************************************************/ TEST_F(UUIDFixture, NullIDStringShouldBeEqualToNullIDString) { - EXPECT_EQ(static_cast(UUID::NULL_UUID), "00000000-0000-0000-0000-000000000000"); + EXPECT_EQ(UUID::NULL_UUID.ToString(), "00000000-0000-0000-0000-000000000000"); } /****************************************************************************************/ @@ -168,9 +168,9 @@ TEST_F(UUIDFixture, GeneratingFiveMillionUniqueID) /****************************************************************************************/ -TEST_F(UUIDFixture, Raw_ShouldGiveBackTheRawDataOfTheID) +TEST_F(UUIDFixture, ToBytes_ShouldGiveBackTheRawDataOfTheID) { - std::span d = m_d; + std::span d = m_d.ToBytes(); std::span raw = m_raw; for (std::uint32_t i = 0; i < UUID::UUID_BYTE_SIZE; ++i) diff --git a/Bigfoot/Tests/Utils/Version.cpp b/Bigfoot/Tests/Utils/Version.cpp index a422b33..bba4a02 100644 --- a/Bigfoot/Tests/Utils/Version.cpp +++ b/Bigfoot/Tests/Utils/Version.cpp @@ -19,18 +19,18 @@ class VersionFixture: public ::testing::Test /****************************************************************************************/ -TEST_F(VersionFixture, string) +TEST_F(VersionFixture, ToString) { - EXPECT_STREQ(static_cast(m_detailed).data(), "1.2.3"); - EXPECT_STREQ(static_cast(m_combined).data(), "1.2.3"); + EXPECT_STREQ(m_detailed.ToString().data(), "1.2.3"); + EXPECT_STREQ(m_combined.ToString().data(), "1.2.3"); } /****************************************************************************************/ -TEST_F(VersionFixture, uint32_t) +TEST_F(VersionFixture, Raw) { - EXPECT_EQ(static_cast(m_detailed), (1 << 16) | (2 << 8) | 3); - EXPECT_EQ(static_cast(m_combined), (1 << 16) | (2 << 8) | 3); + EXPECT_EQ(m_detailed.Raw(), (1 << 16) | (2 << 8) | 3); + EXPECT_EQ(m_combined.Raw(), (1 << 16) | (2 << 8) | 3); } /****************************************************************************************/