8#include <QtCore/qbytearray.h>
9#include <QtCore/qcborcommon.h>
10#include <QtCore/qcompare.h>
11#include <QtCore/qdatetime.h>
12#if QT_CONFIG(regularexpression)
13# include <QtCore/qregularexpression.h>
15#include <QtCore/qstring.h>
16#include <QtCore/qstringview.h>
17#include <QtCore/qurl.h>
18#include <QtCore/quuid.h>
19#include <QtCore/qvariant.h>
22#if defined(False) && defined(True)
31class QCborStreamReader;
32class QCborStreamWriter;
52 SortKeysInMaps = 0x01,
54#ifndef QT_BOOTSTRAPPED
55 UseFloat16 = UseFloat | 0x04,
61 Q_DECLARE_FLAGS(EncodingOptions, EncodingOption)
63 enum DiagnosticNotationOption {
68 Q_DECLARE_FLAGS(DiagnosticNotationOptions, DiagnosticNotationOption)
81 False = SimpleType +
int(QCborSimpleType::False),
82 True = SimpleType +
int(QCborSimpleType::True),
83 Null = SimpleType +
int(QCborSimpleType::Null),
84 Undefined = SimpleType +
int(QCborSimpleType::Undefined),
91 RegularExpression = 0x10023,
99 QCborValue(Type t_) : t(t_)
100 {
if (isTag_helper(t_)) adjustDefaultConstructedExtendedType(); }
101 QCborValue(std::nullptr_t) : t(Null) {}
102 QCborValue(
bool b_) : t(b_ ? True : False) {}
104 QCborValue(
int i) : QCborValue(qint64(i)) {}
105 QCborValue(
unsigned u) : QCborValue(qint64(u)) {}
107 QCborValue(qint64 i) : n(i), t(Integer) {}
108 QCborValue(
double v) : t(Double) { memcpy(&n, &v,
sizeof(n)); }
109 QCborValue(QCborSimpleType st) : t(type_helper(st)) {}
111 QCborValue(
const QByteArray &ba);
112 QCborValue(
const QString &s);
113 QCborValue(QStringView s);
114 QCborValue(QLatin1StringView s);
115#ifndef QT_NO_CAST_FROM_ASCII
116 QT_ASCII_CAST_WARN QCborValue(
const char *s) : QCborValue(QString::fromUtf8(s)) {}
118 QCborValue(
const QCborArray &a);
119 QCborValue(QCborArray &&a);
120 QCborValue(
const QCborMap &m);
121 QCborValue(QCborMap &&m);
122 QCborValue(QCborTag tag,
const QCborValue &taggedValue = QCborValue());
123 QCborValue(QCborKnownTags t_,
const QCborValue &tv = QCborValue())
124 : QCborValue(QCborTag(t_), tv)
127#if QT_CONFIG(datestring)
128 explicit QCborValue(
const QDateTime &dt);
130#ifndef QT_BOOTSTRAPPED
131 explicit QCborValue(
const QUrl &url);
132# if QT_CONFIG(regularexpression)
133 explicit QCborValue(
const QRegularExpression &rx);
135 explicit QCborValue(
const QUuid &uuid);
138 ~QCborValue() {
if (container) dispose(); }
141 QCborValue(
const void *) =
delete;
143 QCborValue(
const QCborValue &other)
noexcept;
144 QCborValue(QCborValue &&other)
noexcept
145 : n(other.n), container(std::exchange(other.container,
nullptr)), t(std::exchange(other.t, Undefined))
148 QCborValue &operator=(
const QCborValue &other)
noexcept;
149 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCborValue)
151 void swap(QCborValue &other)
noexcept
153 std::swap(n, other.n);
154 qt_ptr_swap(container, other.container);
155 std::swap(t, other.t);
158 Type type()
const {
return t; }
159 bool isInteger()
const {
return type() == Integer; }
160 bool isByteArray()
const {
return type() == ByteArray; }
161 bool isString()
const {
return type() == String; }
162 bool isArray()
const {
return type() == Array; }
163 bool isMap()
const {
return type() == Map; }
164 bool isTag()
const {
return isTag_helper(type()); }
165 bool isFalse()
const {
return type() == False; }
166 bool isTrue()
const {
return type() == True; }
167 bool isBool()
const {
return isFalse() || isTrue(); }
168 bool isNull()
const {
return type() == Null; }
169 bool isUndefined()
const {
return type() == Undefined; }
170 bool isDouble()
const {
return type() == Double; }
171 bool isDateTime()
const {
return type() == DateTime; }
172 bool isUrl()
const {
return type() == Url; }
173 bool isRegularExpression()
const {
return type() == RegularExpression; }
174 bool isUuid()
const {
return type() == Uuid; }
175 bool isInvalid()
const {
return type() == Invalid; }
176 bool isContainer()
const {
return isMap() || isArray(); }
178 bool isSimpleType()
const
180 return int(type()) >> 8 ==
int(SimpleType) >> 8;
182 bool isSimpleType(QCborSimpleType st)
const
184 return type() == type_helper(st);
186 QCborSimpleType toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined)
const
188 return isSimpleType() ? QCborSimpleType(type() & 0xff) : defaultValue;
191 qint64 toInteger(qint64 defaultValue = 0)
const
192 {
return isInteger() ? value_helper() : isDouble() ? qint64(fp_helper()) : defaultValue; }
193 bool toBool(
bool defaultValue =
false)
const
194 {
return isBool() ? isTrue() : defaultValue; }
195 double toDouble(
double defaultValue = 0)
const
196 {
return isDouble() ? fp_helper() : isInteger() ?
double(value_helper()) : defaultValue; }
198 QCborTag tag(QCborTag defaultValue = QCborTag(-1))
const;
199 QCborValue taggedValue(
const QCborValue &defaultValue = QCborValue())
const;
201 QByteArray toByteArray(
const QByteArray &defaultValue = {})
const;
202 QString toString(
const QString &defaultValue = {})
const;
203 QAnyStringView toStringView(QAnyStringView defaultValue = {})
const;
204#if QT_CONFIG(datestring)
205 QDateTime toDateTime(
const QDateTime &defaultValue = {})
const;
207#ifndef QT_BOOTSTRAPPED
208 QUrl toUrl(
const QUrl &defaultValue = {})
const;
209# if QT_CONFIG(regularexpression)
210 QRegularExpression toRegularExpression(
const QRegularExpression &defaultValue = {})
const;
212 QUuid toUuid(
const QUuid &defaultValue = {})
const;
216 QCborArray toArray()
const;
217 QCborArray toArray(
const QCborArray &defaultValue)
const;
218 QCborMap toMap()
const;
219 QCborMap toMap(
const QCborMap &defaultValue)
const;
221 const QCborValue operator[](
const QString &key)
const;
222 const QCborValue operator[](QLatin1StringView key)
const;
223 const QCborValue operator[](qint64 key)
const;
224 QCborValueRef operator[](qint64 key);
225 QCborValueRef operator[](QLatin1StringView key);
226 QCborValueRef operator[](
const QString & key);
228 int compare(
const QCborValue &other)
const;
229#if QT_CORE_REMOVED_SINCE(6
, 8
)
230 bool operator==(
const QCborValue &other)
const noexcept
231 {
return compare(other) == 0; }
232 bool operator!=(
const QCborValue &other)
const noexcept
233 {
return !operator==(other); }
234 bool operator<(
const QCborValue &other)
const
235 {
return compare(other) < 0; }
238 static QCborValue fromVariant(
const QVariant &variant);
239 QVariant toVariant()
const;
240 static QCborValue fromJsonValue(
const QJsonValue &v);
241 QJsonValue toJsonValue()
const;
243#if QT_CONFIG(cborstreamreader)
244 static QCborValue fromCbor(QCborStreamReader &reader);
245 static QCborValue fromCbor(
const QByteArray &ba, QCborParserError *error =
nullptr);
246 static QCborValue fromCbor(
const char *data, qsizetype len, QCborParserError *error =
nullptr)
247 {
return fromCbor(QByteArray(data, len), error); }
248 static QCborValue fromCbor(
const quint8 *data, qsizetype len, QCborParserError *error =
nullptr)
249 {
return fromCbor(QByteArray(
reinterpret_cast<
const char *>(data), len), error); }
251#if QT_CONFIG(cborstreamwriter)
252 QByteArray toCbor(EncodingOptions opt = NoTransformation)
const;
253 void toCbor(QCborStreamWriter &writer, EncodingOptions opt = NoTransformation)
const;
256 QString toDiagnosticNotation(DiagnosticNotationOptions opts = Compact)
const;
259 friend Q_CORE_EXPORT Q_DECL_PURE_FUNCTION
260 bool comparesEqual(
const QCborValue &lhs,
const QCborValue &rhs)
noexcept;
261 friend Qt::strong_ordering compareThreeWay(
const QCborValue &lhs,
262 const QCborValue &rhs)
noexcept
264 int c = lhs.compare(rhs);
265 return Qt::compareThreeWay(c, 0);
268 Q_DECLARE_STRONGLY_ORDERED(QCborValue)
269 friend class QCborArray;
270 friend class QCborMap;
271 friend class QCborValueConstRef;
272 friend class QCborValueRef;
273 friend class QCborContainerPrivate;
274 friend class QJsonPrivate::Value;
277 QCborContainerPrivate *container =
nullptr;
281 void adjustDefaultConstructedExtendedType();
282 qint64 value_helper()
const
287 double fp_helper()
const
289 static_assert(
sizeof(
double) ==
sizeof(n));
291 memcpy(&d, &n,
sizeof(d));
295 constexpr static Type type_helper(QCborSimpleType st)
297 return Type(quint8(st) | SimpleType);
300 constexpr static bool isTag_helper(Type tt)
302 return tt == Tag || tt >= 0x10000;
307Q_CORE_EXPORT size_t qHash(
const QCborValue &value, size_t seed = 0);
317 bool isInteger()
const {
return type() == QCborValue::Integer; }
318 bool isByteArray()
const {
return type() == QCborValue::ByteArray; }
319 bool isString()
const {
return type() == QCborValue::String; }
320 bool isArray()
const {
return type() == QCborValue::Array; }
321 bool isMap()
const {
return type() == QCborValue::Map; }
323 bool isFalse()
const {
return type() == QCborValue::False; }
324 bool isTrue()
const {
return type() == QCborValue::True; }
326 bool isNull()
const {
return type() == QCborValue::Null; }
327 bool isUndefined()
const {
return type() == QCborValue::Undefined; }
328 bool isDouble()
const {
return type() == QCborValue::Double; }
329 bool isDateTime()
const {
return type() == QCborValue::DateTime; }
330 bool isUrl()
const {
return type() == QCborValue::Url; }
332 bool isUuid()
const {
return type() == QCborValue::Uuid; }
333 bool isInvalid()
const {
return type() == QCborValue::Invalid; }
340 return concrete().toSimpleType(defaultValue);
344 {
return concrete().tag(defaultValue); }
346 {
return concrete().taggedValue(defaultValue); }
349 {
return concrete().toInteger(defaultValue); }
350 bool toBool(
bool defaultValue =
false)
const
351 {
return concrete().toBool(defaultValue); }
353 {
return concrete().toDouble(defaultValue); }
356 {
return concrete().toByteArray(defaultValue); }
357 QString
toString(
const QString &defaultValue = {})
const
358 {
return concrete().toString(defaultValue); }
360 {
return concreteStringView(*
this, defaultValue); }
361#if QT_CONFIG(datestring)
365#ifndef QT_BOOTSTRAPPED
366 QUrl
toUrl(
const QUrl &defaultValue = {})
const
367 {
return concrete().toUrl(defaultValue); }
368# if QT_CONFIG(regularexpression)
372 QUuid
toUuid(
const QUuid &defaultValue = {})
const
373 {
return concrete().toUuid(defaultValue); }
377 inline QCborArray
toArray()
const;
378 inline QCborArray
toArray(
const QCborArray &a)
const;
379 inline QCborMap
toMap()
const;
380 inline QCborMap
toMap(
const QCborMap &m)
const;
387 {
return concrete().compare(other); }
392#if QT_CONFIG(cborstreamwriter)
400 {
return concrete().toDiagnosticNotation(opt); }
403 friend class QCborValue;
404 friend class QCborArray;
405 friend class QCborMap;
408 QCborValue
concrete()
const noexcept {
return concrete(*
this); }
411 {
return QHashPrivate::ex1to2arg(key.concrete(), seed); }
413 static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION
bool
420 return comparesEqual_helper(lhs, rhs);
425 return compareThreeWay_helper(lhs, rhs);
434 const QCborValue &rhs)
noexcept
436 return comparesEqual_helper(lhs, rhs);
439 const QCborValue &rhs)
noexcept
441 return compareThreeWay_helper(lhs, rhs);
447 static Q_CORE_EXPORT
bool
449 static Q_CORE_EXPORT
double
451 static Q_CORE_EXPORT qint64
453 static Q_CORE_EXPORT QByteArray
455 static Q_CORE_EXPORT QString
457 static Q_CORE_EXPORT QAnyStringView
469QT6_ONLY(QT_WARNING_DISABLE_MSVC(4275))
470class QT6_ONLY(Q_CORE_EXPORT) QCborValueRef :
public QCborValueConstRef
473 QCborValueRef(
const QCborValueRef &)
noexcept =
default;
474 QCborValueRef(QCborValueRef &&)
noexcept =
default;
475 QCborValueRef &operator=(
const QCborValue &other)
476 { assign(*
this, other);
return *
this; }
477 QCborValueRef &operator=(QCborValue &&other)
478 { assign(*
this, std::move(other)); other.container =
nullptr;
return *
this; }
479 QCborValueRef &operator=(
const QCborValueRef &other)
480 { assign(*
this, other);
return *
this; }
482 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](qint64 key);
483 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](QLatin1StringView key);
484 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](
const QString & key);
486#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
490 operator QCborValue()
const {
return concrete(); }
491 QCborValue::Type type()
const {
return concreteType(); }
492 bool isInteger()
const {
return type() == QCborValue::Integer; }
493 bool isByteArray()
const {
return type() == QCborValue::ByteArray; }
494 bool isString()
const {
return type() == QCborValue::String; }
495 bool isArray()
const {
return type() == QCborValue::Array; }
496 bool isMap()
const {
return type() == QCborValue::Map; }
497 bool isTag()
const {
return QCborValue::isTag_helper(type()); }
498 bool isFalse()
const {
return type() == QCborValue::False; }
499 bool isTrue()
const {
return type() == QCborValue::True; }
500 bool isBool()
const {
return isFalse() || isTrue(); }
501 bool isNull()
const {
return type() == QCborValue::Null; }
502 bool isUndefined()
const {
return type() == QCborValue::Undefined; }
503 bool isDouble()
const {
return type() == QCborValue::Double; }
504 bool isDateTime()
const {
return type() == QCborValue::DateTime; }
505 bool isUrl()
const {
return type() == QCborValue::Url; }
506 bool isRegularExpression()
const {
return type() == QCborValue::RegularExpression; }
507 bool isUuid()
const {
return type() == QCborValue::Uuid; }
508 bool isInvalid()
const {
return type() == QCborValue::Invalid; }
509 bool isContainer()
const {
return isMap() || isArray(); }
510 bool isSimpleType()
const
512 return type() >= QCborValue::SimpleType && type() < QCborValue::SimpleType + 0x100;
514 bool isSimpleType(QCborSimpleType st)
const
516 return type() == QCborValue::type_helper(st);
518 QCborSimpleType toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined)
const
520 return isSimpleType() ? QCborSimpleType(type() & 0xff) : defaultValue;
523 QCborTag tag(QCborTag defaultValue = QCborTag(-1))
const
524 {
return concrete().tag(defaultValue); }
525 QCborValue taggedValue(
const QCborValue &defaultValue = QCborValue())
const
526 {
return concrete().taggedValue(defaultValue); }
528 qint64 toInteger(qint64 defaultValue = 0)
const
529 {
return concreteIntegral(*
this, defaultValue); }
530 bool toBool(
bool defaultValue =
false)
const
531 {
return concreteBoolean(*
this, defaultValue); }
532 double toDouble(
double defaultValue = 0)
const
533 {
return concreteDouble(*
this, defaultValue); }
535 QByteArray toByteArray(
const QByteArray &defaultValue = {})
const
536 {
return concreteByteArray(*
this, defaultValue); }
537 QString toString(
const QString &defaultValue = {})
const
538 {
return concreteString(*
this, defaultValue); }
539#if QT_CONFIG(datestring)
540 QDateTime toDateTime(
const QDateTime &defaultValue = {})
const
541 {
return concrete().toDateTime(defaultValue); }
543#ifndef QT_BOOTSTRAPPED
544 QUrl toUrl(
const QUrl &defaultValue = {})
const
545 {
return concrete().toUrl(defaultValue); }
546# if QT_CONFIG(regularexpression)
547 QRegularExpression toRegularExpression(
const QRegularExpression &defaultValue = {})
const
548 {
return concrete().toRegularExpression(defaultValue); }
550 QUuid toUuid(
const QUuid &defaultValue = {})
const
551 {
return concrete().toUuid(defaultValue); }
555 QCborArray toArray()
const;
556 QCborArray toArray(
const QCborArray &a)
const;
557 QCborMap toMap()
const;
558 QCborMap toMap(
const QCborMap &m)
const;
560 const QCborValue operator[](
const QString &key)
const;
561 const QCborValue operator[](QLatin1StringView key)
const;
562 const QCborValue operator[](qint64 key)
const;
564 int compare(
const QCborValue &other)
const
565 {
return concrete().compare(other); }
566#if QT_CORE_REMOVED_SINCE(6
, 8
)
567 bool operator==(
const QCborValue &other)
const
568 {
return compare(other) == 0; }
569 bool operator!=(
const QCborValue &other)
const
570 {
return !operator==(other); }
571 bool operator<(
const QCborValue &other)
const
572 {
return compare(other) < 0; }
575 QVariant toVariant()
const {
return concrete().toVariant(); }
576 QJsonValue toJsonValue()
const;
578#if QT_CONFIG(cborstreamwriter)
579 using QCborValueConstRef::toCbor;
580 QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation)
581 {
return std::as_const(*
this).toCbor(opt); }
582 void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
585 using QCborValueConstRef::toDiagnosticNotation;
586 QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact)
587 {
return std::as_const(*
this).toDiagnosticNotation(opt); }
590 static QCborValue concrete(QCborValueRef that)
noexcept;
591 QCborValue concrete()
const noexcept {
return concrete(*
this); }
593 Q_DECL_PURE_FUNCTION
static QCborValue::Type concreteType(QCborValueRef self)
noexcept;
594 QCborValue::Type concreteType()
const noexcept {
return concreteType(*
this); }
597 constexpr QCborValueRef() : QCborValueConstRef(
nullptr, 0) {}
599 QCborValueRef(QCborContainerPrivate *dd, qsizetype ii)
600 : QCborValueConstRef(dd, ii)
604 using QCborValueConstRef::QCborValueConstRef;
607 friend class QCborValue;
608 friend class QCborArray;
609 friend class QCborMap;
610 friend class QCborContainerPrivate;
611 friend class QCborValueConstRef;
614 QT7_ONLY(Q_CORE_EXPORT)
static void assign(QCborValueRef that,
const QCborValue &other);
615 QT7_ONLY(Q_CORE_EXPORT)
static void assign(QCborValueRef that, QCborValue &&other);
616 QT7_ONLY(Q_CORE_EXPORT)
static void assign(QCborValueRef that,
const QCborValueRef other);
619Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::EncodingOptions)
620Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::DiagnosticNotationOptions)
622#if !defined(QT_NO_DEBUG_STREAM)
623Q_CORE_EXPORT QDebug operator<<(QDebug,
const QCborValue &v);
626#ifndef QT_NO_DATASTREAM
627#if QT_CONFIG(cborstreamwriter)
628Q_CORE_EXPORT QDataStream &operator<<(QDataStream &,
const QCborValue &);
630Q_CORE_EXPORT
QDataStream &operator>>(QDataStream &, QCborValue &);
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
QCborArray toArray(const QCborArray &a) const
QCborMap toMap(const QCborMap &m) const
QVariant toVariant() const
QCborValueConstRef & operator=(const QCborValueConstRef &)=delete
QCborArray toArray() const
bool toBool(bool defaultValue=false) const
QCborValue taggedValue(const QCborValue &defaultValue=QCborValue()) const
QCborSimpleType toSimpleType(QCborSimpleType defaultValue=QCborSimpleType::Undefined) const
bool isSimpleType() const
bool isRegularExpression() const
QCborValue::Type type() const
QCborValueConstRef(const QCborValueConstRef &)=default
QCborTag tag(QCborTag defaultValue=QCborTag(-1)) const
constexpr QCborValueConstRef()
QByteArray toByteArray(const QByteArray &defaultValue={}) const
qint64 toInteger(qint64 defaultValue=0) const
bool isSimpleType(QCborSimpleType st) const
QUuid toUuid(const QUuid &defaultValue={}) const
QCborContainerPrivate * d
QAnyStringView toStringView(QAnyStringView defaultValue={}) const
friend bool comparesEqual(const QCborValueConstRef &lhs, const QCborValueConstRef &rhs) noexcept
friend bool comparesEqual(const QCborValueConstRef &lhs, const QCborValue &rhs) noexcept
QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt=QCborValue::Compact) const
int compare(const QCborValue &other) const
friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs, const QCborValue &rhs) noexcept
operator QCborValue() const
friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs, const QCborValueConstRef &rhs) noexcept
constexpr QCborValueConstRef(QCborContainerPrivate *dd, qsizetype ii)
QCborValue concrete() const noexcept
QString toString(const QString &defaultValue={}) const
QUrl toUrl(const QUrl &defaultValue={}) const
QJsonValue toJsonValue() const
friend size_t qHash(const QCborValueConstRef &key, size_t seed=0) noexcept
double toDouble(double defaultValue=0) const
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\keyword 16-bit Floating Point Support\inmodule QtCore \inheaderfile QFloat16
Combined button and popup list for selecting options.
QMutableListIterator< QByteArray > QMutableByteArrayListIterator
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
QList< QVariant > QVariantList
#define qCWarning(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
#define QStringLiteral(str)
\inmodule QtCore\reentrant
QString errorString() const
\variable QCborParserError::offset
~QListSpecialMethods()=default
QListSpecialMethods & operator=(const QListSpecialMethods &)=default
QListSpecialMethods(QListSpecialMethods &&)=default
QListSpecialMethods & operator=(QListSpecialMethods &&)=default
QListSpecialMethods()=default
QListSpecialMethods(const QListSpecialMethods &)=default
QByteArray join(QByteArrayView sep={}) const
static T value(const Iterator &it)
static T value(Iterator &it)
static QCborValueConstRef key(Iterator &it)
static QCborValueConstRef key(const Iterator &it)