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 QCborValue(std::nullptr_t) : t(Null) {}
101 QCborValue(
bool b_) : t(b_ ? True : False) {}
103 QCborValue(
int i) : QCborValue(qint64(i)) {}
104 QCborValue(
unsigned u) : QCborValue(qint64(u)) {}
106 QCborValue(qint64 i) : n(i), t(Integer) {}
107 QCborValue(
double v) : t(Double) { memcpy(&n, &v,
sizeof(n)); }
108 QCborValue(QCborSimpleType st) : t(type_helper(st)) {}
110 QCborValue(
const QByteArray &ba);
111 QCborValue(
const QString &s);
112 QCborValue(QStringView s);
113 QCborValue(QLatin1StringView s);
114#ifndef QT_NO_CAST_FROM_ASCII
115 QT_ASCII_CAST_WARN QCborValue(
const char *s) : QCborValue(QString::fromUtf8(s)) {}
117 QCborValue(
const QCborArray &a);
118 QCborValue(QCborArray &&a);
119 QCborValue(
const QCborMap &m);
120 QCborValue(QCborMap &&m);
121 QCborValue(QCborTag tag,
const QCborValue &taggedValue = QCborValue());
122 QCborValue(QCborKnownTags t_,
const QCborValue &tv = QCborValue())
123 : QCborValue(QCborTag(t_), tv)
126#if QT_CONFIG(datestring)
127 explicit QCborValue(
const QDateTime &dt);
129#ifndef QT_BOOTSTRAPPED
130 explicit QCborValue(
const QUrl &url);
131# if QT_CONFIG(regularexpression)
132 explicit QCborValue(
const QRegularExpression &rx);
134 explicit QCborValue(
const QUuid &uuid);
137 ~QCborValue() {
if (container) dispose(); }
140 QCborValue(
const void *) =
delete;
142 QCborValue(
const QCborValue &other)
noexcept;
143 QCborValue(QCborValue &&other)
noexcept
144 : n(other.n), container(std::exchange(other.container,
nullptr)), t(std::exchange(other.t, Undefined))
147 QCborValue &operator=(
const QCborValue &other)
noexcept;
148 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCborValue)
150 void swap(QCborValue &other)
noexcept
152 std::swap(n, other.n);
153 qt_ptr_swap(container, other.container);
154 std::swap(t, other.t);
157 Type type()
const {
return t; }
158 bool isInteger()
const {
return type() == Integer; }
159 bool isByteArray()
const {
return type() == ByteArray; }
160 bool isString()
const {
return type() == String; }
161 bool isArray()
const {
return type() == Array; }
162 bool isMap()
const {
return type() == Map; }
163 bool isTag()
const {
return isTag_helper(type()); }
164 bool isFalse()
const {
return type() == False; }
165 bool isTrue()
const {
return type() == True; }
166 bool isBool()
const {
return isFalse() || isTrue(); }
167 bool isNull()
const {
return type() == Null; }
168 bool isUndefined()
const {
return type() == Undefined; }
169 bool isDouble()
const {
return type() == Double; }
170 bool isDateTime()
const {
return type() == DateTime; }
171 bool isUrl()
const {
return type() == Url; }
172 bool isRegularExpression()
const {
return type() == RegularExpression; }
173 bool isUuid()
const {
return type() == Uuid; }
174 bool isInvalid()
const {
return type() == Invalid; }
175 bool isContainer()
const {
return isMap() || isArray(); }
177 bool isSimpleType()
const
179 return int(type()) >> 8 ==
int(SimpleType) >> 8;
181 bool isSimpleType(QCborSimpleType st)
const
183 return type() == type_helper(st);
185 QCborSimpleType toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined)
const
187 return isSimpleType() ? QCborSimpleType(type() & 0xff) : defaultValue;
190 qint64 toInteger(qint64 defaultValue = 0)
const
191 {
return isInteger() ? value_helper() : isDouble() ? qint64(fp_helper()) : defaultValue; }
192 bool toBool(
bool defaultValue =
false)
const
193 {
return isBool() ? isTrue() : defaultValue; }
194 double toDouble(
double defaultValue = 0)
const
195 {
return isDouble() ? fp_helper() : isInteger() ?
double(value_helper()) : defaultValue; }
197 QCborTag tag(QCborTag defaultValue = QCborTag(-1))
const;
198 QCborValue taggedValue(
const QCborValue &defaultValue = QCborValue())
const;
200 QByteArray toByteArray(
const QByteArray &defaultValue = {})
const;
201 QString toString(
const QString &defaultValue = {})
const;
202 QAnyStringView toStringView(QAnyStringView defaultValue = {})
const;
203#if QT_CONFIG(datestring)
204 QDateTime toDateTime(
const QDateTime &defaultValue = {})
const;
206#ifndef QT_BOOTSTRAPPED
207 QUrl toUrl(
const QUrl &defaultValue = {})
const;
208# if QT_CONFIG(regularexpression)
209 QRegularExpression toRegularExpression(
const QRegularExpression &defaultValue = {})
const;
211 QUuid toUuid(
const QUuid &defaultValue = {})
const;
215 QCborArray toArray()
const;
216 QCborArray toArray(
const QCborArray &defaultValue)
const;
217 QCborMap toMap()
const;
218 QCborMap toMap(
const QCborMap &defaultValue)
const;
220 const QCborValue operator[](
const QString &key)
const;
221 const QCborValue operator[](QLatin1StringView key)
const;
222 const QCborValue operator[](qint64 key)
const;
223 QCborValueRef operator[](qint64 key);
224 QCborValueRef operator[](QLatin1StringView key);
225 QCborValueRef operator[](
const QString & key);
227 int compare(
const QCborValue &other)
const;
228#if QT_CORE_REMOVED_SINCE(6
, 8
)
229 bool operator==(
const QCborValue &other)
const noexcept
230 {
return compare(other) == 0; }
231 bool operator!=(
const QCborValue &other)
const noexcept
232 {
return !operator==(other); }
233 bool operator<(
const QCborValue &other)
const
234 {
return compare(other) < 0; }
237 static QCborValue fromVariant(
const QVariant &variant);
238 QVariant toVariant()
const;
239 static QCborValue fromJsonValue(
const QJsonValue &v);
240 QJsonValue toJsonValue()
const;
242#if QT_CONFIG(cborstreamreader)
243 static QCborValue fromCbor(QCborStreamReader &reader);
244 static QCborValue fromCbor(
const QByteArray &ba, QCborParserError *error =
nullptr);
245 static QCborValue fromCbor(
const char *data, qsizetype len, QCborParserError *error =
nullptr)
246 {
return fromCbor(QByteArray(data,
int(len)), error); }
247 static QCborValue fromCbor(
const quint8 *data, qsizetype len, QCborParserError *error =
nullptr)
248 {
return fromCbor(QByteArray(
reinterpret_cast<
const char *>(data),
int(len)), error); }
250#if QT_CONFIG(cborstreamwriter)
251 QByteArray toCbor(EncodingOptions opt = NoTransformation)
const;
252 void toCbor(QCborStreamWriter &writer, EncodingOptions opt = NoTransformation)
const;
255 QString toDiagnosticNotation(DiagnosticNotationOptions opts = Compact)
const;
258 friend Q_CORE_EXPORT Q_DECL_PURE_FUNCTION
259 bool comparesEqual(
const QCborValue &lhs,
const QCborValue &rhs)
noexcept;
260 friend Qt::strong_ordering compareThreeWay(
const QCborValue &lhs,
261 const QCborValue &rhs)
noexcept
263 int c = lhs.compare(rhs);
264 return Qt::compareThreeWay(c, 0);
267 Q_DECLARE_STRONGLY_ORDERED(QCborValue)
268 friend class QCborArray;
269 friend class QCborMap;
270 friend class QCborValueConstRef;
271 friend class QCborValueRef;
272 friend class QCborContainerPrivate;
273 friend class QJsonPrivate::Value;
276 QCborContainerPrivate *container =
nullptr;
280 qint64 value_helper()
const
285 double fp_helper()
const
287 static_assert(
sizeof(
double) ==
sizeof(n));
289 memcpy(&d, &n,
sizeof(d));
293 constexpr static Type type_helper(QCborSimpleType st)
295 return Type(quint8(st) | SimpleType);
298 constexpr static bool isTag_helper(Type tt)
300 return tt == Tag || tt >= 0x10000;
313 bool isInteger()
const {
return type() == QCborValue::Integer; }
314 bool isByteArray()
const {
return type() == QCborValue::ByteArray; }
315 bool isString()
const {
return type() == QCborValue::String; }
316 bool isArray()
const {
return type() == QCborValue::Array; }
317 bool isMap()
const {
return type() == QCborValue::Map; }
319 bool isFalse()
const {
return type() == QCborValue::False; }
320 bool isTrue()
const {
return type() == QCborValue::True; }
322 bool isNull()
const {
return type() == QCborValue::Null; }
323 bool isUndefined()
const {
return type() == QCborValue::Undefined; }
324 bool isDouble()
const {
return type() == QCborValue::Double; }
325 bool isDateTime()
const {
return type() == QCborValue::DateTime; }
326 bool isUrl()
const {
return type() == QCborValue::Url; }
328 bool isUuid()
const {
return type() == QCborValue::Uuid; }
329 bool isInvalid()
const {
return type() == QCborValue::Invalid; }
336 return concrete().toSimpleType(defaultValue);
340 {
return concrete().tag(defaultValue); }
342 {
return concrete().taggedValue(defaultValue); }
345 {
return concrete().toInteger(defaultValue); }
346 bool toBool(
bool defaultValue =
false)
const
347 {
return concrete().toBool(defaultValue); }
349 {
return concrete().toDouble(defaultValue); }
352 {
return concrete().toByteArray(defaultValue); }
353 QString
toString(
const QString &defaultValue = {})
const
354 {
return concrete().toString(defaultValue); }
356 {
return concreteStringView(*
this, defaultValue); }
357#if QT_CONFIG(datestring)
361#ifndef QT_BOOTSTRAPPED
362 QUrl
toUrl(
const QUrl &defaultValue = {})
const
363 {
return concrete().toUrl(defaultValue); }
364# if QT_CONFIG(regularexpression)
368 QUuid
toUuid(
const QUuid &defaultValue = {})
const
369 {
return concrete().toUuid(defaultValue); }
373 inline QCborArray
toArray()
const;
374 inline QCborArray
toArray(
const QCborArray &a)
const;
375 inline QCborMap
toMap()
const;
376 inline QCborMap
toMap(
const QCborMap &m)
const;
383 {
return concrete().compare(other); }
388#if QT_CONFIG(cborstreamwriter)
396 {
return concrete().toDiagnosticNotation(opt); }
399 friend class QCborValue;
400 friend class QCborArray;
401 friend class QCborMap;
404 QCborValue
concrete()
const noexcept {
return concrete(*
this); }
405 static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION
bool
412 return comparesEqual_helper(lhs, rhs);
417 return compareThreeWay_helper(lhs, rhs);
426 const QCborValue &rhs)
noexcept
428 return comparesEqual_helper(lhs, rhs);
431 const QCborValue &rhs)
noexcept
433 return compareThreeWay_helper(lhs, rhs);
439 static Q_CORE_EXPORT
bool
441 static Q_CORE_EXPORT
double
443 static Q_CORE_EXPORT qint64
445 static Q_CORE_EXPORT QByteArray
447 static Q_CORE_EXPORT QString
449 static Q_CORE_EXPORT QAnyStringView
461QT6_ONLY(QT_WARNING_DISABLE_MSVC(4275))
462class QT6_ONLY(Q_CORE_EXPORT) QCborValueRef :
public QCborValueConstRef
465 QCborValueRef(
const QCborValueRef &)
noexcept =
default;
466 QCborValueRef(QCborValueRef &&)
noexcept =
default;
467 QCborValueRef &operator=(
const QCborValue &other)
468 { assign(*
this, other);
return *
this; }
469 QCborValueRef &operator=(QCborValue &&other)
470 { assign(*
this, std::move(other)); other.container =
nullptr;
return *
this; }
471 QCborValueRef &operator=(
const QCborValueRef &other)
472 { assign(*
this, other);
return *
this; }
474 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](qint64 key);
475 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](QLatin1StringView key);
476 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](
const QString & key);
478#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
482 operator QCborValue()
const {
return concrete(); }
483 QCborValue::Type type()
const {
return concreteType(); }
484 bool isInteger()
const {
return type() == QCborValue::Integer; }
485 bool isByteArray()
const {
return type() == QCborValue::ByteArray; }
486 bool isString()
const {
return type() == QCborValue::String; }
487 bool isArray()
const {
return type() == QCborValue::Array; }
488 bool isMap()
const {
return type() == QCborValue::Map; }
489 bool isTag()
const {
return QCborValue::isTag_helper(type()); }
490 bool isFalse()
const {
return type() == QCborValue::False; }
491 bool isTrue()
const {
return type() == QCborValue::True; }
492 bool isBool()
const {
return isFalse() || isTrue(); }
493 bool isNull()
const {
return type() == QCborValue::Null; }
494 bool isUndefined()
const {
return type() == QCborValue::Undefined; }
495 bool isDouble()
const {
return type() == QCborValue::Double; }
496 bool isDateTime()
const {
return type() == QCborValue::DateTime; }
497 bool isUrl()
const {
return type() == QCborValue::Url; }
498 bool isRegularExpression()
const {
return type() == QCborValue::RegularExpression; }
499 bool isUuid()
const {
return type() == QCborValue::Uuid; }
500 bool isInvalid()
const {
return type() == QCborValue::Invalid; }
501 bool isContainer()
const {
return isMap() || isArray(); }
502 bool isSimpleType()
const
504 return type() >= QCborValue::SimpleType && type() < QCborValue::SimpleType + 0x100;
506 bool isSimpleType(QCborSimpleType st)
const
508 return type() == QCborValue::type_helper(st);
510 QCborSimpleType toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined)
const
512 return isSimpleType() ? QCborSimpleType(type() & 0xff) : defaultValue;
515 QCborTag tag(QCborTag defaultValue = QCborTag(-1))
const
516 {
return concrete().tag(defaultValue); }
517 QCborValue taggedValue(
const QCborValue &defaultValue = QCborValue())
const
518 {
return concrete().taggedValue(defaultValue); }
520 qint64 toInteger(qint64 defaultValue = 0)
const
521 {
return concreteIntegral(*
this, defaultValue); }
522 bool toBool(
bool defaultValue =
false)
const
523 {
return concreteBoolean(*
this, defaultValue); }
524 double toDouble(
double defaultValue = 0)
const
525 {
return concreteDouble(*
this, defaultValue); }
527 QByteArray toByteArray(
const QByteArray &defaultValue = {})
const
528 {
return concreteByteArray(*
this, defaultValue); }
529 QString toString(
const QString &defaultValue = {})
const
530 {
return concreteString(*
this, defaultValue); }
531#if QT_CONFIG(datestring)
532 QDateTime toDateTime(
const QDateTime &defaultValue = {})
const
533 {
return concrete().toDateTime(defaultValue); }
535#ifndef QT_BOOTSTRAPPED
536 QUrl toUrl(
const QUrl &defaultValue = {})
const
537 {
return concrete().toUrl(defaultValue); }
538# if QT_CONFIG(regularexpression)
539 QRegularExpression toRegularExpression(
const QRegularExpression &defaultValue = {})
const
540 {
return concrete().toRegularExpression(defaultValue); }
542 QUuid toUuid(
const QUuid &defaultValue = {})
const
543 {
return concrete().toUuid(defaultValue); }
547 QCborArray toArray()
const;
548 QCborArray toArray(
const QCborArray &a)
const;
549 QCborMap toMap()
const;
550 QCborMap toMap(
const QCborMap &m)
const;
552 const QCborValue operator[](
const QString &key)
const;
553 const QCborValue operator[](QLatin1StringView key)
const;
554 const QCborValue operator[](qint64 key)
const;
556 int compare(
const QCborValue &other)
const
557 {
return concrete().compare(other); }
558#if QT_CORE_REMOVED_SINCE(6
, 8
)
559 bool operator==(
const QCborValue &other)
const
560 {
return compare(other) == 0; }
561 bool operator!=(
const QCborValue &other)
const
562 {
return !operator==(other); }
563 bool operator<(
const QCborValue &other)
const
564 {
return compare(other) < 0; }
567 QVariant toVariant()
const {
return concrete().toVariant(); }
568 QJsonValue toJsonValue()
const;
570#if QT_CONFIG(cborstreamwriter)
571 using QCborValueConstRef::toCbor;
572 QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation)
573 {
return std::as_const(*
this).toCbor(opt); }
574 void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
577 using QCborValueConstRef::toDiagnosticNotation;
578 QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact)
579 {
return std::as_const(*
this).toDiagnosticNotation(opt); }
582 static QCborValue concrete(QCborValueRef that)
noexcept;
583 QCborValue concrete()
const noexcept {
return concrete(*
this); }
585 Q_DECL_PURE_FUNCTION
static QCborValue::Type concreteType(QCborValueRef self)
noexcept;
586 QCborValue::Type concreteType()
const noexcept {
return concreteType(*
this); }
589 constexpr QCborValueRef() : QCborValueConstRef(
nullptr, 0) {}
591 QCborValueRef(QCborContainerPrivate *dd, qsizetype ii)
592 : QCborValueConstRef(dd, ii)
596 using QCborValueConstRef::QCborValueConstRef;
599 friend class QCborValue;
600 friend class QCborArray;
601 friend class QCborMap;
602 friend class QCborContainerPrivate;
603 friend class QCborValueConstRef;
606 QT7_ONLY(Q_CORE_EXPORT)
static void assign(QCborValueRef that,
const QCborValue &other);
607 QT7_ONLY(Q_CORE_EXPORT)
static void assign(QCborValueRef that, QCborValue &&other);
608 QT7_ONLY(Q_CORE_EXPORT)
static void assign(QCborValueRef that,
const QCborValueRef other);
611Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::EncodingOptions)
612Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::DiagnosticNotationOptions)
614Q_CORE_EXPORT size_t qHash(
const QCborValue &value, size_t seed = 0);
616#if !defined(QT_NO_DEBUG_STREAM)
617Q_CORE_EXPORT
QDebug operator<<(QDebug,
const QCborValue &v);
620#ifndef QT_NO_DATASTREAM
621#if QT_CONFIG(cborstreamwriter)
622Q_CORE_EXPORT QDataStream &operator<<(QDataStream &,
const QCborValue &);
624Q_CORE_EXPORT
QDataStream &operator>>(QDataStream &, QCborValue &);
The QAssociativeIterable class is an iterable interface for an associative container in a QVariant.
\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
double toDouble(double defaultValue=0) const
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
The QSequentialIterable class is an iterable interface for a container in a QVariant.
\keyword 16-bit Floating Point Support\inmodule QtCore \inheaderfile QFloat16
QMutableListIterator< QByteArray > QMutableByteArrayListIterator
Q_DECLARE_TYPEINFO(QByteArrayView, Q_PRIMITIVE_TYPE)
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)