diff options
Diffstat (limited to 'src/corelib/serialization/qcborvalue.h')
-rw-r--r-- | src/corelib/serialization/qcborvalue.h | 94 |
1 files changed, 53 insertions, 41 deletions
diff --git a/src/corelib/serialization/qcborvalue.h b/src/corelib/serialization/qcborvalue.h index b90d397bcc..93adbec344 100644 --- a/src/corelib/serialization/qcborvalue.h +++ b/src/corelib/serialization/qcborvalue.h @@ -5,8 +5,9 @@ #define QCBORVALUE_H #include <QtCore/qbytearray.h> -#include <QtCore/qdatetime.h> #include <QtCore/qcborcommon.h> +#include <QtCore/qcompare.h> +#include <QtCore/qdatetime.h> #if QT_CONFIG(regularexpression) # include <QtCore/qregularexpression.h> #endif @@ -22,10 +23,6 @@ # undef False #endif -#if 0 && __has_include(<compare>) -# include <compare> -#endif - QT_BEGIN_NAMESPACE class QCborArray; @@ -222,19 +219,11 @@ public: QCborValueRef operator[](const QString & key); int compare(const QCborValue &other) const; -#if 0 && __has_include(<compare>) - std::strong_ordering operator<=>(const QCborValue &other) const - { - int c = compare(other); - if (c > 0) return std::partial_ordering::greater; - if (c == 0) return std::partial_ordering::equivalent; - return std::partial_ordering::less; - } -#else +#if QT_CORE_REMOVED_SINCE(6, 8) bool operator==(const QCborValue &other) const noexcept { return compare(other) == 0; } bool operator!=(const QCborValue &other) const noexcept - { return !(*this == other); } + { return !operator==(other); } bool operator<(const QCborValue &other) const { return compare(other) < 0; } #endif @@ -260,6 +249,19 @@ public: QString toDiagnosticNotation(DiagnosticNotationOptions opts = Compact) const; private: + friend Q_CORE_EXPORT Q_DECL_PURE_FUNCTION + bool comparesEqual(const QCborValue &lhs, const QCborValue &rhs) noexcept; + friend Qt::strong_ordering compareThreeWay(const QCborValue &lhs, + const QCborValue &rhs) noexcept + { + int c = lhs.compare(rhs); + return Qt::compareThreeWay(c, 0); + } + + Q_DECLARE_STRONGLY_ORDERED(QCborValue) + friend class QCborArray; + friend class QCborMap; + friend class QCborValueConstRef; friend class QCborValueRef; friend class QCborContainerPrivate; friend class QJsonPrivate::Value; @@ -369,22 +371,6 @@ public: int compare(const QCborValue &other) const { return concrete().compare(other); } -#if 0 && __has_include(<compare>) - std::strong_ordering operator<=>(const QCborValue &other) const - { - int c = compare(other); - if (c > 0) return std::strong_ordering::greater; - if (c == 0) return std::strong_ordering::equivalent; - return std::strong_ordering::less; - } -#else - bool operator==(const QCborValue &other) const - { return compare(other) == 0; } - bool operator!=(const QCborValue &other) const - { return !(*this == other); } - bool operator<(const QCborValue &other) const - { return compare(other) < 0; } -#endif QVariant toVariant() const { return concrete().toVariant(); } inline QJsonValue toJsonValue() const; // in qjsonvalue.h @@ -406,6 +392,37 @@ protected: friend class QCborContainerPrivate; QCborValue concrete() const noexcept { return concrete(*this); } + static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool + comparesEqual_helper(QCborValueConstRef lhs, QCborValueConstRef rhs) noexcept; + static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION Qt::strong_ordering + compareThreeWay_helper(QCborValueConstRef lhs, QCborValueConstRef rhs) noexcept; + friend bool comparesEqual(const QCborValueConstRef &lhs, + const QCborValueConstRef &rhs) noexcept + { + return comparesEqual_helper(lhs, rhs); + } + friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs, + const QCborValueConstRef &rhs) noexcept + { + return compareThreeWay_helper(lhs, rhs); + } + Q_DECLARE_STRONGLY_ORDERED(QCborValueConstRef) + + static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool + comparesEqual_helper(QCborValueConstRef lhs, const QCborValue &rhs) noexcept; + static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION Qt::strong_ordering + compareThreeWay_helper(QCborValueConstRef lhs, const QCborValue &rhs) noexcept; + friend bool comparesEqual(const QCborValueConstRef &lhs, + const QCborValue &rhs) noexcept + { + return comparesEqual_helper(lhs, rhs); + } + friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs, + const QCborValue &rhs) noexcept + { + return compareThreeWay_helper(lhs, rhs); + } + Q_DECLARE_STRONGLY_ORDERED(QCborValueConstRef, QCborValue) static Q_CORE_EXPORT QCborValue concrete(QCborValueConstRef that) noexcept; static Q_CORE_EXPORT QCborValue::Type concreteType(QCborValueConstRef that) noexcept Q_DECL_PURE_FUNCTION; @@ -428,6 +445,8 @@ protected: qsizetype i; }; +QT_WARNING_PUSH +QT6_ONLY(QT_WARNING_DISABLE_MSVC(4275)) // non dll-interface class 'QJsonValueConstRef' used as base for dll-interface class 'QJsonValueRef' class QT6_ONLY(Q_CORE_EXPORT) QCborValueRef : public QCborValueConstRef { public: @@ -522,19 +541,11 @@ public: int compare(const QCborValue &other) const { return concrete().compare(other); } -#if 0 && __has_include(<compare>) - std::strong_ordering operator<=>(const QCborValue &other) const - { - int c = compare(other); - if (c > 0) return std::strong_ordering::greater; - if (c == 0) return std::strong_ordering::equivalent; - return std::strong_ordering::less; - } -#else +#if QT_CORE_REMOVED_SINCE(6, 8) bool operator==(const QCborValue &other) const { return compare(other) == 0; } bool operator!=(const QCborValue &other) const - { return !(*this == other); } + { return !operator==(other); } bool operator<(const QCborValue &other) const { return compare(other) < 0; } #endif @@ -582,6 +593,7 @@ private: QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, QCborValue &&other); QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, const QCborValueRef other); }; +QT_WARNING_POP Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::EncodingOptions) Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::DiagnosticNotationOptions) |