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