Files
Bigfoot/Bigfoot/Sources/System/UUID/UUID.cpp
Romain BOULLARD f3a1c7ec36
Some checks failed
Bigfoot / build-and-test (Debug, ON) (push) Successful in 25s
Bigfoot / build-and-test (RelWithDebInfo, OFF) (push) Successful in 27s
Bigfoot / build-and-test (RelWithDebInfo, ON) (push) Successful in 25s
Bigfoot / build-and-test (Release, OFF) (push) Successful in 20s
Bigfoot / build-and-test (Release, ON) (push) Has been cancelled
Bigfoot / build-and-test (Debug, OFF) (push) Successful in 26s
Update compilation
2026-01-28 14:28:07 +01:00

88 lines
2.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