diff options
Diffstat (limited to 'src/corelib/serialization/qcborvalue.h')
-rw-r--r-- | src/corelib/serialization/qcborvalue.h | 108 |
1 files changed, 60 insertions, 48 deletions
diff --git a/src/corelib/serialization/qcborvalue.h b/src/corelib/serialization/qcborvalue.h index 9f80b5e9bd..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; @@ -110,9 +107,7 @@ public: QCborValue(QCborSimpleType st) : t(type_helper(st)) {} QCborValue(const QByteArray &ba); -#if QT_STRINGVIEW_LEVEL < 2 QCborValue(const QString &s); -#endif QCborValue(QStringView s); QCborValue(QLatin1StringView s); #ifndef QT_NO_CAST_FROM_ASCII @@ -141,12 +136,12 @@ public: // make sure const char* doesn't go call the bool constructor QCborValue(const void *) = delete; - QCborValue(const QCborValue &other); + QCborValue(const QCborValue &other) noexcept; QCborValue(QCborValue &&other) noexcept - : n(other.n), container(qExchange(other.container, nullptr)), t(qExchange(other.t, Undefined)) + : n(other.n), container(std::exchange(other.container, nullptr)), t(std::exchange(other.t, Undefined)) { } - QCborValue &operator=(const QCborValue &other); + QCborValue &operator=(const QCborValue &other) noexcept; QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCborValue) void swap(QCborValue &other) noexcept @@ -224,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 @@ -262,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; @@ -371,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 @@ -408,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; @@ -430,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: @@ -524,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 @@ -547,13 +556,13 @@ public: #if QT_CONFIG(cborstreamwriter) using QCborValueConstRef::toCbor; QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation) - { return qAsConst(*this).toCbor(opt); } + { return std::as_const(*this).toCbor(opt); } void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation); #endif using QCborValueConstRef::toDiagnosticNotation; QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact) - { return qAsConst(*this).toDiagnosticNotation(opt); } + { return std::as_const(*this).toDiagnosticNotation(opt); } private: static QCborValue concrete(QCborValueRef that) noexcept; @@ -584,6 +593,9 @@ 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) Q_CORE_EXPORT size_t qHash(const QCborValue &value, size_t seed = 0); |