CoriEngine
Loading...
Searching...
No Matches
Uuid.hpp
Go to the documentation of this file.
1#ifndef UUID_H
2#define UUID_H
3#include <uuid.h>
4
5namespace Cori {
6 namespace Core {
10 class UUID {
11 public:
15 UUID();
16
21 explicit UUID(const std::string& uuidStr) : m_ID(LoadFromString(uuidStr)) {}
22
23 explicit operator uuids::uuid() const noexcept { return m_ID; }
24
29 [[nodiscard]] std::string GetSerializationString() const {
30 return uuids::to_string(m_ID);
31 }
32
33 [[nodiscard]] std::pair<uint64_t, uint64_t> GetRaw() const {
34 const auto span = m_ID.as_bytes();
35 const uint64_t left = *reinterpret_cast<const uint64_t*>(&span[0]);
36 const uint64_t right = *reinterpret_cast<const uint64_t*>(&span[8]);
37 return std::make_pair(left, right);
38 }
39
43 bool operator==(const UUID& other) const {
44 return m_ID == other.m_ID;
45 }
46
47 private:
48 const uuids::uuid m_ID;
49
50 static uuids::uuid LoadFromString(const std::string& uuidStr);
51 };
52 }
53}
54
55template<>
56struct std::hash<Cori::Core::UUID> {
57 std::size_t operator()(const Cori::Core::UUID& uuid) const noexcept { return hash<uuids::uuid>{}(static_cast<uuids::uuid>(uuid)); }
58};
59
60#endif
A 128bit UUID, can be serialized to the string and deserialized from it.
Definition Uuid.hpp:10
bool operator==(const UUID &other) const
Do really i need to explain this?
Definition Uuid.hpp:43
UUID()
Generates a random 128bit UUID.
Definition Uuid.cpp:22
UUID(const std::string &uuidStr)
Loads UUID from a serialized string, the one created by GetSerializationString() method.
Definition Uuid.hpp:21
std::pair< uint64_t, uint64_t > GetRaw() const
Definition Uuid.hpp:33
std::string GetSerializationString() const
Returns the UUID as a formated string liable for serialization.
Definition Uuid.hpp:29
Core systems of the engine are here.
Global engine namespace.
std::size_t operator()(const Cori::Core::UUID &uuid) const noexcept
Definition Uuid.hpp:57