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