The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
5.0KB

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