summaryrefslogtreecommitdiff
path: root/include/erebos/uuid.h
blob: d6ccf500ddd7c8de2e25cfc575c28f49ea2586ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
		}
	};
}