Files
Bigfoot/Bigfoot/Libs/System/UUID/UUID.cpp
T
rboullard f82d40532c
Bigfoot / Sonarqube (game) (push) Skipped
Bigfoot / Sonarqube (toolmode) (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Failing after 12s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Failing after 11s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Failing after 10s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Failing after 9s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Failing after 10s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Failing after 10s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Failing after 15s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Failing after 9s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Failing after 10s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Failing after 11s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Failing after 10s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Failing after 9s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Failing after 10s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Failing after 11s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Failing after 10s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Failing after 10s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Failing after 10s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Failing after 9s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Failing after 10s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Failing after 9s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Failing after 11s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Failing after 12s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Failing after 10s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Failing after 9s
Bigfoot / Clang Format Checks (push) Failing after 12s
Refactor Bigfoot files layout + Create our three graphics libraries
2026-09-03 00:02:09 +02:00

118 lines
3.6 KiB
C++

/*********************************************************************
* \file UUID.cpp
*
* \author Romain BOULLARD
* \date October 2025
*********************************************************************/
#include <System/UUID/UUID.hpp>
#include <System/UUID/UUID_generated.hpp>
namespace Bigfoot
{
UUID UUID::NULL_UUID {"00000000-0000-0000-0000-000000000000"};
/****************************************************************************************/
UUID::UUID():
m_uuid(ms_uuidGenerator())
{
}
/****************************************************************************************/
UUID::UUID(const std::string_view p_string):
UUID(NULL_UUID)
{
if (const std::optional<uuids::uuid> value = uuids::uuid::from_string(p_string); value.has_value())
{
m_uuid = value.value();
}
}
/****************************************************************************************/
UUID::UUID(const std::span<const std::byte, UUID_BYTE_SIZE> p_raw)
{
const std::span<std::uint8_t, UUID_BYTE_SIZE> raw {
const_cast<std::uint8_t*>(reinterpret_cast<const std::uint8_t*>(p_raw.data())),
UUID_BYTE_SIZE};
m_uuid = uuids::uuid {raw};
}
/****************************************************************************************/
std::span<const std::byte, UUID::UUID_BYTE_SIZE> UUID::ToBytes() const
{
return m_uuid.as_bytes();
}
/****************************************************************************************/
eastl::string UUID::ToString() const
{
const std::string uuid = uuids::to_string(m_uuid);
return eastl::string {uuid.data(), uuid.size()};
}
/****************************************************************************************/
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()
{
std::random_device randomDevice;
std::array<std::uint32_t, std::mt19937::state_size> seed {};
std::generate(seed.begin(), seed.end(), std::reference_wrapper {randomDevice});
std::seed_seq seedSeq(seed.begin(), seed.end());
return std::mt19937 {seedSeq};
}
/****************************************************************************************/
uuids::uuid_random_generator UUID::GetUUIDGenerator()
{
return uuids::uuid_random_generator {ms_randomGenerator};
}
} // namespace Bigfoot
/****************************************************************************************/
namespace flatbuffers
{
Flat::Bigfoot::UUID Pack(const Bigfoot::UUID& p_uuid)
{
const std::span<const std::byte, Bigfoot::UUID::UUID_BYTE_SIZE> bytes = p_uuid.ToBytes();
return Flat::Bigfoot::UUID {
std::span<const std::uint8_t, Bigfoot::UUID::UUID_BYTE_SIZE> {reinterpret_cast<const std::uint8_t*>(bytes.data()),
bytes.size()}};
}
/****************************************************************************************/
Bigfoot::UUID UnPack(const Flat::Bigfoot::UUID& p_flatUUID)
{
const std::span<const std::uint8_t, Bigfoot::UUID::UUID_BYTE_SIZE> bytesView {p_flatUUID.bytes()->data(),
p_flatUUID.bytes()->size()};
return Bigfoot::UUID {std::as_bytes(bytesView)};
}
} // namespace flatbuffers