Audacity 3.2.0
Uuid.h
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file Uuid.h
6 @brief Declare a class to generate and parse UUIDs
7
8 Dmitry Vedenko
9 **********************************************************************/
10
11#pragma once
12
13#include <array>
14#include <cstdint>
15#include <string>
16
17namespace audacity
18{
19
27class UUID_API Uuid final
28{
29public:
30 using Bytes = std::array<uint8_t, 16>;
31
33 Uuid();
34
36 explicit Uuid(const Bytes& data) noexcept;
37
39 static Uuid Generate();
40
47 static Uuid FromString(const std::string& str);
48
50 bool IsNil() const noexcept;
51
53 explicit operator bool() const noexcept;
54
55 // Comparison is performed lexicographically.
56
57 bool operator==(const Uuid& other) const noexcept;
58 bool operator!=(const Uuid& other) const noexcept;
59
60 bool operator>(const Uuid& other) const noexcept;
61 bool operator>=(const Uuid& other) const noexcept;
62
63 bool operator<(const Uuid& other) const noexcept;
64 bool operator<=(const Uuid& other) const noexcept;
65
67 const Bytes& ToBytes() const noexcept;
68
70 std::string ToString() const;
71
73 std::string ToHexString() const;
74
75 std::size_t GetHash() const noexcept;
76
77private:
78 Bytes mData;
79};
80
81} // namespace audacity
82
83namespace std
84{
85template <> struct UUID_API hash<audacity::Uuid>
86{
87 std::size_t operator()(const audacity::Uuid& uuid) const noexcept
88 {
89 return uuid.GetHash();
90 }
91};
92} // namespace std
#define str(a)
Platform independent class for generating and parsing UUIDs.
Utility class that generates and parses UUIDs.
Definition: Uuid.h:28
std::array< uint8_t, 16 > Bytes
Definition: Uuid.h:30
auto ToString(const std::optional< TimeSignature > &ts)
STL namespace.
std::size_t operator()(const audacity::Uuid &uuid) const noexcept
Definition: Uuid.h:87