File indexing completed on 2026-05-07 08:48:06
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 class QCborValueConstRef
0306 {
0307 public:
0308 QCborValueConstRef(const QCborValueConstRef &) = default;
0309 QCborValueConstRef &operator=(const QCborValueConstRef &) = delete;
0310 operator QCborValue() const { return concrete(); }
0311
0312 QCborValue::Type type() const { return concreteType(*this); }
0313 bool isInteger() const { return type() == QCborValue::Integer; }
0314 bool isByteArray() const { return type() == QCborValue::ByteArray; }
0315 bool isString() const { return type() == QCborValue::String; }
0316 bool isArray() const { return type() == QCborValue::Array; }
0317 bool isMap() const { return type() == QCborValue::Map; }
0318 bool isTag() const { return concrete().isTag(); }
0319 bool isFalse() const { return type() == QCborValue::False; }
0320 bool isTrue() const { return type() == QCborValue::True; }
0321 bool isBool() const { return isFalse() || isTrue(); }
0322 bool isNull() const { return type() == QCborValue::Null; }
0323 bool isUndefined() const { return type() == QCborValue::Undefined; }
0324 bool isDouble() const { return type() == QCborValue::Double; }
0325 bool isDateTime() const { return type() == QCborValue::DateTime; }
0326 bool isUrl() const { return type() == QCborValue::Url; }
0327 bool isRegularExpression() const { return type() == QCborValue::RegularExpression; }
0328 bool isUuid() const { return type() == QCborValue::Uuid; }
0329 bool isInvalid() const { return type() == QCborValue::Invalid; }
0330 bool isContainer() const { return isMap() || isArray(); }
0331 bool isSimpleType() const { return concrete().isSimpleType(); }
0332 bool isSimpleType(QCborSimpleType st) const { return concrete().isSimpleType(st); }
0333
0334 QCborSimpleType toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined) const
0335 {
0336 return concrete().toSimpleType(defaultValue);
0337 }
0338
0339 QCborTag tag(QCborTag defaultValue = QCborTag(-1)) const
0340 { return concrete().tag(defaultValue); }
0341 QCborValue taggedValue(const QCborValue &defaultValue = QCborValue()) const
0342 { return concrete().taggedValue(defaultValue); }
0343
0344 qint64 toInteger(qint64 defaultValue = 0) const
0345 { return concrete().toInteger(defaultValue); }
0346 bool toBool(bool defaultValue = false) const
0347 { return concrete().toBool(defaultValue); }
0348 double toDouble(double defaultValue = 0) const
0349 { return concrete().toDouble(defaultValue); }
0350
0351 QByteArray toByteArray(const QByteArray &defaultValue = {}) const
0352 { return concrete().toByteArray(defaultValue); }
0353 QString toString(const QString &defaultValue = {}) const
0354 { return concrete().toString(defaultValue); }
0355 QAnyStringView toStringView(QAnyStringView defaultValue = {}) const
0356 { return concreteStringView(*this, defaultValue); }
0357 #if QT_CONFIG(datestring)
0358 QDateTime toDateTime(const QDateTime &defaultValue = {}) const
0359 { return concrete().toDateTime(defaultValue); }
0360 #endif
0361 #ifndef QT_BOOTSTRAPPED
0362 QUrl toUrl(const QUrl &defaultValue = {}) const
0363 { return concrete().toUrl(defaultValue); }
0364 # if QT_CONFIG(regularexpression)
0365 QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const
0366 { return concrete().toRegularExpression(defaultValue); }
0367 # endif
0368 QUuid toUuid(const QUuid &defaultValue = {}) const
0369 { return concrete().toUuid(defaultValue); }
0370 #endif
0371
0372
0373 inline QCborArray toArray() const;
0374 inline QCborArray toArray(const QCborArray &a) const;
0375 inline QCborMap toMap() const;
0376 inline QCborMap toMap(const QCborMap &m) const;
0377
0378 Q_CORE_EXPORT const QCborValue operator[](const QString &key) const;
0379 Q_CORE_EXPORT const QCborValue operator[](QLatin1StringView key) const;
0380 Q_CORE_EXPORT const QCborValue operator[](qint64 key) const;
0381
0382 int compare(const QCborValue &other) const
0383 { return concrete().compare(other); }
0384
0385 QVariant toVariant() const { return concrete().toVariant(); }
0386 inline QJsonValue toJsonValue() const;
0387
0388 #if QT_CONFIG(cborstreamwriter)
0389 QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation) const
0390 { return concrete().toCbor(opt); }
0391 void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation) const
0392 { return concrete().toCbor(writer, opt); }
0393 #endif
0394
0395 QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact) const
0396 { return concrete().toDiagnosticNotation(opt); }
0397
0398 protected:
0399 friend class QCborValue;
0400 friend class QCborArray;
0401 friend class QCborMap;
0402 friend class QCborContainerPrivate;
0403
0404 QCborValue concrete() const noexcept { return concrete(*this); }
0405 static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool
0406 comparesEqual_helper(QCborValueConstRef lhs, QCborValueConstRef rhs) noexcept;
0407 static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION Qt::strong_ordering
0408 compareThreeWay_helper(QCborValueConstRef lhs, QCborValueConstRef rhs) noexcept;
0409 friend bool comparesEqual(const QCborValueConstRef &lhs,
0410 const QCborValueConstRef &rhs) noexcept
0411 {
0412 return comparesEqual_helper(lhs, rhs);
0413 }
0414 friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs,
0415 const QCborValueConstRef &rhs) noexcept
0416 {
0417 return compareThreeWay_helper(lhs, rhs);
0418 }
0419 Q_DECLARE_STRONGLY_ORDERED(QCborValueConstRef)
0420
0421 static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool
0422 comparesEqual_helper(QCborValueConstRef lhs, const QCborValue &rhs) noexcept;
0423 static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION Qt::strong_ordering
0424 compareThreeWay_helper(QCborValueConstRef lhs, const QCborValue &rhs) noexcept;
0425 friend bool comparesEqual(const QCborValueConstRef &lhs,
0426 const QCborValue &rhs) noexcept
0427 {
0428 return comparesEqual_helper(lhs, rhs);
0429 }
0430 friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs,
0431 const QCborValue &rhs) noexcept
0432 {
0433 return compareThreeWay_helper(lhs, rhs);
0434 }
0435 Q_DECLARE_STRONGLY_ORDERED(QCborValueConstRef, QCborValue)
0436
0437 static Q_CORE_EXPORT QCborValue concrete(QCborValueConstRef that) noexcept;
0438 static Q_CORE_EXPORT QCborValue::Type concreteType(QCborValueConstRef that) noexcept Q_DECL_PURE_FUNCTION;
0439 static Q_CORE_EXPORT bool
0440 concreteBoolean(QCborValueConstRef that, bool defaultValue) noexcept Q_DECL_PURE_FUNCTION;
0441 static Q_CORE_EXPORT double
0442 concreteDouble(QCborValueConstRef that, double defaultValue) noexcept Q_DECL_PURE_FUNCTION;
0443 static Q_CORE_EXPORT qint64
0444 concreteIntegral(QCborValueConstRef that, qint64 defaultValue) noexcept Q_DECL_PURE_FUNCTION;
0445 static Q_CORE_EXPORT QByteArray
0446 concreteByteArray(QCborValueConstRef that, const QByteArray &defaultValue);
0447 static Q_CORE_EXPORT QString
0448 concreteString(QCborValueConstRef that, const QString &defaultValue);
0449 static Q_CORE_EXPORT QAnyStringView
0450 concreteStringView(QCborValueConstRef that, QAnyStringView defaultValue);
0451
0452 constexpr QCborValueConstRef() : d(nullptr), i(0) {}
0453 constexpr QCborValueConstRef(QCborContainerPrivate *dd, qsizetype ii)
0454 : d(dd), i(ii)
0455 {}
0456 QCborContainerPrivate *d;
0457 qsizetype i;
0458 };
0459
0460 QT_WARNING_PUSH
0461 QT6_ONLY(QT_WARNING_DISABLE_MSVC(4275))
0462 class QT6_ONLY(Q_CORE_EXPORT) QCborValueRef : public QCborValueConstRef
0463 {
0464 public:
0465 QCborValueRef(const QCborValueRef &) noexcept = default;
0466 QCborValueRef(QCborValueRef &&) noexcept = default;
0467 QCborValueRef &operator=(const QCborValue &other)
0468 { assign(*this, other); return *this; }
0469 QCborValueRef &operator=(QCborValue &&other)
0470 { assign(*this, std::move(other)); other.container = nullptr; return *this; }
0471 QCborValueRef &operator=(const QCborValueRef &other)
0472 { assign(*this, other); return *this; }
0473
0474 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](qint64 key);
0475 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](QLatin1StringView key);
0476 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](const QString & key);
0477
0478 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
0479
0480
0481
0482 operator QCborValue() const { return concrete(); }
0483 QCborValue::Type type() const { return concreteType(); }
0484 bool isInteger() const { return type() == QCborValue::Integer; }
0485 bool isByteArray() const { return type() == QCborValue::ByteArray; }
0486 bool isString() const { return type() == QCborValue::String; }
0487 bool isArray() const { return type() == QCborValue::Array; }
0488 bool isMap() const { return type() == QCborValue::Map; }
0489 bool isTag() const { return QCborValue::isTag_helper(type()); }
0490 bool isFalse() const { return type() == QCborValue::False; }
0491 bool isTrue() const { return type() == QCborValue::True; }
0492 bool isBool() const { return isFalse() || isTrue(); }
0493 bool isNull() const { return type() == QCborValue::Null; }
0494 bool isUndefined() const { return type() == QCborValue::Undefined; }
0495 bool isDouble() const { return type() == QCborValue::Double; }
0496 bool isDateTime() const { return type() == QCborValue::DateTime; }
0497 bool isUrl() const { return type() == QCborValue::Url; }
0498 bool isRegularExpression() const { return type() == QCborValue::RegularExpression; }
0499 bool isUuid() const { return type() == QCborValue::Uuid; }
0500 bool isInvalid() const { return type() == QCborValue::Invalid; }
0501 bool isContainer() const { return isMap() || isArray(); }
0502 bool isSimpleType() const
0503 {
0504 return type() >= QCborValue::SimpleType && type() < QCborValue::SimpleType + 0x100;
0505 }
0506 bool isSimpleType(QCborSimpleType st) const
0507 {
0508 return type() == QCborValue::type_helper(st);
0509 }
0510 QCborSimpleType toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined) const
0511 {
0512 return isSimpleType() ? QCborSimpleType(type() & 0xff) : defaultValue;
0513 }
0514
0515 QCborTag tag(QCborTag defaultValue = QCborTag(-1)) const
0516 { return concrete().tag(defaultValue); }
0517 QCborValue taggedValue(const QCborValue &defaultValue = QCborValue()) const
0518 { return concrete().taggedValue(defaultValue); }
0519
0520 qint64 toInteger(qint64 defaultValue = 0) const
0521 { return concreteIntegral(*this, defaultValue); }
0522 bool toBool(bool defaultValue = false) const
0523 { return concreteBoolean(*this, defaultValue); }
0524 double toDouble(double defaultValue = 0) const
0525 { return concreteDouble(*this, defaultValue); }
0526
0527 QByteArray toByteArray(const QByteArray &defaultValue = {}) const
0528 { return concreteByteArray(*this, defaultValue); }
0529 QString toString(const QString &defaultValue = {}) const
0530 { return concreteString(*this, defaultValue); }
0531 #if QT_CONFIG(datestring)
0532 QDateTime toDateTime(const QDateTime &defaultValue = {}) const
0533 { return concrete().toDateTime(defaultValue); }
0534 #endif
0535 #ifndef QT_BOOTSTRAPPED
0536 QUrl toUrl(const QUrl &defaultValue = {}) const
0537 { return concrete().toUrl(defaultValue); }
0538 # if QT_CONFIG(regularexpression)
0539 QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const
0540 { return concrete().toRegularExpression(defaultValue); }
0541 # endif
0542 QUuid toUuid(const QUuid &defaultValue = {}) const
0543 { return concrete().toUuid(defaultValue); }
0544 #endif
0545
0546
0547 QCborArray toArray() const;
0548 QCborArray toArray(const QCborArray &a) const;
0549 QCborMap toMap() const;
0550 QCborMap toMap(const QCborMap &m) const;
0551
0552 const QCborValue operator[](const QString &key) const;
0553 const QCborValue operator[](QLatin1StringView key) const;
0554 const QCborValue operator[](qint64 key) const;
0555
0556 int compare(const QCborValue &other) const
0557 { return concrete().compare(other); }
0558 #if QT_CORE_REMOVED_SINCE(6, 8)
0559 bool operator==(const QCborValue &other) const
0560 { return compare(other) == 0; }
0561 bool operator!=(const QCborValue &other) const
0562 { return !operator==(other); }
0563 bool operator<(const QCborValue &other) const
0564 { return compare(other) < 0; }
0565 #endif
0566
0567 QVariant toVariant() const { return concrete().toVariant(); }
0568 QJsonValue toJsonValue() const;
0569
0570 #if QT_CONFIG(cborstreamwriter)
0571 using QCborValueConstRef::toCbor;
0572 QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation)
0573 { return std::as_const(*this).toCbor(opt); }
0574 void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
0575 #endif
0576
0577 using QCborValueConstRef::toDiagnosticNotation;
0578 QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact)
0579 { return std::as_const(*this).toDiagnosticNotation(opt); }
0580
0581 private:
0582 static QCborValue concrete(QCborValueRef that) noexcept;
0583 QCborValue concrete() const noexcept { return concrete(*this); }
0584
0585 static QCborValue::Type concreteType(QCborValueRef self) noexcept Q_DECL_PURE_FUNCTION;
0586 QCborValue::Type concreteType() const noexcept { return concreteType(*this); }
0587
0588
0589 constexpr QCborValueRef() : QCborValueConstRef(nullptr, 0) {}
0590
0591 QCborValueRef(QCborContainerPrivate *dd, qsizetype ii)
0592 : QCborValueConstRef(dd, ii)
0593 {}
0594 #else
0595 private:
0596 using QCborValueConstRef::QCborValueConstRef;
0597 #endif
0598
0599 friend class QCborValue;
0600 friend class QCborArray;
0601 friend class QCborMap;
0602 friend class QCborContainerPrivate;
0603 friend class QCborValueConstRef;
0604
0605
0606 QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, const QCborValue &other);
0607 QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, QCborValue &&other);
0608 QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, const QCborValueRef other);
0609 };
0610 QT_WARNING_POP
0611 Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::EncodingOptions)
0612 Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::DiagnosticNotationOptions)
0613
0614 Q_CORE_EXPORT size_t qHash(const QCborValue &value, size_t seed = 0);
0615
0616 #if !defined(QT_NO_DEBUG_STREAM)
0617 Q_CORE_EXPORT QDebug operator<<(QDebug, const QCborValue &v);
0618 #endif
0619
0620 #ifndef QT_NO_DATASTREAM
0621 #if QT_CONFIG(cborstreamwriter)
0622 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QCborValue &);
0623 #endif
0624 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QCborValue &);
0625 #endif
0626
0627 QT_END_NAMESPACE
0628
0629 #endif