From fbbba96705be705fa8282fa67ecaa259276f4688 Mon Sep 17 00:00:00 2001 From: cat Date: Sat, 3 Jan 2026 13:16:53 +0200 Subject: [PATCH] UUID system iteration 2 --- sourceCode/Types.hpp | 17 ++++++++++++++--- sourceCode/Types/UUID.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 sourceCode/Types/UUID.cpp diff --git a/sourceCode/Types.hpp b/sourceCode/Types.hpp index 44360c1..2ed11b4 100644 --- a/sourceCode/Types.hpp +++ b/sourceCode/Types.hpp @@ -8,8 +8,19 @@ */ #ifndef GUARD_TOURMALINE_TYPES_H #define GUARD_TOURMALINE_TYPES_H -#include +#include +#include namespace Tourmaline::Type { -using UUID = std::string; -} +struct UUID { + [[nodiscard]] + std::string asString() const; + + UUID(uint64_t firstHalf, uint64_t secondHalf); + UUID(const std::string &uuid); + UUID(UUID &&uuid) noexcept; + +private: + std::unique_ptr data = std::make_unique(2); +}; +} // namespace Tourmaline::Type #endif diff --git a/sourceCode/Types/UUID.cpp b/sourceCode/Types/UUID.cpp new file mode 100644 index 0000000..11b04a0 --- /dev/null +++ b/sourceCode/Types/UUID.cpp @@ -0,0 +1,32 @@ +/* + * SPDX-FileCopyrightText: Dora "cat" + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "Types.hpp" +#include +#include +#include +#include + +using namespace Tourmaline::Type; +std::string UUID::asString() const { + return std::format("{:016X}{:016X}", data[0], data[1]); +} + +UUID::UUID(UUID &&uuid) noexcept { data.swap(uuid.data); } + +UUID::UUID(uint64_t firstHalf, uint64_t secondHalf) { + data[0] = firstHalf; + data[1] = secondHalf; +} + +UUID::UUID(const std::string &uuid) { + // We are assuming that it is a valid UUID, if not then somewhere else this + // UUID should cause an error + std::copy(uuid.begin(), uuid.begin() + 32, data.get()); +}