Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qtyperevision.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // Copyright (C) 2022 Intel Corporation.
0003 // Copyright (C) 2015 Keith Gardner <kreios4004@gmail.com>
0004 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0005 
0006 #ifndef QTYPEREVISION_H
0007 #define QTYPEREVISION_H
0008 
0009 #include <QtCore/qassert.h>
0010 #include <QtCore/qcontainertools_impl.h>
0011 #include <QtCore/qmetatype.h>
0012 #include <QtCore/qtypeinfo.h>
0013 
0014 #include <limits>
0015 
0016 QT_BEGIN_NAMESPACE
0017 
0018 class QDataStream;
0019 class QDebug;
0020 
0021 class QTypeRevision;
0022 Q_CORE_EXPORT size_t qHash(const QTypeRevision &key, size_t seed = 0);
0023 
0024 #ifndef QT_NO_DATASTREAM
0025 Q_CORE_EXPORT QDataStream& operator<<(QDataStream &out, const QTypeRevision &revision);
0026 Q_CORE_EXPORT QDataStream& operator>>(QDataStream &in, QTypeRevision &revision);
0027 #endif
0028 
0029 class QTypeRevision
0030 {
0031 public:
0032     template<typename Integer>
0033     using if_valid_segment_type = typename std::enable_if<
0034             std::is_integral<Integer>::value, bool>::type;
0035 
0036     template<typename Integer>
0037     using if_valid_value_type = typename std::enable_if<
0038             std::is_integral<Integer>::value
0039             && (sizeof(Integer) > sizeof(quint16)
0040                 || (sizeof(Integer) == sizeof(quint16)
0041                     && !std::is_signed<Integer>::value)), bool>::type;
0042 
0043     template<typename Integer, if_valid_segment_type<Integer> = true>
0044     static constexpr bool isValidSegment(Integer segment)
0045     {
0046         // using extra parentheses around max to avoid expanding it if it is a macro
0047         return segment >= Integer(0)
0048                 && ((std::numeric_limits<Integer>::max)() < Integer(SegmentUnknown)
0049                     || segment < Integer(SegmentUnknown));
0050     }
0051 
0052     template<typename Major, typename Minor,
0053              if_valid_segment_type<Major> = true,
0054              if_valid_segment_type<Minor> = true>
0055     static constexpr QTypeRevision fromVersion(Major majorVersion, Minor minorVersion)
0056     {
0057         return Q_ASSERT(isValidSegment(majorVersion)),
0058                Q_ASSERT(isValidSegment(minorVersion)),
0059                QTypeRevision(quint8(majorVersion), quint8(minorVersion));
0060     }
0061 
0062     template<typename Major, if_valid_segment_type<Major> = true>
0063     static constexpr QTypeRevision fromMajorVersion(Major majorVersion)
0064     {
0065         return Q_ASSERT(isValidSegment(majorVersion)),
0066                QTypeRevision(quint8(majorVersion), SegmentUnknown);
0067     }
0068 
0069     template<typename Minor, if_valid_segment_type<Minor> = true>
0070     static constexpr QTypeRevision fromMinorVersion(Minor minorVersion)
0071     {
0072         return Q_ASSERT(isValidSegment(minorVersion)),
0073                QTypeRevision(SegmentUnknown, quint8(minorVersion));
0074     }
0075 
0076     template<typename Integer, if_valid_value_type<Integer> = true>
0077     static constexpr QTypeRevision fromEncodedVersion(Integer value)
0078     {
0079         return Q_ASSERT((value & ~Integer(0xffff)) == Integer(0)),
0080                QTypeRevision((value & Integer(0xff00)) >> 8, value & Integer(0xff));
0081     }
0082 
0083     static constexpr QTypeRevision zero() { return QTypeRevision(0, 0); }
0084 
0085     constexpr QTypeRevision() = default;
0086 
0087     constexpr bool hasMajorVersion() const { return m_majorVersion != SegmentUnknown; }
0088     constexpr quint8 majorVersion() const { return m_majorVersion; }
0089 
0090     constexpr bool hasMinorVersion() const { return m_minorVersion != SegmentUnknown; }
0091     constexpr quint8 minorVersion() const { return m_minorVersion; }
0092 
0093     constexpr bool isValid() const { return hasMajorVersion() || hasMinorVersion(); }
0094 
0095     template<typename Integer, if_valid_value_type<Integer> = true>
0096     constexpr Integer toEncodedVersion() const
0097     {
0098         return Integer(m_majorVersion << 8) | Integer(m_minorVersion);
0099     }
0100 
0101     [[nodiscard]] friend constexpr bool operator==(QTypeRevision lhs, QTypeRevision rhs)
0102     {
0103         return lhs.toEncodedVersion<quint16>() == rhs.toEncodedVersion<quint16>();
0104     }
0105 
0106     [[nodiscard]] friend constexpr bool operator!=(QTypeRevision lhs, QTypeRevision rhs)
0107     {
0108         return lhs.toEncodedVersion<quint16>() != rhs.toEncodedVersion<quint16>();
0109     }
0110 
0111     [[nodiscard]] friend constexpr bool operator<(QTypeRevision lhs, QTypeRevision rhs)
0112     {
0113         return (!lhs.hasMajorVersion() && rhs.hasMajorVersion())
0114                 // non-0 major > unspecified major > major 0
0115                 ? rhs.majorVersion() != 0
0116                 : ((lhs.hasMajorVersion() && !rhs.hasMajorVersion())
0117                 // major 0 < unspecified major < non-0 major
0118                 ? lhs.majorVersion() == 0
0119                 : (lhs.majorVersion() != rhs.majorVersion()
0120                     // both majors specified and non-0
0121                     ? lhs.majorVersion() < rhs.majorVersion()
0122                     : ((!lhs.hasMinorVersion() && rhs.hasMinorVersion())
0123                         // non-0 minor > unspecified minor > minor 0
0124                         ? rhs.minorVersion() != 0
0125                         : ((lhs.hasMinorVersion() && !rhs.hasMinorVersion())
0126                             // minor 0 < unspecified minor < non-0 minor
0127                             ? lhs.minorVersion() == 0
0128                             // both minors specified and non-0
0129                             : lhs.minorVersion() < rhs.minorVersion()))));
0130     }
0131 
0132     [[nodiscard]] friend constexpr bool operator>(QTypeRevision lhs, QTypeRevision rhs)
0133     {
0134         return lhs != rhs && !(lhs < rhs);
0135     }
0136 
0137     [[nodiscard]] friend constexpr bool operator<=(QTypeRevision lhs, QTypeRevision rhs)
0138     {
0139         return lhs == rhs || lhs < rhs;
0140     }
0141 
0142     [[nodiscard]] friend constexpr bool operator>=(QTypeRevision lhs, QTypeRevision rhs)
0143     {
0144         return lhs == rhs || !(lhs < rhs);
0145     }
0146 
0147 private:
0148     enum { SegmentUnknown = 0xff };
0149 
0150 #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
0151     constexpr QTypeRevision(quint8 major, quint8 minor)
0152         : m_minorVersion(minor), m_majorVersion(major) {}
0153 
0154     quint8 m_minorVersion = SegmentUnknown;
0155     quint8 m_majorVersion = SegmentUnknown;
0156 #else
0157     constexpr QTypeRevision(quint8 major, quint8 minor)
0158         : m_majorVersion(major), m_minorVersion(minor) {}
0159 
0160     quint8 m_majorVersion = SegmentUnknown;
0161     quint8 m_minorVersion = SegmentUnknown;
0162 #endif
0163 };
0164 
0165 static_assert(sizeof(QTypeRevision) == 2);
0166 Q_DECLARE_TYPEINFO(QTypeRevision, Q_RELOCATABLE_TYPE);
0167 
0168 #ifndef QT_NO_DEBUG_STREAM
0169 Q_CORE_EXPORT QDebug operator<<(QDebug, const QTypeRevision &revision);
0170 #endif
0171 
0172 QT_END_NAMESPACE
0173 
0174 QT_DECL_METATYPE_EXTERN(QTypeRevision, Q_CORE_EXPORT)
0175 
0176 #endif // QTYPEREVISION_H
0177 
0178 #if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 2
0179 // make QVersionNumber available from <QTypeRevision>
0180 #include <QtCore/qversionnumber.h>
0181 #endif