smgl 0.11.0
Structured Metadata Engine and Graph Objects Library
Loading...
Searching...
No Matches
Uuid.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <array>
6#include <cstdint>
7#include <string>
8
9namespace smgl
10{
11
17class Uuid
18{
19public:
22
24 Uuid() = default;
25
27 explicit operator bool() const;
29 auto operator==(const Uuid& rhs) const -> bool;
31 auto operator!=(const Uuid& rhs) const -> bool;
32
34 void reset();
36 auto is_nil() const -> bool;
37
44 auto string() const -> std::string;
45
52 auto short_string() const -> std::string;
53
60 static auto FromString(const std::string& str) -> Uuid;
61
68 static auto Uuid4() -> Uuid;
69
70private:
72 std::array<Byte, 16> buffer_{};
73};
74
77{
78public:
80 auto uuid() const -> Uuid;
82 void setUuid(const Uuid& uuid);
83
84protected:
89};
90
91} // namespace smgl
92
93namespace std
94{
96template <>
97struct hash<smgl::Uuid> {
99 auto operator()(smgl::Uuid const& u) const noexcept -> std::size_t
100 {
101 return std::hash<std::string>{}(u.string());
102 }
103};
104} // namespace std
Base class for objects which are uniquely identifiable.
Definition Uuid.hpp:77
auto uuid() const -> Uuid
void setUuid(const Uuid &uuid)
Universally unique identifier class.
Definition Uuid.hpp:18
static auto Uuid4() -> Uuid
Generate a UUIDv4 using pseudo-random numbers.
void reset()
Reset the UUID to a nil value.
auto is_nil() const -> bool
Returns true is all bytes are zero.
std::array< Byte, 16 > buffer_
Definition Uuid.hpp:72
auto short_string() const -> std::string
Get a string representation of the short UUID.
static auto FromString(const std::string &str) -> Uuid
Construct a UUID from a string.
Uuid()=default
auto operator==(const Uuid &rhs) const -> bool
auto operator!=(const Uuid &rhs) const -> bool
T make_shared(T... args)
Project top-level namespace.
ISO C++ top-level namespace.
auto operator()(smgl::Uuid const &u) const noexcept -> std::size_t
Definition Uuid.hpp:99