Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qcborvalue.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) 2022 Intel Corporation.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QCBORVALUE_H
0005 #define QCBORVALUE_H
0006 
0007 #include <QtCore/qbytearray.h>
0008 #include <QtCore/qcborcommon.h>
0009 #include <QtCore/qcompare.h>
0010 #include <QtCore/qdatetime.h>
0011 #if QT_CONFIG(regularexpression)
0012 #  include <QtCore/qregularexpression.h>
0013 #endif
0014 #include <QtCore/qstring.h>
0015 #include <QtCore/qstringview.h>
0016 #include <QtCore/qurl.h>
0017 #include <QtCore/quuid.h>
0018 #include <QtCore/qvariant.h>
0019 
0020 /* X11 headers use these values too, but as defines */
0021 #if defined(False) && defined(True)
0022 #  undef True
0023 #  undef False
0024 #endif
0025 
0026 QT_BEGIN_NAMESPACE
0027 
0028 class QCborArray;
0029 class QCborMap;
0030 class QCborStreamReader;
0031 class QCborStreamWriter;
0032 class QDataStream;
0033 
0034 namespace QJsonPrivate { class Value; }
0035 
0036 struct QCborParserError
0037 {
0038     qint64 offset = 0;
0039     QCborError error = { QCborError::NoError };
0040 
0041     QString errorString() const { return error.toString(); }
0042 };
0043 
0044 class QCborValueRef;
0045 class QCborContainerPrivate;
0046 class Q_CORE_EXPORT QCborValue
0047 {
0048     Q_GADGET
0049 public:
0050     enum EncodingOption {
0051         SortKeysInMaps = 0x01,
0052         UseFloat = 0x02,
0053 #ifndef QT_BOOTSTRAPPED
0054         UseFloat16 = UseFloat | 0x04,
0055 #endif
0056         UseIntegers = 0x08,
0057 
0058         NoTransformation = 0
0059     };
0060     Q_DECLARE_FLAGS(EncodingOptions, EncodingOption)
0061 
0062     enum DiagnosticNotationOption {
0063         Compact         = 0x00,
0064         LineWrapped     = 0x01,
0065         ExtendedFormat  = 0x02
0066     };
0067     Q_DECLARE_FLAGS(DiagnosticNotationOptions, DiagnosticNotationOption)
0068 
0069     // different from QCborStreamReader::Type because we have more types
0070     enum Type : int {
0071         Integer         = 0x00,
0072         ByteArray       = 0x40,
0073         String          = 0x60,
0074         Array           = 0x80,
0075         Map             = 0xa0,
0076         Tag             = 0xc0,
0077 
0078         // range 0x100 - 0x1ff for Simple Types
0079         SimpleType      = 0x100,
0080         False           = SimpleType + int(QCborSimpleType::False),
0081         True            = SimpleType + int(QCborSimpleType::True),
0082         Null            = SimpleType + int(QCborSimpleType::Null),
0083         Undefined       = SimpleType + int(QCborSimpleType::Undefined),
0084 
0085         Double          = 0x202,
0086 
0087         // extended (tagged) types
0088         DateTime        = 0x10000,
0089         Url             = 0x10020,
0090         RegularExpression = 0x10023,
0091         Uuid            = 0x10025,
0092 
0093         Invalid         = -1
0094     };
0095     Q_ENUM(Type)
0096 
0097     QCborValue() {}
0098     QCborValue(Type t_) : t(t_) {}
0099     QCborValue(std::nullptr_t) : t(Null) {}
0100     QCborValue(bool b_) : t(b_ ? True : False) {}
0101 #ifndef Q_QDOC
0102     QCborValue(int i) : QCborValue(qint64(i)) {}
0103     QCborValue(unsigned u) : QCborValue(qint64(u)) {}
0104 #endif
0105     QCborValue(qint64 i) : n(i), t(Integer) {}
0106     QCborValue(double v) : t(Double) { memcpy(&n, &v, sizeof(n)); }
0107     QCborValue(QCborSimpleType st) : t(type_helper(st)) {}
0108 
0109     QCborValue(const QByteArray &ba);
0110     QCborValue(const QString &s);
0111     QCborValue(QStringView s);
0112     QCborValue(QLatin1StringView s);
0113 #ifndef QT_NO_CAST_FROM_ASCII
0114     QT_ASCII_CAST_WARN QCborValue(const char *s) : QCborValue(QString::fromUtf8(s)) {}
0115 #endif
0116     QCborValue(const QCborArray &a);
0117     QCborValue(QCborArray &&a);
0118     QCborValue(const QCborMap &m);
0119     QCborValue(QCborMap &&m);
0120     QCborValue(QCborTag tag, const QCborValue &taggedValue = QCborValue());
0121     QCborValue(QCborKnownTags t_, const QCborValue &tv = QCborValue())
0122         : QCborValue(QCborTag(t_), tv)
0123     {}
0124 
0125 #if QT_CONFIG(datestring)
0126     explicit QCborValue(const QDateTime &dt);
0127 #endif
0128 #ifndef QT_BOOTSTRAPPED
0129     explicit QCborValue(const QUrl &url);
0130 #  if QT_CONFIG(regularexpression)
0131     explicit QCborValue(const QRegularExpression &rx);
0132 #  endif
0133     explicit QCborValue(const QUuid &uuid);
0134 #endif
0135 
0136     ~QCborValue() { if (container) dispose(); }
0137 
0138     // make sure const char* doesn't go call the bool constructor
0139     QCborValue(const void *) = delete;
0140 
0141     QCborValue(const QCborValue &other) noexcept;
0142     QCborValue(QCborValue &&other) noexcept
0143         : n(other.n), container(std::exchange(other.container, nullptr)), t(std::exchange(other.t, Undefined))
0144     {
0145     }
0146     QCborValue &operator=(const QCborValue &other) noexcept;
0147     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCborValue)
0148 
0149     void swap(QCborValue &other) noexcept
0150     {
0151         std::swap(n, other.n);
0152         qt_ptr_swap(container, other.container);
0153         std::swap(t, other.t);
0154     }
0155 
0156     Type type() const           { return t; }
0157     bool isInteger() const      { return type() == Integer; }
0158     bool isByteArray() const    { return type() == ByteArray; }
0159     bool isString() const       { return type() == String; }
0160     bool isArray() const        { return type() == Array; }
0161     bool isMap() const          { return type() == Map; }
0162     bool isTag() const          { return isTag_helper(type()); }
0163     bool isFalse() const        { return type() == False; }
0164     bool isTrue() const         { return type() == True; }
0165     bool isBool() const         { return isFalse() || isTrue(); }
0166     bool isNull() const         { return type() == Null; }
0167     bool isUndefined() const    { return type() == Undefined; }
0168     bool isDouble() const       { return type() == Double; }
0169     bool isDateTime() const     { return type() == DateTime; }
0170     bool isUrl() const          { return type() == Url; }
0171     bool isRegularExpression() const { return type() == RegularExpression; }
0172     bool isUuid() const         { return type() == Uuid; }
0173     bool isInvalid() const      { return type() == Invalid; }
0174     bool isContainer() const    { return isMap() || isArray(); }
0175 
0176     bool isSimpleType() const
0177     {
0178         return int(type()) >> 8 == int(SimpleType) >> 8;
0179     }
0180     bool isSimpleType(QCborSimpleType st) const
0181     {
0182         return type() == type_helper(st);
0183     }
0184     QCborSimpleType toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined) const
0185     {
0186         return isSimpleType() ? QCborSimpleType(type() & 0xff) : defaultValue;
0187     }
0188 
0189     qint64 toInteger(qint64 defaultValue = 0) const
0190     { return isInteger() ? value_helper() : isDouble() ? qint64(fp_helper()) : defaultValue; }
0191     bool toBool(bool defaultValue = false) const
0192     { return isBool() ? isTrue() : defaultValue; }
0193     double toDouble(double defaultValue = 0) const
0194     { return isDouble() ? fp_helper() : isInteger() ? double(value_helper()) : defaultValue; }
0195 
0196     QCborTag tag(QCborTag defaultValue = QCborTag(-1)) const;
0197     QCborValue taggedValue(const QCborValue &defaultValue = QCborValue()) const;
0198 
0199     QByteArray toByteArray(const QByteArray &defaultValue = {}) const;
0200     QString toString(const QString &defaultValue = {}) const;
0201 #if QT_CONFIG(datestring)
0202     QDateTime toDateTime(const QDateTime &defaultValue = {}) const;
0203 #endif
0204 #ifndef QT_BOOTSTRAPPED
0205     QUrl toUrl(const QUrl &defaultValue = {}) const;
0206 #  if QT_CONFIG(regularexpression)
0207     QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const;
0208 #  endif
0209     QUuid toUuid(const QUuid &defaultValue = {}) const;
0210 #endif
0211 
0212     // only forward-declared, need split functions
0213     QCborArray toArray() const;
0214     QCborArray toArray(const QCborArray &defaultValue) const;
0215     QCborMap toMap() const;
0216     QCborMap toMap(const QCborMap &defaultValue) const;
0217 
0218     const QCborValue operator[](const QString &key) const;
0219     const QCborValue operator[](QLatin1StringView key) const;
0220     const QCborValue operator[](qint64 key) const;
0221     QCborValueRef operator[](qint64 key);
0222     QCborValueRef operator[](QLatin1StringView key);
0223     QCborValueRef operator[](const QString & key);
0224 
0225     int compare(const QCborValue &other) const;
0226 #if QT_CORE_REMOVED_SINCE(6, 8)
0227     bool operator==(const QCborValue &other) const noexcept
0228     { return compare(other) == 0; }
0229     bool operator!=(const QCborValue &other) const noexcept
0230     { return !operator==(other); }
0231     bool operator<(const QCborValue &other) const
0232     { return compare(other) < 0; }
0233 #endif
0234 
0235     static QCborValue fromVariant(const QVariant &variant);
0236     QVariant toVariant() const;
0237     static QCborValue fromJsonValue(const QJsonValue &v);
0238     QJsonValue toJsonValue() const;
0239 
0240 #if QT_CONFIG(cborstreamreader)
0241     static QCborValue fromCbor(QCborStreamReader &reader);
0242     static QCborValue fromCbor(const QByteArray &ba, QCborParserError *error = nullptr);
0243     static QCborValue fromCbor(const char *data, qsizetype len, QCborParserError *error = nullptr)
0244     { return fromCbor(QByteArray(data, int(len)), error); }
0245     static QCborValue fromCbor(const quint8 *data, qsizetype len, QCborParserError *error = nullptr)
0246     { return fromCbor(QByteArray(reinterpret_cast<const char *>(data), int(len)), error); }
0247 #endif // QT_CONFIG(cborstreamreader)
0248 #if QT_CONFIG(cborstreamwriter)
0249     QByteArray toCbor(EncodingOptions opt = NoTransformation) const;
0250     void toCbor(QCborStreamWriter &writer, EncodingOptions opt = NoTransformation) const;
0251 #endif
0252 
0253     QString toDiagnosticNotation(DiagnosticNotationOptions opts = Compact) const;
0254 
0255 private:
0256     friend Q_CORE_EXPORT Q_DECL_PURE_FUNCTION
0257     bool comparesEqual(const QCborValue &lhs, const QCborValue &rhs) noexcept;
0258     friend Qt::strong_ordering compareThreeWay(const QCborValue &lhs,
0259                                                const QCborValue &rhs) noexcept
0260     {
0261         int c = lhs.compare(rhs);
0262         return Qt::compareThreeWay(c, 0);
0263     }
0264 
0265     Q_DECLARE_STRONGLY_ORDERED(QCborValue)
0266     friend class QCborArray;
0267     friend class QCborMap;
0268     friend class QCborValueConstRef;
0269     friend class QCborValueRef;
0270     friend class QCborContainerPrivate;
0271     friend class QJsonPrivate::Value;
0272 
0273     qint64 n = 0;
0274     QCborContainerPrivate *container = nullptr;
0275     Type t = Undefined;
0276 
0277     void dispose();
0278     qint64 value_helper() const
0279     {
0280         return n;
0281     }
0282 
0283     double fp_helper() const
0284     {
0285         static_assert(sizeof(double) == sizeof(n));
0286         double d;
0287         memcpy(&d, &n, sizeof(d));
0288         return d;
0289     }
0290 
0291     constexpr static Type type_helper(QCborSimpleType st)
0292     {
0293         return Type(quint8(st) | SimpleType);
0294     }
0295 
0296     constexpr static bool isTag_helper(Type tt)
0297     {
0298         return tt == Tag || tt >= 0x10000;
0299     }
0300 };
0301 Q_DECLARE_SHARED(QCborValue)
0302 
0303 class QCborValueConstRef
0304 {
0305 public:
0306     QCborValueConstRef(const QCborValueConstRef &) = default;
0307     QCborValueConstRef &operator=(const QCborValueConstRef &) = delete;
0308     operator QCborValue() const     { return concrete(); }
0309 
0310     QCborValue::Type type() const   { return concreteType(*this); }
0311     bool isInteger() const          { return type() == QCborValue::Integer; }
0312     bool isByteArray() const        { return type() == QCborValue::ByteArray; }
0313     bool isString() const           { return type() == QCborValue::String; }
0314     bool isArray() const            { return type() == QCborValue::Array; }
0315     bool isMap() const              { return type() == QCborValue::Map; }
0316     bool isTag() const              { return concrete().isTag(); }
0317     bool isFalse() const            { return type() == QCborValue::False; }
0318     bool isTrue() const             { return type() == QCborValue::True; }
0319     bool isBool() const             { return isFalse() || isTrue(); }
0320     bool isNull() const             { return type() == QCborValue::Null; }
0321     bool isUndefined() const        { return type() == QCborValue::Undefined; }
0322     bool isDouble() const           { return type() == QCborValue::Double; }
0323     bool isDateTime() const         { return type() == QCborValue::DateTime; }
0324     bool isUrl() const              { return type() == QCborValue::Url; }
0325     bool isRegularExpression() const { return type() == QCborValue::RegularExpression; }
0326     bool isUuid() const             { return type() == QCborValue::Uuid; }
0327     bool isInvalid() const          { return type() == QCborValue::Invalid; }
0328     bool isContainer() const        { return isMap() || isArray(); }
0329     bool isSimpleType() const       { return concrete().isSimpleType(); }
0330     bool isSimpleType(QCborSimpleType st) const { return concrete().isSimpleType(st); }
0331 
0332     QCborSimpleType toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined) const
0333     {
0334         return concrete().toSimpleType(defaultValue);
0335     }
0336 
0337     QCborTag tag(QCborTag defaultValue = QCborTag(-1)) const
0338     { return concrete().tag(defaultValue); }
0339     QCborValue taggedValue(const QCborValue &defaultValue = QCborValue()) const
0340     { return concrete().taggedValue(defaultValue); }
0341 
0342     qint64 toInteger(qint64 defaultValue = 0) const
0343     { return concrete().toInteger(defaultValue); }
0344     bool toBool(bool defaultValue = false) const
0345     { return concrete().toBool(defaultValue); }
0346     double toDouble(double defaultValue = 0) const
0347     { return concrete().toDouble(defaultValue); }
0348 
0349     QByteArray toByteArray(const QByteArray &defaultValue = {}) const
0350     { return concrete().toByteArray(defaultValue); }
0351     QString toString(const QString &defaultValue = {}) const
0352     { return concrete().toString(defaultValue); }
0353 #if QT_CONFIG(datestring)
0354     QDateTime toDateTime(const QDateTime &defaultValue = {}) const
0355     { return concrete().toDateTime(defaultValue); }
0356 #endif
0357 #ifndef QT_BOOTSTRAPPED
0358     QUrl toUrl(const QUrl &defaultValue = {}) const
0359     { return concrete().toUrl(defaultValue); }
0360 #  if QT_CONFIG(regularexpression)
0361     QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const
0362     { return concrete().toRegularExpression(defaultValue); }
0363 #  endif
0364     QUuid toUuid(const QUuid &defaultValue = {}) const
0365     { return concrete().toUuid(defaultValue); }
0366 #endif
0367 
0368     // only forward-declared, need split functions. Implemented in qcbor{array,map}.h
0369     inline QCborArray toArray() const;
0370     inline QCborArray toArray(const QCborArray &a) const;
0371     inline QCborMap toMap() const;
0372     inline QCborMap toMap(const QCborMap &m) const;
0373 
0374     Q_CORE_EXPORT const QCborValue operator[](const QString &key) const;
0375     Q_CORE_EXPORT const QCborValue operator[](QLatin1StringView key) const;
0376     Q_CORE_EXPORT const QCborValue operator[](qint64 key) const;
0377 
0378     int compare(const QCborValue &other) const
0379     { return concrete().compare(other); }
0380 
0381     QVariant toVariant() const                  { return concrete().toVariant(); }
0382     inline QJsonValue toJsonValue() const;      // in qjsonvalue.h
0383 
0384 #if QT_CONFIG(cborstreamwriter)
0385     QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation) const
0386     { return concrete().toCbor(opt); }
0387     void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation) const
0388     { return concrete().toCbor(writer, opt); }
0389 #endif
0390 
0391     QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact) const
0392     { return concrete().toDiagnosticNotation(opt); }
0393 
0394 protected:
0395     friend class QCborValue;
0396     friend class QCborArray;
0397     friend class QCborMap;
0398     friend class QCborContainerPrivate;
0399 
0400     QCborValue concrete() const noexcept  { return concrete(*this); }
0401     static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool
0402     comparesEqual_helper(QCborValueConstRef lhs, QCborValueConstRef rhs) noexcept;
0403     static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION Qt::strong_ordering
0404     compareThreeWay_helper(QCborValueConstRef lhs, QCborValueConstRef rhs) noexcept;
0405     friend bool comparesEqual(const QCborValueConstRef &lhs,
0406                               const QCborValueConstRef &rhs) noexcept
0407     {
0408         return comparesEqual_helper(lhs, rhs);
0409     }
0410     friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs,
0411                                                const QCborValueConstRef &rhs) noexcept
0412     {
0413         return compareThreeWay_helper(lhs, rhs);
0414     }
0415     Q_DECLARE_STRONGLY_ORDERED(QCborValueConstRef)
0416 
0417     static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool
0418     comparesEqual_helper(QCborValueConstRef lhs, const QCborValue &rhs) noexcept;
0419     static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION Qt::strong_ordering
0420     compareThreeWay_helper(QCborValueConstRef lhs, const QCborValue &rhs) noexcept;
0421     friend bool comparesEqual(const QCborValueConstRef &lhs,
0422                               const QCborValue &rhs) noexcept
0423     {
0424         return comparesEqual_helper(lhs, rhs);
0425     }
0426     friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs,
0427                                                const QCborValue &rhs) noexcept
0428     {
0429         return compareThreeWay_helper(lhs, rhs);
0430     }
0431     Q_DECLARE_STRONGLY_ORDERED(QCborValueConstRef, QCborValue)
0432 
0433     static Q_CORE_EXPORT QCborValue concrete(QCborValueConstRef that) noexcept;
0434     static Q_CORE_EXPORT QCborValue::Type concreteType(QCborValueConstRef that) noexcept Q_DECL_PURE_FUNCTION;
0435     static Q_CORE_EXPORT bool
0436     concreteBoolean(QCborValueConstRef that, bool defaultValue) noexcept Q_DECL_PURE_FUNCTION;
0437     static Q_CORE_EXPORT double
0438     concreteDouble(QCborValueConstRef that, double defaultValue) noexcept Q_DECL_PURE_FUNCTION;
0439     static Q_CORE_EXPORT qint64
0440     concreteIntegral(QCborValueConstRef that, qint64 defaultValue) noexcept Q_DECL_PURE_FUNCTION;
0441     static Q_CORE_EXPORT QByteArray
0442     concreteByteArray(QCborValueConstRef that, const QByteArray &defaultValue);
0443     static Q_CORE_EXPORT QString
0444     concreteString(QCborValueConstRef that, const QString &defaultValue);
0445 
0446     constexpr QCborValueConstRef() : d(nullptr), i(0) {} // this will actually be invalid
0447     constexpr QCborValueConstRef(QCborContainerPrivate *dd, qsizetype ii)
0448         : d(dd), i(ii)
0449     {}
0450     QCborContainerPrivate *d;
0451     qsizetype i;
0452 };
0453 
0454 QT_WARNING_PUSH
0455 QT6_ONLY(QT_WARNING_DISABLE_MSVC(4275)) // non dll-interface class 'QJsonValueConstRef' used as base for dll-interface class 'QJsonValueRef'
0456 class QT6_ONLY(Q_CORE_EXPORT) QCborValueRef : public QCborValueConstRef
0457 {
0458 public:
0459     QCborValueRef(const QCborValueRef &) noexcept = default;
0460     QCborValueRef(QCborValueRef &&) noexcept = default;
0461     QCborValueRef &operator=(const QCborValue &other)
0462     { assign(*this, other); return *this; }
0463     QCborValueRef &operator=(QCborValue &&other)
0464     { assign(*this, std::move(other)); other.container = nullptr; return *this; }
0465     QCborValueRef &operator=(const QCborValueRef &other)
0466     { assign(*this, other); return *this; }
0467 
0468     QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](qint64 key);
0469     QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](QLatin1StringView key);
0470     QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](const QString & key);
0471 
0472 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
0473     // retained for binary compatibility (due to the Q_CORE_EXPORT) because at
0474     // least one compiler emits and exports all inlines in an exported class
0475 
0476     operator QCborValue() const     { return concrete(); }
0477     QCborValue::Type type() const   { return concreteType(); }
0478     bool isInteger() const          { return type() == QCborValue::Integer; }
0479     bool isByteArray() const        { return type() == QCborValue::ByteArray; }
0480     bool isString() const           { return type() == QCborValue::String; }
0481     bool isArray() const            { return type() == QCborValue::Array; }
0482     bool isMap() const              { return type() == QCborValue::Map; }
0483     bool isTag() const              { return QCborValue::isTag_helper(type()); }
0484     bool isFalse() const            { return type() == QCborValue::False; }
0485     bool isTrue() const             { return type() == QCborValue::True; }
0486     bool isBool() const             { return isFalse() || isTrue(); }
0487     bool isNull() const             { return type() == QCborValue::Null; }
0488     bool isUndefined() const        { return type() == QCborValue::Undefined; }
0489     bool isDouble() const           { return type() == QCborValue::Double; }
0490     bool isDateTime() const         { return type() == QCborValue::DateTime; }
0491     bool isUrl() const              { return type() == QCborValue::Url; }
0492     bool isRegularExpression() const { return type() == QCborValue::RegularExpression; }
0493     bool isUuid() const             { return type() == QCborValue::Uuid; }
0494     bool isInvalid() const          { return type() == QCborValue::Invalid; }
0495     bool isContainer() const        { return isMap() || isArray(); }
0496     bool isSimpleType() const
0497     {
0498         return type() >= QCborValue::SimpleType && type() < QCborValue::SimpleType + 0x100;
0499     }
0500     bool isSimpleType(QCborSimpleType st) const
0501     {
0502         return type() == QCborValue::type_helper(st);
0503     }
0504     QCborSimpleType toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined) const
0505     {
0506         return isSimpleType() ? QCborSimpleType(type() & 0xff) : defaultValue;
0507     }
0508 
0509     QCborTag tag(QCborTag defaultValue = QCborTag(-1)) const
0510     { return concrete().tag(defaultValue); }
0511     QCborValue taggedValue(const QCborValue &defaultValue = QCborValue()) const
0512     { return concrete().taggedValue(defaultValue); }
0513 
0514     qint64 toInteger(qint64 defaultValue = 0) const
0515     { return concreteIntegral(*this, defaultValue); }
0516     bool toBool(bool defaultValue = false) const
0517     { return concreteBoolean(*this, defaultValue); }
0518     double toDouble(double defaultValue = 0) const
0519     { return concreteDouble(*this, defaultValue); }
0520 
0521     QByteArray toByteArray(const QByteArray &defaultValue = {}) const
0522     { return concreteByteArray(*this, defaultValue); }
0523     QString toString(const QString &defaultValue = {}) const
0524     { return concreteString(*this, defaultValue); }
0525 #if QT_CONFIG(datestring)
0526     QDateTime toDateTime(const QDateTime &defaultValue = {}) const
0527     { return concrete().toDateTime(defaultValue); }
0528 #endif
0529 #ifndef QT_BOOTSTRAPPED
0530     QUrl toUrl(const QUrl &defaultValue = {}) const
0531     { return concrete().toUrl(defaultValue); }
0532 #  if QT_CONFIG(regularexpression)
0533     QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const
0534     { return concrete().toRegularExpression(defaultValue); }
0535 #  endif
0536     QUuid toUuid(const QUuid &defaultValue = {}) const
0537     { return concrete().toUuid(defaultValue); }
0538 #endif
0539 
0540     // only forward-declared, need split functions. Implemented in qcbor{array,map}.h
0541     QCborArray toArray() const;
0542     QCborArray toArray(const QCborArray &a) const;
0543     QCborMap toMap() const;
0544     QCborMap toMap(const QCborMap &m) const;
0545 
0546     const QCborValue operator[](const QString &key) const;
0547     const QCborValue operator[](QLatin1StringView key) const;
0548     const QCborValue operator[](qint64 key) const;
0549 
0550     int compare(const QCborValue &other) const
0551     { return concrete().compare(other); }
0552 #if QT_CORE_REMOVED_SINCE(6, 8)
0553     bool operator==(const QCborValue &other) const
0554     { return compare(other) == 0; }
0555     bool operator!=(const QCborValue &other) const
0556     { return !operator==(other); }
0557     bool operator<(const QCborValue &other) const
0558     { return compare(other) < 0; }
0559 #endif
0560 
0561     QVariant toVariant() const                  { return concrete().toVariant(); }
0562     QJsonValue toJsonValue() const;
0563 
0564 #if QT_CONFIG(cborstreamwriter)
0565     using QCborValueConstRef::toCbor;
0566     QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation)
0567     { return std::as_const(*this).toCbor(opt); }
0568     void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
0569 #endif
0570 
0571     using QCborValueConstRef::toDiagnosticNotation;
0572     QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact)
0573     { return std::as_const(*this).toDiagnosticNotation(opt); }
0574 
0575 private:
0576     static QCborValue concrete(QCborValueRef that) noexcept;
0577     QCborValue concrete() const noexcept  { return concrete(*this); }
0578 
0579     static QCborValue::Type concreteType(QCborValueRef self) noexcept Q_DECL_PURE_FUNCTION;
0580     QCborValue::Type concreteType() const noexcept { return concreteType(*this); }
0581 
0582     // this will actually be invalid...
0583     constexpr QCborValueRef() : QCborValueConstRef(nullptr, 0) {}
0584 
0585     QCborValueRef(QCborContainerPrivate *dd, qsizetype ii)
0586         : QCborValueConstRef(dd, ii)
0587     {}
0588 #else
0589 private:
0590     using QCborValueConstRef::QCborValueConstRef;
0591 #endif // < Qt 7
0592 
0593     friend class QCborValue;
0594     friend class QCborArray;
0595     friend class QCborMap;
0596     friend class QCborContainerPrivate;
0597     friend class QCborValueConstRef;
0598 
0599     // static so we can pass this by value
0600     QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, const QCborValue &other);
0601     QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, QCborValue &&other);
0602     QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, const QCborValueRef other);
0603 };
0604 QT_WARNING_POP
0605 Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::EncodingOptions)
0606 Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::DiagnosticNotationOptions)
0607 
0608 Q_CORE_EXPORT size_t qHash(const QCborValue &value, size_t seed = 0);
0609 
0610 #if !defined(QT_NO_DEBUG_STREAM)
0611 Q_CORE_EXPORT QDebug operator<<(QDebug, const QCborValue &v);
0612 #endif
0613 
0614 #ifndef QT_NO_DATASTREAM
0615 #if QT_CONFIG(cborstreamwriter)
0616 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QCborValue &);
0617 #endif
0618 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QCborValue &);
0619 #endif
0620 
0621 QT_END_NAMESPACE
0622 
0623 #endif // QCBORVALUE_H