1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-04 03:40:07 +00:00

Added some comparison and getter methods to Uuid.

This commit is contained in:
jules 2017-05-04 12:02:37 +01:00
parent 0c24b48be8
commit 014311fdbf
2 changed files with 42 additions and 2 deletions

View file

@ -48,6 +48,20 @@ Uuid& Uuid::operator= (const Uuid& other) noexcept
bool Uuid::operator== (const Uuid& other) const noexcept { return memcmp (uuid, other.uuid, sizeof (uuid)) == 0; }
bool Uuid::operator!= (const Uuid& other) const noexcept { return ! operator== (other); }
bool Uuid::operator< (const Uuid& other) const noexcept { return compare (other) < 0; }
bool Uuid::operator> (const Uuid& other) const noexcept { return compare (other) > 0; }
bool Uuid::operator<= (const Uuid& other) const noexcept { return compare (other) <= 0; }
bool Uuid::operator>= (const Uuid& other) const noexcept { return compare (other) >= 0; }
int Uuid::compare (Uuid other) const noexcept
{
for (size_t i = 0; i < sizeof (uuid); ++i)
if (int diff = uuid[i] - (int) other.uuid[i])
return diff > 0 ? 1 : -1;
return 0;
}
Uuid Uuid::null() noexcept
{
return Uuid ((const uint8*) nullptr);
@ -55,8 +69,8 @@ Uuid Uuid::null() noexcept
bool Uuid::isNull() const noexcept
{
for (size_t i = 0; i < sizeof (uuid); ++i)
if (uuid[i] != 0)
for (auto i : uuid)
if (i != 0)
return false;
return true;
@ -109,3 +123,10 @@ Uuid& Uuid::operator= (const uint8* const rawData) noexcept
return *this;
}
uint32 Uuid::getTimeLow() const noexcept { return ByteOrder::bigEndianInt (uuid); }
uint16 Uuid::getTimeMid() const noexcept { return ByteOrder::bigEndianShort (uuid + 4); }
uint16 Uuid::getTimeHighAndVersion() const noexcept { return ByteOrder::bigEndianShort (uuid + 6); }
uint8 Uuid::getClockSeqAndReserved() const noexcept { return uuid[8]; }
uint8 Uuid::getClockSeqLow() const noexcept { return uuid[9]; }
uint64 Uuid::getNode() const noexcept { return (((uint64) ByteOrder::bigEndianShort (uuid + 10)) << 32) + ByteOrder::bigEndianInt (uuid + 12); }

View file

@ -58,6 +58,10 @@ public:
bool operator== (const Uuid&) const noexcept;
bool operator!= (const Uuid&) const noexcept;
bool operator< (const Uuid&) const noexcept;
bool operator> (const Uuid&) const noexcept;
bool operator<= (const Uuid&) const noexcept;
bool operator>= (const Uuid&) const noexcept;
//==============================================================================
/** Returns a stringified version of this UUID.
@ -85,6 +89,20 @@ public:
Uuid& operator= (const String& uuidString);
//==============================================================================
/** Returns the time-low section of the UUID. */
uint32 getTimeLow() const noexcept;
/** Returns the time-mid section of the UUID. */
uint16 getTimeMid() const noexcept;
/** Returns the time-high-and-version section of the UUID. */
uint16 getTimeHighAndVersion() const noexcept;
/** Returns the clock-seq-and-reserved section of the UUID. */
uint8 getClockSeqAndReserved() const noexcept;
/** Returns the clock-seq-low section of the UUID. */
uint8 getClockSeqLow() const noexcept;
/** Returns the node section of the UUID. */
uint64 getNode() const noexcept;
//==============================================================================
/** Returns a pointer to the internal binary representation of the ID.
@ -106,6 +124,7 @@ private:
//==============================================================================
uint8 uuid[16];
String getHexRegion (int, int) const;
int compare (Uuid) const noexcept;
JUCE_LEAK_DETECTOR (Uuid)
};