diff options
author | rtk0c <[email protected]> | 2022-05-25 22:30:59 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-05-25 22:30:59 -0700 |
commit | 8fc3192da5ae3ac24511ad32088d669c799b6ddb (patch) | |
tree | e8288e736427dd758986860e0956286969d60f7b /source-common/Uid.hpp | |
parent | d18a28a9659092952aef70a30a47726e7c16d31a (diff) |
Changeset: 39 Move more things to source-common/
Diffstat (limited to 'source-common/Uid.hpp')
-rw-r--r-- | source-common/Uid.hpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source-common/Uid.hpp b/source-common/Uid.hpp new file mode 100644 index 0000000..f58129c --- /dev/null +++ b/source-common/Uid.hpp @@ -0,0 +1,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; + } +}; |