CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
UUID.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
12
15
16#include <cstdlib>
17#include <cstring>
18#include <iosfwd>
19#include <random>
20#include <tuple>
21
22namespace CeresEngine {
23
27 struct CE_SCRIPT_EXPORT(storage = "value") UUID {
30 UInt32 raw[4] = {0, 0, 0, 0}; // NOLINT
31
35
39
43
46
47 public:
51 constexpr bool empty() const { return raw[0] == 0 && raw[1] == 0 && raw[2] == 0 && raw[3] == 0; }
52
57
60 void toString(String& str) const;
61
62 public:
65 void copyTo(Byte* buffer) const { memcpy(buffer, &raw[0], sizeof(raw[0]) * 4); }
66
69 void copyFrom(const Byte* buffer) { memcpy(&raw[0], buffer, sizeof(raw[0]) * 4); }
70
71 public:
76 friend constexpr bool operator==(const UUID& lhs, const UUID& rhs) noexcept {
77 return lhs.raw[0] == rhs.raw[0] && lhs.raw[1] == rhs.raw[1] && lhs.raw[2] == rhs.raw[2] && lhs.raw[3] == rhs.raw[3];
78 }
79
84 friend constexpr bool operator!=(const UUID& lhs, const UUID& rhs) noexcept { return !(lhs == rhs); }
85
90 friend constexpr bool operator<(const UUID& lhs, const UUID& rhs) noexcept {
91 return lhs.raw[0] < rhs.raw[0] && lhs.raw[1] < rhs.raw[1] && lhs.raw[2] < rhs.raw[2] && lhs.raw[3] < rhs.raw[3];
92 }
93
98 friend constexpr bool operator>(const UUID& lhs, const UUID& rhs) noexcept { return rhs < lhs; }
99
105 friend constexpr bool operator<=(const UUID& lhs, const UUID& rhs) noexcept { return !(rhs < lhs); }
106
112 friend constexpr bool operator>=(const UUID& lhs, const UUID& rhs) noexcept { return !(lhs < rhs); }
113
115 friend String toString(const UUID& uuid) { return uuid.toString(); }
116
122 friend std::ostream& operator<<(std::ostream& os, const UUID& uuid);
123
124 public:
128 static UUID random();
129
133 static UUID withNamespace(const UUID& ns, StringView name);
134
139 static UUID fromName(StringView name);
140
146 };
147
148} // namespace CeresEngine
149
151template<> struct std::hash<CeresEngine::UUID> {
152 size_t operator()(const CeresEngine::UUID& value) const {
153 using CeresEngine::hash;
154 return hash(value.raw[0], value.raw[1], value.raw[2], value.raw[3]);
155 }
156};
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
A generator represents a coroutine type that produces a sequence of values of type T,...
Definition Generator.hpp:50
Definition Application.hpp:19
Byte
Definition DataTypes.hpp:40
StringView toString(Button button) noexcept
Returns a string representation for the given button
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Represents a universally unique identifier (UUID).
Definition UUID.hpp:27
friend constexpr bool operator<=(const UUID &lhs, const UUID &rhs) noexcept
Compares two UUID objects for ordering.
Definition UUID.hpp:105
friend String toString(const UUID &uuid)
Converts the UUID into its string representation.
Definition UUID.hpp:115
friend std::ostream & operator<<(std::ostream &os, const UUID &uuid)
Prints a string representation of a UUID into a standard output stream.
friend constexpr bool operator>=(const UUID &lhs, const UUID &rhs) noexcept
Compares two UUID objects for ordering.
Definition UUID.hpp:112
UInt32 raw[4]
The UUID raw representation.
Definition UUID.hpp:30
void copyFrom(const Byte *buffer)
Copies the UUID from a buffer.
Definition UUID.hpp:69
friend constexpr bool operator>(const UUID &lhs, const UUID &rhs) noexcept
Compares two UUID objects for ordering.
Definition UUID.hpp:98
friend constexpr bool operator<(const UUID &lhs, const UUID &rhs) noexcept
Compares two UUID objects for ordering.
Definition UUID.hpp:90
friend constexpr bool operator==(const UUID &lhs, const UUID &rhs) noexcept
Compares two UUID objects for equality.
Definition UUID.hpp:76
friend constexpr bool operator!=(const UUID &lhs, const UUID &rhs) noexcept
Compares two UUID objects for inequality.
Definition UUID.hpp:84