2020-12-31 11:38:12 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-12-31 11:38:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Array.h>
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2022-02-15 20:55:53 +02:00
|
|
|
#ifdef KERNEL
|
|
|
|
# include <Kernel/KString.h>
|
|
|
|
#else
|
|
|
|
# include <AK/String.h>
|
|
|
|
#endif
|
|
|
|
|
2020-12-31 11:38:12 +02:00
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
class UUID {
|
|
|
|
public:
|
2022-01-28 20:21:40 +02:00
|
|
|
enum class Endianness {
|
|
|
|
Mixed,
|
|
|
|
Little
|
|
|
|
};
|
|
|
|
|
2021-09-15 23:20:31 -07:00
|
|
|
UUID() = default;
|
2020-12-31 11:38:12 +02:00
|
|
|
UUID(Array<u8, 16> uuid_buffer);
|
2022-01-28 20:21:40 +02:00
|
|
|
UUID(StringView, Endianness endianness = Endianness::Little);
|
2021-01-10 16:29:28 -07:00
|
|
|
~UUID() = default;
|
2020-12-31 11:38:12 +02:00
|
|
|
|
|
|
|
bool operator==(const UUID&) const;
|
|
|
|
bool operator!=(const UUID& other) const { return !(*this == other); }
|
|
|
|
bool operator<=(const UUID&) const = delete;
|
|
|
|
bool operator>=(const UUID&) const = delete;
|
|
|
|
bool operator<(const UUID&) const = delete;
|
|
|
|
bool operator>(const UUID&) const = delete;
|
|
|
|
|
2022-02-15 20:55:53 +02:00
|
|
|
#ifdef KERNEL
|
|
|
|
ErrorOr<NonnullOwnPtr<Kernel::KString>> to_string() const;
|
|
|
|
#else
|
2020-12-31 11:38:12 +02:00
|
|
|
String to_string() const;
|
2022-02-15 20:55:53 +02:00
|
|
|
#endif
|
2020-12-31 11:38:12 +02:00
|
|
|
bool is_zero() const;
|
|
|
|
|
|
|
|
private:
|
2022-01-28 20:21:40 +02:00
|
|
|
void convert_string_view_to_little_endian_uuid(StringView);
|
|
|
|
void convert_string_view_to_mixed_endian_uuid(StringView);
|
2020-12-31 11:38:12 +02:00
|
|
|
|
|
|
|
Array<u8, 16> m_uuid_buffer {};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::UUID;
|