8 #ifndef TurtleBrains_uuid_hpp
9 #define TurtleBrains_uuid_hpp
15 #include <turtle_brains/core/tb_platform.hpp>
16 #include <turtle_brains/core/tb_string.hpp>
17 #include <turtle_brains/core/tb_types.hpp>
19 #include <sole/sole.hpp>
37 static TypedUUID Generate0(
void) {
TypedUUID value; value.mUUID = sole::uuid0();
return value; }
40 static TypedUUID Generate1(
void) {
TypedUUID value; value.mUUID = sole::uuid1();
return value; }
43 static TypedUUID Generate4(
void) {
TypedUUID value; value.mUUID = sole::uuid4();
return value; }
47 static TypedUUID FromRawData(
const std::array<tbCore::byte, 16>& uuidData) {
return TypedUUID(uuidData); }
50 mUUID(sole::rebuild(0, 0))
55 mUUID(sole::rebuild(uuidString))
60 mUUID(sole::rebuild(first64, last64))
64 explicit TypedUUID(
const std::array<tbCore::byte, 16>& uuidData) :
65 mUUID(sole::rebuild(0, 0))
69 for (
size_t index = 0; index < 8; ++index)
71 reinterpret_cast<tbCore::byte*
>(&first)[index] = uuidData[index];
72 reinterpret_cast<tbCore::byte*
>(&last)[index] = uuidData[index + 8];
75 mUUID = sole::rebuild(first, last);
84 mUUID(sole::rebuild(0, 0))
86 std::swap(mUUID, other.mUUID);
95 inline std::array<tbCore::byte, 16> RawData(
void)
const
97 std::array<tbCore::byte, 16> data;
98 for (
size_t index = 0; index < 8; ++index)
100 data[index] =
reinterpret_cast<const tbCore::byte*
>(&mUUID.ab)[index];
101 data[index + 8] =
reinterpret_cast<const tbCore::byte*
>(&mUUID.cd)[index];
115 std::swap(mUUID, other.mUUID);
119 inline bool operator==(
const TypedUUID& other)
const {
return mUUID == other.mUUID; }
120 inline bool operator!=(
const TypedUUID& other)
const {
return mUUID != other.mUUID; }
121 inline bool operator<(
const TypedUUID& other)
const {
return mUUID < other.mUUID; }
123 template<
typename ToType>
friend class TypedUUID;
131 friend inline std::ostream& operator<<(std::ostream& output,
const TypedUUID<Type>&
object)
133 return output <<
object.String();
136 friend std::istream& operator>>(std::istream& input,
TypedUUID<Type>& data)
139 input >> temporaryString;
140 data.mUUID = sole::rebuild(temporaryString);
153 enum class DefaultKeyType {};
154 using uuid = TypedUUID<DefaultKeyType>;
164 template<
typename Type>
struct std::hash<
tbCore::TypedUUID<Type>>
Definition: tb_uuid.hpp:33
Contains core functionality for each component of the API.
Definition: tb_debug_logger.hpp:125
String ToString(const Type &object)
Definition: tb_string.hpp:317
std::string String
Definition: tb_string.hpp:302
std::uint8_t byte
Unsigned integer with a size of 8 bits. Supports values from 0 to 255.
Definition: tb_types.hpp:23
std::uint64_t uint64
Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1).
Definition: tb_types.hpp:29