diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-02-04 16:07:16 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-02-07 19:19:50 +0100 |
commit | 2145cdc54d5812793310f7e3b3709bfa2648bd50 (patch) | |
tree | 66ec56fd89185ac59ae83a3b1465c355028ca1b3 /src/corelib/tools/qversionnumber.h | |
parent | 78da102810067ea951990577ce7b6f722aafdeb9 (diff) |
Core: Provide comparison functions for QTypeRevision
The unspecified segment is between 0 and 1. This is because
QTypeRevision::zero(), as the default revisision needs to be smaller
than any other. At the same time we want explicitly specified non-zero
revisions to be larger than unspecified ones. Breaking this down on a
per segment level gives us the order shown here.
Change-Id: I1cca12f1180eb6f77563fb5b22c3400e118dc5e9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/tools/qversionnumber.h')
-rw-r--r-- | src/corelib/tools/qversionnumber.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index 16058bd04a..03a27548b8 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -416,6 +416,42 @@ inline constexpr bool operator!=(QTypeRevision lhs, QTypeRevision rhs) return lhs.toEncodedVersion<quint16>() != rhs.toEncodedVersion<quint16>(); } +inline constexpr bool operator<(QTypeRevision lhs, QTypeRevision rhs) +{ + return (!lhs.hasMajorVersion() && rhs.hasMajorVersion()) + // non-0 major > unspecified major > major 0 + ? rhs.majorVersion() != 0 + : ((lhs.hasMajorVersion() && !rhs.hasMajorVersion()) + // major 0 < unspecified major < non-0 major + ? lhs.majorVersion() == 0 + : (lhs.majorVersion() != rhs.majorVersion() + // both majors specified and non-0 + ? lhs.majorVersion() < rhs.majorVersion() + : ((!lhs.hasMinorVersion() && rhs.hasMinorVersion()) + // non-0 minor > unspecified minor > minor 0 + ? rhs.minorVersion() != 0 + : ((lhs.hasMinorVersion() && !rhs.hasMinorVersion()) + // minor 0 < unspecified minor < non-0 minor + ? lhs.minorVersion() == 0 + // both minors specified and non-0 + : lhs.minorVersion() < rhs.minorVersion())))); +} + +inline constexpr bool operator>(QTypeRevision lhs, QTypeRevision rhs) +{ + return lhs != rhs && !(lhs < rhs); +} + +inline constexpr bool operator<=(QTypeRevision lhs, QTypeRevision rhs) +{ + return lhs == rhs || lhs < rhs; +} + +inline constexpr bool operator>=(QTypeRevision lhs, QTypeRevision rhs) +{ + return lhs == rhs || !(lhs < rhs); +} + Q_STATIC_ASSERT(sizeof(QTypeRevision) == 2); Q_DECLARE_TYPEINFO(QTypeRevision, Q_MOVABLE_TYPE); |