juce_Uuid.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef JUCE_UUID_H_INCLUDED
  22. #define JUCE_UUID_H_INCLUDED
  23. //==============================================================================
  24. /**
  25. A universally unique 128-bit identifier.
  26. This class generates very random unique numbers. It's vanishingly unlikely
  27. that two identical UUIDs would ever be created by chance. The values are
  28. formatted to meet the RFC 4122 version 4 standard.
  29. The class includes methods for saving the ID as a string or as raw binary data.
  30. */
  31. class JUCE_API Uuid
  32. {
  33. public:
  34. //==============================================================================
  35. /** Creates a new unique ID, compliant with RFC 4122 version 4. */
  36. Uuid();
  37. /** Destructor. */
  38. ~Uuid() noexcept;
  39. /** Creates a copy of another UUID. */
  40. Uuid (const Uuid&) noexcept;
  41. /** Copies another UUID. */
  42. Uuid& operator= (const Uuid&) noexcept;
  43. //==============================================================================
  44. /** Returns true if the ID is zero. */
  45. bool isNull() const noexcept;
  46. /** Returns a null Uuid object. */
  47. static Uuid null() noexcept;
  48. bool operator== (const Uuid&) const noexcept;
  49. bool operator!= (const Uuid&) const noexcept;
  50. //==============================================================================
  51. /** Returns a stringified version of this UUID.
  52. A Uuid object can later be reconstructed from this string using operator= or
  53. the constructor that takes a string parameter.
  54. @returns a 32 character hex string.
  55. */
  56. String toString() const;
  57. /** Returns a stringified version of this UUID, separating it into sections with dashes.
  58. @returns a string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  59. */
  60. String toDashedString() const;
  61. /** Creates an ID from an encoded string version.
  62. @see toString
  63. */
  64. Uuid (const String& uuidString);
  65. /** Copies from a stringified UUID.
  66. The string passed in should be one that was created with the toString() method.
  67. */
  68. Uuid& operator= (const String& uuidString);
  69. //==============================================================================
  70. /** Returns a pointer to the internal binary representation of the ID.
  71. This is an array of 16 bytes. To reconstruct a Uuid from its data, use
  72. the constructor or operator= method that takes an array of uint8s.
  73. */
  74. const uint8* getRawData() const noexcept { return uuid; }
  75. /** Creates a UUID from a 16-byte array.
  76. @see getRawData
  77. */
  78. Uuid (const uint8* rawData) noexcept;
  79. /** Sets this UUID from 16-bytes of raw data. */
  80. Uuid& operator= (const uint8* rawData) noexcept;
  81. private:
  82. //==============================================================================
  83. uint8 uuid[16];
  84. String getHexRegion (int, int) const;
  85. JUCE_LEAK_DETECTOR (Uuid)
  86. };
  87. #endif // JUCE_UUID_H_INCLUDED