Compare commits

...

1 Commits

Author SHA1 Message Date
cat
fbbba96705 UUID system iteration 2 2026-01-03 13:16:53 +02:00
2 changed files with 46 additions and 3 deletions

View File

@@ -8,8 +8,19 @@
*/
#ifndef GUARD_TOURMALINE_TYPES_H
#define GUARD_TOURMALINE_TYPES_H
#include <string>
#include <cstdint>
#include <memory>
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<uint64_t[]> data = std::make_unique<uint64_t[]>(2);
};
} // namespace Tourmaline::Type
#endif

32
sourceCode/Types/UUID.cpp Normal file
View File

@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: Dora "cat" <cat@thenight.club>
* 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 <algorithm>
#include <format>
#include <memory>
#include <string>
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());
}