2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
20 ==============================================================================
26 //==============================================================================
28 A universally unique 128-bit identifier.
30 This class generates very random unique numbers. It's vanishingly unlikely
31 that two identical UUIDs would ever be created by chance. The values are
32 formatted to meet the RFC 4122 version 4 standard.
34 The class includes methods for saving the ID as a string or as raw binary data.
41 //==============================================================================
42 /** Creates a new unique ID, compliant with RFC 4122 version 4. */
48 /** Creates a copy of another UUID. */
49 Uuid (const Uuid
&) noexcept
;
51 /** Copies another UUID. */
52 Uuid
& operator= (const Uuid
&) noexcept
;
54 //==============================================================================
55 /** Returns true if the ID is zero. */
56 bool isNull() const noexcept
;
58 /** Returns a null Uuid object. */
59 static Uuid
null() noexcept
;
61 bool operator== (const Uuid
&) const noexcept
;
62 bool operator!= (const Uuid
&) const noexcept
;
63 bool operator< (const Uuid
&) const noexcept
;
64 bool operator> (const Uuid
&) const noexcept
;
65 bool operator<= (const Uuid
&) const noexcept
;
66 bool operator>= (const Uuid
&) const noexcept
;
68 //==============================================================================
69 /** Returns a stringified version of this UUID.
71 A Uuid object can later be reconstructed from this string using operator= or
72 the constructor that takes a string parameter.
74 @returns a 32 character hex string.
76 String
toString() const;
78 /** Returns a stringified version of this UUID, separating it into sections with dashes.
79 @returns a string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
81 String
toDashedString() const;
83 /** Creates an ID from an encoded string version.
86 Uuid (const String
& uuidString
);
88 /** Copies from a stringified UUID.
89 The string passed in should be one that was created with the toString() method.
91 Uuid
& operator= (const String
& uuidString
);
94 //==============================================================================
95 /** Returns the time-low section of the UUID. */
96 uint32
getTimeLow() const noexcept
;
97 /** Returns the time-mid section of the UUID. */
98 uint16
getTimeMid() const noexcept
;
99 /** Returns the time-high-and-version section of the UUID. */
100 uint16
getTimeHighAndVersion() const noexcept
;
101 /** Returns the clock-seq-and-reserved section of the UUID. */
102 uint8
getClockSeqAndReserved() const noexcept
;
103 /** Returns the clock-seq-low section of the UUID. */
104 uint8
getClockSeqLow() const noexcept
;
105 /** Returns the node section of the UUID. */
106 uint64
getNode() const noexcept
;
108 /** Returns a hash of the UUID. */
109 uint64
hash() const noexcept
;
111 //==============================================================================
112 /** Returns a pointer to the internal binary representation of the ID.
114 This is an array of 16 bytes. To reconstruct a Uuid from its data, use
115 the constructor or operator= method that takes an array of uint8s.
117 const uint8
* getRawData() const noexcept
{ return uuid
; }
119 /** Creates a UUID from a 16-byte array.
122 Uuid (const uint8
* rawData
) noexcept
;
124 /** Sets this UUID from 16-bytes of raw data. */
125 Uuid
& operator= (const uint8
* rawData
) noexcept
;
129 //==============================================================================
131 String
getHexRegion (int, int) const;
132 int compare (Uuid
) const noexcept
;
134 JUCE_LEAK_DETECTOR (Uuid
)
142 template <> struct hash
<juce::Uuid
>
144 size_t operator() (const juce::Uuid
& u
) const noexcept
{ return (size_t) u
.hash(); }