Some checks failed
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 6m47s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 4m59s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 5m20s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 5m18s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m33s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m37s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 6m32s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m31s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m38s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m33s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 6m12s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m9s
Bigfoot / Clang Format Checks (push) Failing after 11s
110 lines
3.4 KiB
C++
110 lines
3.4 KiB
C++
/*********************************************************************
|
|
* \file UUID.cpp
|
|
*
|
|
* \author Romain BOULLARD
|
|
* \date October 2025
|
|
*********************************************************************/
|
|
#include <System/UUID/UUID.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*>(std::bit_cast<const std::uint8_t*>(p_raw.data())),
|
|
UUID_BYTE_SIZE};
|
|
|
|
m_uuid = uuids::uuid {raw};
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
UUID::operator std::span<const std::byte, UUID::UUID_BYTE_SIZE>() const
|
|
{
|
|
return m_uuid.as_bytes();
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
UUID::operator std::string() const
|
|
{
|
|
return uuids::to_string(m_uuid);
|
|
}
|
|
|
|
/****************************************************************************************/
|
|
|
|
UUID::operator bool() const
|
|
{
|
|
return *this != NULL_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;
|
|
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
|