CoriEngine
Loading...
Searching...
No Matches
Uuid.cpp
Go to the documentation of this file.
1#include "Uuid.hpp"
2
3namespace {
4 uuids::uuid Generate() {
5
6 static std::mt19937 engine = [] {
7 std::random_device rd;
8 auto seed_data = std::array<int32_t, std::mt19937::state_size>{};
9 std::ranges::generate(seed_data, std::ref(rd));
10 std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
11 return std::mt19937{seq};
12 }();
13
14 static uuids::uuid_random_generator gen{engine};
15
16 return gen();
17 }
18}
19
20namespace Cori {
21 namespace Core {
22 UUID::UUID() : m_ID(Generate()) {}
23
24 uuids::uuid UUID::LoadFromString(const std::string& uuidStr) {
25 if (uuids::uuid::is_valid_uuid(uuidStr)) {
26 return uuids::uuid::from_string(uuidStr).value();
27 }
28 const uuids::uuid randomUuid = Generate();
29 CORI_CORE_WARN_TAGGED({ Logger::Tags::Core::Self, Logger::Tags::Core::UUID }, "LoadFromString has failed. Provided uuidStr: '{}', is not a valid string representation of standart UUID. Generated a random UUID instead with value: '{}'", uuidStr, uuids::to_string(randomUuid));
30 CORI_CORE_WARN_TAGGED({ Logger::Tags::Core::Self, Logger::Tags::Core::UUID },"Correct UUID format is: 'xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx' or '{{xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx}}'");
31 return randomUuid;
32 }
33 }
34}
#define CORI_CORE_WARN_TAGGED(...)
Definition Logger.hpp:1038
UUID()
Generates a random 128bit UUID.
Definition Uuid.cpp:22
Core systems of the engine are here.
Global engine namespace.
static constexpr char Self[]
Definition Logger.hpp:83
static constexpr char UUID[]
Definition Logger.hpp:99