dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
UUIDGenerator.hpp
1// SPDX-FileCopyrightText: 2025 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard includes
12#include <array>
13#include <cstdint>
14#include <string>
15#include <random>
16
17namespace dfx::Utils
18{
32struct UUID : public std::array<uint8_t, 16>
33{
39
45 bool isValid() const noexcept;
53 std::string toString() const;
54};
55
70class UUIDGenerator
71{
72public:
84 static UUID generate();
85
86private:
87 UUIDGenerator();
88
89private:
90 std::mt19937 _gen;
91 std::uniform_int_distribution<uint8_t> _dist;
92};
93} // !namespace dfx::Utils
94
95namespace std
96{
97template<>
98struct hash<dfx::Utils::UUID>
99{
100 std::size_t operator()(dfx::Utils::UUID const & uuid) const noexcept
101 {
102 // Combine bytes into size_t using a common hash combining strategy
103 std::size_t hash = 0;
104 for (auto const byte : uuid)
105 hash ^= static_cast<std::size_t>(byte) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
106 return hash;
107 }
108};
109} // !namespace std
static UUID generate()
Generate a new UUID.
Definition SystemConfigCommandHandler.hpp:15
Definition Message.hpp:21
STL namespace.
128-bit UUID value type.
Definition UUIDGenerator.hpp:33
UUID()
Construct a UUID.
bool isValid() const noexcept
Check whether the UUID is valid.
std::string toString() const
Convert the UUID to a string representation.