Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added comparison operators to Uuid following standard IETF and ITU conventions. #183

Closed
wants to merge 1 commit into from

Conversation

@julianstorer
Copy link
Contributor

I think there are a few mistakes in there, and it all seems a bit over-complicated.. How about these as accessor methods for the UUID sections:

    /** Returns the time-low section of the UUID. */
uint32 getTimeLow() const noexcept                  { return ByteOrder::bigEndianInt (uuid + 12); }
/** Returns the time-mid section of the UUID. */
uint16 getTimeMid() const noexcept                  { return ByteOrder::bigEndianShort (uuid + 10); }
/** Returns the time-high-and-version section of the UUID. */
uint16 getTimeHighAndVersion() const noexcept       { return ByteOrder::bigEndianShort (uuid + 8); }
/** Returns the clock-seq-and-reserved section of the UUID. */
uint8  getClockSeqAndReserved() const noexcept      { return uuid[7]; }
/** Returns the clock-seq-low section of the UUID. */
uint8  getClockSeqLow() const noexcept              { return uuid[6]; }
/** Returns the node section of the UUID. */
uint64 getNode() const noexcept                     { return (((uint64) ByteOrder::bigEndianShort (uuid + 4)) << 32) + ByteOrder::bigEndianInt (uuid); }

..and then a simple compare method that uses them?

@jrlanglois
Copy link
Author

Yep, as I said in the forum post this initial go at it is a bit goofy... Your suggestion works for me.

@julianstorer
Copy link
Contributor

julianstorer commented May 3, 2017

Hmm, did you actually test any of your code, it just all looks the wrong way round.. Compare with the way that toDashedString() reads the bytes.

And since the whole thing is ordered as one big-endian number, shouldn't the compare method just be this?

int Uuid::compare (Uuid other) const noexcept
{
    for (int i = 0; i < 16; ++i)
        if (int diff = uuid[i] - other.uuid[i])
            return diff;

    return 0;
}

I'm curious as to what you were doing where your changes seemed to be a fix?

@jrlanglois
Copy link
Author

jrlanglois commented May 3, 2017

I guess I set myself up for the flac, but the code was basically copied from one of the sources listed above, and reformatted to JUCE's coding standard (to some extent...) and other things to avoid macros.

@jrlanglois jrlanglois deleted the UUIDComp branch August 18, 2017 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants