OpenShot Library | libopenshot-audio  0.2.0
juce_Uuid.h
1 
2 /** @weakgroup juce_core-misc
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  A universally unique 128-bit identifier.
33 
34  This class generates very random unique numbers. It's vanishingly unlikely
35  that two identical UUIDs would ever be created by chance. The values are
36  formatted to meet the RFC 4122 version 4 standard.
37 
38  The class includes methods for saving the ID as a string or as raw binary data.
39 
40  @tags{Core}
41 */
43 {
44 public:
45  //==============================================================================
46  /** Creates a new unique ID, compliant with RFC 4122 version 4. */
47  Uuid();
48 
49  /** Destructor. */
50  ~Uuid() noexcept;
51 
52  /** Creates a copy of another UUID. */
53  Uuid (const Uuid&) noexcept;
54 
55  /** Copies another UUID. */
56  Uuid& operator= (const Uuid&) noexcept;
57 
58  //==============================================================================
59  /** Returns true if the ID is zero. */
60  bool isNull() const noexcept;
61 
62  /** Returns a null Uuid object. */
63  static Uuid null() noexcept;
64 
65  bool operator== (const Uuid&) const noexcept;
66  bool operator!= (const Uuid&) const noexcept;
67  bool operator< (const Uuid&) const noexcept;
68  bool operator> (const Uuid&) const noexcept;
69  bool operator<= (const Uuid&) const noexcept;
70  bool operator>= (const Uuid&) const noexcept;
71 
72  //==============================================================================
73  /** Returns a stringified version of this UUID.
74 
75  A Uuid object can later be reconstructed from this string using operator= or
76  the constructor that takes a string parameter.
77 
78  @returns a 32 character hex string.
79  */
80  String toString() const;
81 
82  /** Returns a stringified version of this UUID, separating it into sections with dashes.
83  @returns a string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
84  */
85  String toDashedString() const;
86 
87  /** Creates an ID from an encoded string version.
88  @see toString
89  */
90  Uuid (const String& uuidString);
91 
92  /** Copies from a stringified UUID.
93  The string passed in should be one that was created with the toString() method.
94  */
95  Uuid& operator= (const String& uuidString);
96 
97 
98  //==============================================================================
99  /** Returns the time-low section of the UUID. */
100  uint32 getTimeLow() const noexcept;
101  /** Returns the time-mid section of the UUID. */
102  uint16 getTimeMid() const noexcept;
103  /** Returns the time-high-and-version section of the UUID. */
104  uint16 getTimeHighAndVersion() const noexcept;
105  /** Returns the clock-seq-and-reserved section of the UUID. */
106  uint8 getClockSeqAndReserved() const noexcept;
107  /** Returns the clock-seq-low section of the UUID. */
108  uint8 getClockSeqLow() const noexcept;
109  /** Returns the node section of the UUID. */
110  uint64 getNode() const noexcept;
111 
112  /** Returns a hash of the UUID. */
113  uint64 hash() const noexcept;
114 
115  //==============================================================================
116  /** Returns a pointer to the internal binary representation of the ID.
117 
118  This is an array of 16 bytes. To reconstruct a Uuid from its data, use
119  the constructor or operator= method that takes an array of uint8s.
120  */
121  const uint8* getRawData() const noexcept { return uuid; }
122 
123  /** Creates a UUID from a 16-byte array.
124  @see getRawData
125  */
126  Uuid (const uint8* rawData) noexcept;
127 
128  /** Sets this UUID from 16-bytes of raw data. */
129  Uuid& operator= (const uint8* rawData) noexcept;
130 
131 
132 private:
133  //==============================================================================
134  uint8 uuid[16];
135  String getHexRegion (int, int) const;
136  int compare (Uuid) const noexcept;
137 
138  JUCE_LEAK_DETECTOR (Uuid)
139 };
140 
141 } // namespace juce
142 
143 #if ! DOXYGEN
144 namespace std
145 {
146  template <> struct hash<juce::Uuid>
147  {
148  size_t operator() (const juce::Uuid& u) const noexcept { return (size_t) u.hash(); }
149  };
150 }
151 #endif
152 
153 /** @}*/
juce::Uuid
A universally unique 128-bit identifier.
Definition: juce_Uuid.h:42
JUCE_API
#define JUCE_API
This macro is added to all JUCE public class declarations.
Definition: juce_StandardHeader.h:143
juce::Uuid::getRawData
const uint8 * getRawData() const noexcept
Returns a pointer to the internal binary representation of the ID.
Definition: juce_Uuid.h:121
juce::String
The JUCE String class!
Definition: juce_String.h:42