summaryrefslogtreecommitdiff
path: root/include/erebos/uuid.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/erebos/uuid.h')
-rw-r--r--include/erebos/uuid.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/include/erebos/uuid.h b/include/erebos/uuid.h
new file mode 100644
index 0000000..d6ccf50
--- /dev/null
+++ b/include/erebos/uuid.h
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <array>
+#include <cstdint>
+#include <cstring>
+#include <optional>
+#include <string>
+
+namespace erebos {
+
+struct UUID
+{
+ UUID(): uuid({}) {}
+ explicit UUID(const std::string &);
+ explicit operator std::string() const;
+
+ static std::optional<UUID> fromString(const std::string &);
+ static bool fromString(const std::string &, UUID &);
+
+ static UUID generate();
+
+ bool operator==(const UUID &) const;
+ bool operator!=(const UUID &) const;
+
+ std::array<uint8_t, 16> uuid;
+};
+
+}
+
+namespace std
+{
+ template<> struct hash<erebos::UUID>
+ {
+ std::size_t operator()(const erebos::UUID & uuid) const noexcept
+ {
+ std::size_t res;
+ std::memcpy(&res, uuid.uuid.data(), sizeof res);
+ return res;
+ }
+ };
+}