From f138311d2d2e0cc9ba0496d523bb46f2c1c9fb73 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Wed, 20 Sep 2023 23:58:58 -0700 Subject: Copy from the PlasticSCM repo, replace vendored glm wtih conan --- source/10-common/Uid.hpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 source/10-common/Uid.hpp (limited to 'source/10-common/Uid.hpp') diff --git a/source/10-common/Uid.hpp b/source/10-common/Uid.hpp new file mode 100644 index 0000000..a691911 --- /dev/null +++ b/source/10-common/Uid.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include "Utils.hpp" + +#include +#include +#include +#include +#include + +#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 + +// Serialize Uid object as an array with two elements, instead of the simple string format +#define BRUSSEL_Uid_WRITE_USE_ARRAY 0 + +struct Uid { + uint64_t upper = 0; + uint64_t lower = 0; + + // Generate a random Uid + 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) const; + rapidjson::Value Write(rapidjson::Document& root) const; + + auto operator<=>(const Uid&) const = default; +}; + +template <> +struct std::hash { + size_t operator()(const Uid& uid) const { + size_t hash = 0; + Utils::HashCombine(hash, uid.upper); + Utils::HashCombine(hash, uid.lower); + return hash; + } +}; -- cgit v1.2.3-70-g09d2