| @@ -45,51 +45,40 @@ Uuid::Uuid() | |||
| // into the mix too, to make it very very unlikely that two UUIDs will ever be the same.. | |||
| static Random r1 (getRandomSeedFromMACAddresses()); | |||
| value.asInt64[0] = r1.nextInt64(); | |||
| value.asInt64[1] = r1.nextInt64(); | |||
| Random r2; | |||
| for (int i = 4; --i >= 0;) | |||
| value.asInt[i] ^= r2.nextInt(); | |||
| for (size_t i = 0; i < sizeof (uuid); ++i) | |||
| uuid[i] = (uint8) (r1.nextInt() ^ r2.nextInt()); | |||
| } | |||
| Uuid::~Uuid() noexcept | |||
| { | |||
| } | |||
| Uuid::~Uuid() noexcept {} | |||
| Uuid::Uuid (const Uuid& other) | |||
| : value (other.value) | |||
| Uuid::Uuid (const Uuid& other) noexcept | |||
| { | |||
| memcpy (uuid, other.uuid, sizeof (uuid)); | |||
| } | |||
| Uuid& Uuid::operator= (const Uuid& other) | |||
| Uuid& Uuid::operator= (const Uuid& other) noexcept | |||
| { | |||
| value = other.value; | |||
| memcpy (uuid, other.uuid, sizeof (uuid)); | |||
| return *this; | |||
| } | |||
| bool Uuid::operator== (const Uuid& other) const | |||
| { | |||
| return value.asInt64[0] == other.value.asInt64[0] | |||
| && value.asInt64[1] == other.value.asInt64[1]; | |||
| } | |||
| bool Uuid::operator!= (const Uuid& other) const | |||
| { | |||
| return ! operator== (other); | |||
| } | |||
| 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::isNull() const noexcept | |||
| { | |||
| return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0); | |||
| for (size_t i = 0; i < sizeof (uuid); ++i) | |||
| if (uuid[i] != 0) | |||
| return false; | |||
| return true; | |||
| } | |||
| //============================================================================== | |||
| String Uuid::toString() const | |||
| { | |||
| return String::toHexString (value.asBytes, sizeof (value.asBytes), 0); | |||
| return String::toHexString (uuid, sizeof (uuid), 0); | |||
| } | |||
| Uuid::Uuid (const String& uuidString) | |||
| @@ -101,23 +90,22 @@ Uuid& Uuid::operator= (const String& uuidString) | |||
| { | |||
| MemoryBlock mb; | |||
| mb.loadFromHexString (uuidString); | |||
| mb.ensureSize (sizeof (value.asBytes), true); | |||
| mb.copyTo (value.asBytes, 0, sizeof (value.asBytes)); | |||
| mb.ensureSize (sizeof (uuid), true); | |||
| mb.copyTo (uuid, 0, sizeof (uuid)); | |||
| return *this; | |||
| } | |||
| //============================================================================== | |||
| Uuid::Uuid (const uint8* const rawData) | |||
| { | |||
| operator= (rawData); | |||
| } | |||
| Uuid& Uuid::operator= (const uint8* const rawData) | |||
| Uuid& Uuid::operator= (const uint8* const rawData) noexcept | |||
| { | |||
| if (rawData != nullptr) | |||
| memcpy (value.asBytes, rawData, sizeof (value.asBytes)); | |||
| memcpy (uuid, rawData, sizeof (uuid)); | |||
| else | |||
| zeromem (value.asBytes, sizeof (value.asBytes)); | |||
| zeromem (uuid, sizeof (uuid)); | |||
| return *this; | |||
| } | |||
| @@ -50,20 +50,17 @@ public: | |||
| ~Uuid() noexcept; | |||
| /** Creates a copy of another UUID. */ | |||
| Uuid (const Uuid& other); | |||
| Uuid (const Uuid& other) noexcept; | |||
| /** Copies another UUID. */ | |||
| Uuid& operator= (const Uuid& other); | |||
| Uuid& operator= (const Uuid& other) noexcept; | |||
| //============================================================================== | |||
| /** Returns true if the ID is zero. */ | |||
| bool isNull() const noexcept; | |||
| //============================================================================== | |||
| /** Compares two UUIDs. */ | |||
| bool operator== (const Uuid& other) const; | |||
| /** Compares two UUIDs. */ | |||
| bool operator!= (const Uuid& other) const; | |||
| bool operator== (const Uuid& other) const noexcept; | |||
| bool operator!= (const Uuid& other) const noexcept; | |||
| //============================================================================== | |||
| /** Returns a stringified version of this UUID. | |||
| @@ -76,13 +73,11 @@ public: | |||
| String toString() const; | |||
| /** Creates an ID from an encoded string version. | |||
| @see toString | |||
| */ | |||
| Uuid (const String& uuidString); | |||
| /** Copies from a stringified UUID. | |||
| The string passed in should be one that was created with the toString() method. | |||
| */ | |||
| Uuid& operator= (const String& uuidString); | |||
| @@ -94,29 +89,20 @@ public: | |||
| This is an array of 16 bytes. To reconstruct a Uuid from its data, use | |||
| the constructor or operator= method that takes an array of uint8s. | |||
| */ | |||
| const uint8* getRawData() const noexcept { return value.asBytes; } | |||
| const uint8* getRawData() const noexcept { return uuid; } | |||
| /** Creates a UUID from a 16-byte array. | |||
| @see getRawData | |||
| */ | |||
| Uuid (const uint8* rawData); | |||
| /** Sets this UUID from 16-bytes of raw data. */ | |||
| Uuid& operator= (const uint8* rawData); | |||
| Uuid& operator= (const uint8* rawData) noexcept; | |||
| private: | |||
| //============================================================================== | |||
| #ifndef DOXYGEN | |||
| union | |||
| { | |||
| uint8 asBytes [16]; | |||
| int asInt[4]; | |||
| int64 asInt64[2]; | |||
| } value; | |||
| #endif | |||
| uint8 uuid[16]; | |||
| JUCE_LEAK_DETECTOR (Uuid); | |||
| }; | |||
| @@ -24,36 +24,35 @@ | |||
| */ | |||
| MACAddress::MACAddress() | |||
| : asInt64 (0) | |||
| { | |||
| zeromem (address, sizeof (address)); | |||
| } | |||
| MACAddress::MACAddress (const MACAddress& other) | |||
| : asInt64 (other.asInt64) | |||
| { | |||
| memcpy (address, other.address, sizeof (address)); | |||
| } | |||
| MACAddress& MACAddress::operator= (const MACAddress& other) | |||
| { | |||
| asInt64 = other.asInt64; | |||
| memcpy (address, other.address, sizeof (address)); | |||
| return *this; | |||
| } | |||
| MACAddress::MACAddress (const uint8 bytes[6]) | |||
| : asInt64 (0) | |||
| { | |||
| memcpy (asBytes, bytes, sizeof (asBytes)); | |||
| memcpy (address, bytes, sizeof (address)); | |||
| } | |||
| String MACAddress::toString() const | |||
| { | |||
| String s; | |||
| for (int i = 0; i < numElementsInArray (asBytes); ++i) | |||
| for (size_t i = 0; i < sizeof (address); ++i) | |||
| { | |||
| s << String::toHexString ((int) asBytes[i]).paddedLeft ('0', 2); | |||
| s << String::toHexString ((int) address[i]).paddedLeft ('0', 2); | |||
| if (i < numElementsInArray (asBytes) - 1) | |||
| if (i < sizeof (address) - 1) | |||
| s << '-'; | |||
| } | |||
| @@ -64,13 +63,13 @@ int64 MACAddress::toInt64() const noexcept | |||
| { | |||
| int64 n = 0; | |||
| for (int i = numElementsInArray (asBytes); --i >= 0;) | |||
| n = (n << 8) | asBytes[i]; | |||
| for (int i = (int) sizeof (address); --i >= 0;) | |||
| n = (n << 8) | address[i]; | |||
| return n; | |||
| } | |||
| bool MACAddress::isNull() const noexcept { return asInt64 == 0; } | |||
| bool MACAddress::isNull() const noexcept { return toInt64() == 0; } | |||
| bool MACAddress::operator== (const MACAddress& other) const noexcept { return asInt64 == other.asInt64; } | |||
| bool MACAddress::operator!= (const MACAddress& other) const noexcept { return asInt64 != other.asInt64; } | |||
| bool MACAddress::operator== (const MACAddress& other) const noexcept { return memcmp (address, other.address, sizeof (address)) == 0; } | |||
| bool MACAddress::operator!= (const MACAddress& other) const noexcept { return ! operator== (other); } | |||
| @@ -59,7 +59,7 @@ public: | |||
| explicit MACAddress (const uint8 bytes[6]); | |||
| /** Returns a pointer to the 6 bytes that make up this address. */ | |||
| const uint8* getBytes() const noexcept { return asBytes; } | |||
| const uint8* getBytes() const noexcept { return address; } | |||
| /** Returns a dash-separated string in the form "11-22-33-44-55-66" */ | |||
| String toString() const; | |||
| @@ -79,13 +79,7 @@ public: | |||
| //============================================================================== | |||
| private: | |||
| #ifndef DOXYGEN | |||
| union | |||
| { | |||
| uint64 asInt64; | |||
| uint8 asBytes[6]; | |||
| }; | |||
| #endif | |||
| uint8 address[6]; | |||
| }; | |||
| @@ -450,18 +450,9 @@ String URL::addEscapeChars (const String& s, const bool isParameter) | |||
| if (! (CharacterFunctions::isLetterOrDigit (c) | |||
| || legalChars.indexOf ((juce_wchar) c) >= 0)) | |||
| { | |||
| if (c == ' ') | |||
| { | |||
| utf8.set (i, '+'); | |||
| } | |||
| else | |||
| { | |||
| static const char hexDigits[] = "0123456789abcdef"; | |||
| utf8.set (i, '%'); | |||
| utf8.insert (++i, hexDigits [((uint8) c) >> 4]); | |||
| utf8.insert (++i, hexDigits [c & 15]); | |||
| } | |||
| utf8.set (i, '%'); | |||
| utf8.insert (++i, "0123456789abcdef" [((uint8) c) >> 4]); | |||
| utf8.insert (++i, "0123456789abcdef" [c & 15]); | |||
| } | |||
| } | |||
| @@ -45,10 +45,6 @@ | |||
| { | |||
| } | |||
| ~MyTask() | |||
| { | |||
| } | |||
| void run() | |||
| { | |||
| for (int i = 0; i < thingsToDo; ++i) | |||