aboutsummaryrefslogtreecommitdiff
path: root/source/Uid.hpp
blob: f58129c3cd6c01b1ef1ccec076d972b4562a7568 (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
42
#pragma once

#include "Utils.hpp"

#include <rapidjson/fwd.h>
#include <cinttypes>
#include <functional>
#include <string>
#include <string_view>

#define BRUSSEL_Uid_SCAN_STR "%" PRIx64 "-%" PRIx64
#define BRUSSEL_Uid_SCAN_EXPAND(uid) &((uid).upper), &((uid).upper)
#define BRUSSEL_Uid_FORMAT_STR "%016" PRIx64 "-%016" PRIx64
#define BRUSSEL_Uid_FORMAT_EXPAND(uid) (uid).upper, (uid).lower

struct Uid {
	uint64_t upper = 0;
	uint64_t lower = 0;

	static Uid Create();

	bool IsNull() const;

	void ReadString(std::string_view str);
	std::string WriteString();

	void Read(const rapidjson::Value& value);
	void WriteInto(rapidjson::Value& value, rapidjson::Document& root);
	rapidjson::Value Write(rapidjson::Document& root);

	auto operator<=>(const Uid&) const = default;
};

template <>
struct std::hash<Uid> {
	size_t operator()(const Uid& uid) const {
		size_t hash = 0;
		Utils::HashCombine(hash, uid.upper);
		Utils::HashCombine(hash, uid.lower);
		return hash;
	}
};