Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcborvalue.h
Go to the documentation of this file.
1// Copyright (C) 2022 Intel Corporation.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCBORVALUE_H
5#define QCBORVALUE_H
6
7#include <QtCore/qbytearray.h>
8#include <QtCore/qcborcommon.h>
9#include <QtCore/qcompare.h>
10#include <QtCore/qdatetime.h>
11#if QT_CONFIG(regularexpression)
12# include <QtCore/qregularexpression.h>
13#endif
14#include <QtCore/qstring.h>
15#include <QtCore/qstringview.h>
16#include <QtCore/qurl.h>
17#include <QtCore/quuid.h>
18#include <QtCore/qvariant.h>
19
20/* X11 headers use these values too, but as defines */
21#if defined(False) && defined(True)
22# undef True
23# undef False
24#endif
25
27
28class QCborArray;
29class QCborMap;
32class QDataStream;
33
34namespace QJsonPrivate { class Value; }
35
43
44class QCborValueRef;
46class Q_CORE_EXPORT QCborValue
47{
49public:
51 SortKeysInMaps = 0x01,
52 UseFloat = 0x02,
53#ifndef QT_BOOTSTRAPPED
54 UseFloat16 = UseFloat | 0x04,
55#endif
56 UseIntegers = 0x08,
57
58 NoTransformation = 0
59 };
60 Q_DECLARE_FLAGS(EncodingOptions, EncodingOption)
61
63 Compact = 0x00,
64 LineWrapped = 0x01,
65 ExtendedFormat = 0x02
66 };
67 Q_DECLARE_FLAGS(DiagnosticNotationOptions, DiagnosticNotationOption)
68
69 // different from QCborStreamReader::Type because we have more types
70 enum Type : int {
71 Integer = 0x00,
72 ByteArray = 0x40,
73 String = 0x60,
74 Array = 0x80,
75 Map = 0xa0,
76 Tag = 0xc0,
77
78 // range 0x100 - 0x1ff for Simple Types
79 SimpleType = 0x100,
80 False = SimpleType + int(QCborSimpleType::False),
81 True = SimpleType + int(QCborSimpleType::True),
82 Null = SimpleType + int(QCborSimpleType::Null),
84
85 Double = 0x202,
86
87 // extended (tagged) types
88 DateTime = 0x10000,
89 Url = 0x10020,
91 Uuid = 0x10025,
92
93 Invalid = -1
94 };
96
98 QCborValue(Type t_) : t(t_) {}
99 QCborValue(std::nullptr_t) : t(Null) {}
100 QCborValue(bool b_) : t(b_ ? True : False) {}
101#ifndef Q_QDOC
103 QCborValue(unsigned u) : QCborValue(qint64(u)) {}
104#endif
105 QCborValue(qint64 i) : n(i), t(Integer) {}
106 QCborValue(double v) : t(Double) { memcpy(&n, &v, sizeof(n)); }
107 QCborValue(QCborSimpleType st) : t(type_helper(st)) {}
108
109 QCborValue(const QByteArray &ba);
110 QCborValue(const QString &s);
113#ifndef QT_NO_CAST_FROM_ASCII
114 QT_ASCII_CAST_WARN QCborValue(const char *s) : QCborValue(QString::fromUtf8(s)) {}
115#endif
116 QCborValue(const QCborArray &a);
118 QCborValue(const QCborMap &m);
120 QCborValue(QCborTag tag, const QCborValue &taggedValue = QCborValue());
122 : QCborValue(QCborTag(t_), tv)
123 {}
124
125 explicit QCborValue(const QDateTime &dt);
126#ifndef QT_BOOTSTRAPPED
127 explicit QCborValue(const QUrl &url);
128# if QT_CONFIG(regularexpression)
129 explicit QCborValue(const QRegularExpression &rx);
130# endif
131 explicit QCborValue(const QUuid &uuid);
132#endif
133
134 ~QCborValue() { if (container) dispose(); }
135
136 // make sure const char* doesn't go call the bool constructor
137 QCborValue(const void *) = delete;
138
139 QCborValue(const QCborValue &other) noexcept;
141 : n(other.n), container(std::exchange(other.container, nullptr)), t(std::exchange(other.t, Undefined))
142 {
143 }
144 QCborValue &operator=(const QCborValue &other) noexcept;
145 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCborValue)
146
148 {
149 std::swap(n, other.n);
150 qt_ptr_swap(container, other.container);
151 std::swap(t, other.t);
152 }
153
154 Type type() const { return t; }
155 bool isInteger() const { return type() == Integer; }
156 bool isByteArray() const { return type() == ByteArray; }
157 bool isString() const { return type() == String; }
158 bool isArray() const { return type() == Array; }
159 bool isMap() const { return type() == Map; }
160 bool isTag() const { return isTag_helper(type()); }
161 bool isFalse() const { return type() == False; }
162 bool isTrue() const { return type() == True; }
163 bool isBool() const { return isFalse() || isTrue(); }
164 bool isNull() const { return type() == Null; }
165 bool isUndefined() const { return type() == Undefined; }
166 bool isDouble() const { return type() == Double; }
167 bool isDateTime() const { return type() == DateTime; }
168 bool isUrl() const { return type() == Url; }
169 bool isRegularExpression() const { return type() == RegularExpression; }
170 bool isUuid() const { return type() == Uuid; }
171 bool isInvalid() const { return type() == Invalid; }
172 bool isContainer() const { return isMap() || isArray(); }
173
174 bool isSimpleType() const
175 {
176 return int(type()) >> 8 == int(SimpleType) >> 8;
177 }
179 {
180 return type() == type_helper(st);
181 }
183 {
184 return isSimpleType() ? QCborSimpleType(type() & 0xff) : defaultValue;
185 }
186
187 qint64 toInteger(qint64 defaultValue = 0) const
188 { return isInteger() ? value_helper() : isDouble() ? qint64(fp_helper()) : defaultValue; }
189 bool toBool(bool defaultValue = false) const
190 { return isBool() ? isTrue() : defaultValue; }
191 double toDouble(double defaultValue = 0) const
192 { return isDouble() ? fp_helper() : isInteger() ? double(value_helper()) : defaultValue; }
193
194 QCborTag tag(QCborTag defaultValue = QCborTag(-1)) const;
195 QCborValue taggedValue(const QCborValue &defaultValue = QCborValue()) const;
196
197 QByteArray toByteArray(const QByteArray &defaultValue = {}) const;
198 QString toString(const QString &defaultValue = {}) const;
199 QDateTime toDateTime(const QDateTime &defaultValue = {}) const;
200#ifndef QT_BOOTSTRAPPED
201 QUrl toUrl(const QUrl &defaultValue = {}) const;
202# if QT_CONFIG(regularexpression)
203 QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const;
204# endif
205 QUuid toUuid(const QUuid &defaultValue = {}) const;
206#endif
207
208 // only forward-declared, need split functions
209 QCborArray toArray() const;
210 QCborArray toArray(const QCborArray &defaultValue) const;
211 QCborMap toMap() const;
212 QCborMap toMap(const QCborMap &defaultValue) const;
213
214 const QCborValue operator[](const QString &key) const;
215 const QCborValue operator[](QLatin1StringView key) const;
216 const QCborValue operator[](qint64 key) const;
217 QCborValueRef operator[](qint64 key);
218 QCborValueRef operator[](QLatin1StringView key);
219 QCborValueRef operator[](const QString & key);
220
221 int compare(const QCborValue &other) const;
222#if QT_CORE_REMOVED_SINCE(6, 8)
223 bool operator==(const QCborValue &other) const noexcept
224 { return compare(other) == 0; }
225 bool operator!=(const QCborValue &other) const noexcept
226 { return !operator==(other); }
227 bool operator<(const QCborValue &other) const
228 { return compare(other) < 0; }
229#endif
230
231 static QCborValue fromVariant(const QVariant &variant);
232 QVariant toVariant() const;
233 static QCborValue fromJsonValue(const QJsonValue &v);
234 QJsonValue toJsonValue() const;
235
236#if QT_CONFIG(cborstreamreader)
237 static QCborValue fromCbor(QCborStreamReader &reader);
238 static QCborValue fromCbor(const QByteArray &ba, QCborParserError *error = nullptr);
239 static QCborValue fromCbor(const char *data, qsizetype len, QCborParserError *error = nullptr)
240 { return fromCbor(QByteArray(data, int(len)), error); }
241 static QCborValue fromCbor(const quint8 *data, qsizetype len, QCborParserError *error = nullptr)
242 { return fromCbor(QByteArray(reinterpret_cast<const char *>(data), int(len)), error); }
243#endif // QT_CONFIG(cborstreamreader)
244#if QT_CONFIG(cborstreamwriter)
245 QByteArray toCbor(EncodingOptions opt = NoTransformation) const;
246 void toCbor(QCborStreamWriter &writer, EncodingOptions opt = NoTransformation) const;
247#endif
248
249 QString toDiagnosticNotation(DiagnosticNotationOptions opts = Compact) const;
250
251private:
252 friend Q_CORE_EXPORT Q_DECL_PURE_FUNCTION
253 bool comparesEqual(const QCborValue &lhs, const QCborValue &rhs) noexcept;
255 const QCborValue &rhs) noexcept
256 {
257 int c = lhs.compare(rhs);
258 return Qt::compareThreeWay(c, 0);
259 }
260
262 friend class QCborArray;
263 friend class QCborMap;
264 friend class QCborValueConstRef;
265 friend class QCborValueRef;
267 friend class QJsonPrivate::Value;
268
269 qint64 n = 0;
270 QCborContainerPrivate *container = nullptr;
271 Type t = Undefined;
272
273 void dispose();
274 qint64 value_helper() const
275 {
276 return n;
277 }
278
279 double fp_helper() const
280 {
281 static_assert(sizeof(double) == sizeof(n));
282 double d;
283 memcpy(&d, &n, sizeof(d));
284 return d;
285 }
286
287 constexpr static Type type_helper(QCborSimpleType st)
288 {
289 return Type(quint8(st) | SimpleType);
290 }
291
292 constexpr static bool isTag_helper(Type tt)
293 {
294 return tt == Tag || tt >= 0x10000;
295 }
296};
297Q_DECLARE_SHARED(QCborValue)
298
300{
301public:
304 operator QCborValue() const { return concrete(); }
305
306 QCborValue::Type type() const { return concreteType(*this); }
307 bool isInteger() const { return type() == QCborValue::Integer; }
308 bool isByteArray() const { return type() == QCborValue::ByteArray; }
309 bool isString() const { return type() == QCborValue::String; }
310 bool isArray() const { return type() == QCborValue::Array; }
311 bool isMap() const { return type() == QCborValue::Map; }
312 bool isTag() const { return concrete().isTag(); }
313 bool isFalse() const { return type() == QCborValue::False; }
314 bool isTrue() const { return type() == QCborValue::True; }
315 bool isBool() const { return isFalse() || isTrue(); }
316 bool isNull() const { return type() == QCborValue::Null; }
317 bool isUndefined() const { return type() == QCborValue::Undefined; }
318 bool isDouble() const { return type() == QCborValue::Double; }
319 bool isDateTime() const { return type() == QCborValue::DateTime; }
320 bool isUrl() const { return type() == QCborValue::Url; }
322 bool isUuid() const { return type() == QCborValue::Uuid; }
323 bool isInvalid() const { return type() == QCborValue::Invalid; }
324 bool isContainer() const { return isMap() || isArray(); }
325 bool isSimpleType() const { return concrete().isSimpleType(); }
326 bool isSimpleType(QCborSimpleType st) const { return concrete().isSimpleType(st); }
327
329 {
330 return concrete().toSimpleType(defaultValue);
331 }
332
333 QCborTag tag(QCborTag defaultValue = QCborTag(-1)) const
334 { return concrete().tag(defaultValue); }
335 QCborValue taggedValue(const QCborValue &defaultValue = QCborValue()) const
336 { return concrete().taggedValue(defaultValue); }
337
338 qint64 toInteger(qint64 defaultValue = 0) const
339 { return concrete().toInteger(defaultValue); }
340 bool toBool(bool defaultValue = false) const
341 { return concrete().toBool(defaultValue); }
342 double toDouble(double defaultValue = 0) const
343 { return concrete().toDouble(defaultValue); }
344
345 QByteArray toByteArray(const QByteArray &defaultValue = {}) const
346 { return concrete().toByteArray(defaultValue); }
347 QString toString(const QString &defaultValue = {}) const
348 { return concrete().toString(defaultValue); }
349 QDateTime toDateTime(const QDateTime &defaultValue = {}) const
350 { return concrete().toDateTime(defaultValue); }
351#ifndef QT_BOOTSTRAPPED
352 QUrl toUrl(const QUrl &defaultValue = {}) const
353 { return concrete().toUrl(defaultValue); }
354# if QT_CONFIG(regularexpression)
355 QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const
356 { return concrete().toRegularExpression(defaultValue); }
357# endif
358 QUuid toUuid(const QUuid &defaultValue = {}) const
359 { return concrete().toUuid(defaultValue); }
360#endif
361
362 // only forward-declared, need split functions. Implemented in qcbor{array,map}.h
363 inline QCborArray toArray() const;
364 inline QCborArray toArray(const QCborArray &a) const;
365 inline QCborMap toMap() const;
366 inline QCborMap toMap(const QCborMap &m) const;
367
368 Q_CORE_EXPORT const QCborValue operator[](const QString &key) const;
369 Q_CORE_EXPORT const QCborValue operator[](QLatin1StringView key) const;
370 Q_CORE_EXPORT const QCborValue operator[](qint64 key) const;
371
372 int compare(const QCborValue &other) const
373 { return concrete().compare(other); }
374
375 QVariant toVariant() const { return concrete().toVariant(); }
376 inline QJsonValue toJsonValue() const; // in qjsonvalue.h
377
378#if QT_CONFIG(cborstreamwriter)
379 QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation) const
380 { return concrete().toCbor(opt); }
381 void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation) const
382 { return concrete().toCbor(writer, opt); }
383#endif
384
385 QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact) const
386 { return concrete().toDiagnosticNotation(opt); }
387
388protected:
389 friend class QCborValue;
390 friend class QCborArray;
391 friend class QCborMap;
393
394 QCborValue concrete() const noexcept { return concrete(*this); }
395 static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool
396 comparesEqual_helper(QCborValueConstRef lhs, QCborValueConstRef rhs) noexcept;
397 static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION Qt::strong_ordering
398 compareThreeWay_helper(QCborValueConstRef lhs, QCborValueConstRef rhs) noexcept;
399 friend bool comparesEqual(const QCborValueConstRef &lhs,
400 const QCborValueConstRef &rhs) noexcept
401 {
402 return comparesEqual_helper(lhs, rhs);
403 }
405 const QCborValueConstRef &rhs) noexcept
406 {
407 return compareThreeWay_helper(lhs, rhs);
408 }
410
411 static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool
412 comparesEqual_helper(QCborValueConstRef lhs, const QCborValue &rhs) noexcept;
413 static Q_CORE_EXPORT Q_DECL_PURE_FUNCTION Qt::strong_ordering
414 compareThreeWay_helper(QCborValueConstRef lhs, const QCborValue &rhs) noexcept;
415 friend bool comparesEqual(const QCborValueConstRef &lhs,
416 const QCborValue &rhs) noexcept
417 {
418 return comparesEqual_helper(lhs, rhs);
419 }
421 const QCborValue &rhs) noexcept
422 {
423 return compareThreeWay_helper(lhs, rhs);
424 }
426
427 static Q_CORE_EXPORT QCborValue concrete(QCborValueConstRef that) noexcept;
428 static Q_CORE_EXPORT QCborValue::Type concreteType(QCborValueConstRef that) noexcept Q_DECL_PURE_FUNCTION;
429 static Q_CORE_EXPORT bool
430 concreteBoolean(QCborValueConstRef that, bool defaultValue) noexcept Q_DECL_PURE_FUNCTION;
431 static Q_CORE_EXPORT double
432 concreteDouble(QCborValueConstRef that, double defaultValue) noexcept Q_DECL_PURE_FUNCTION;
433 static Q_CORE_EXPORT qint64
434 concreteIntegral(QCborValueConstRef that, qint64 defaultValue) noexcept Q_DECL_PURE_FUNCTION;
435 static Q_CORE_EXPORT QByteArray
436 concreteByteArray(QCborValueConstRef that, const QByteArray &defaultValue);
437 static Q_CORE_EXPORT QString
438 concreteString(QCborValueConstRef that, const QString &defaultValue);
439
440 constexpr QCborValueConstRef() : d(nullptr), i(0) {} // this will actually be invalid
442 : d(dd), i(ii)
443 {}
446};
447
449QT6_ONLY(QT_WARNING_DISABLE_MSVC(4275)) // non dll-interface class 'QJsonValueConstRef' used as base for dll-interface class 'QJsonValueRef'
450class QT6_ONLY(Q_CORE_EXPORT) QCborValueRef : public QCborValueConstRef
451{
452public:
453 QCborValueRef(const QCborValueRef &) noexcept = default;
454 QCborValueRef(QCborValueRef &&) noexcept = default;
455 QCborValueRef &operator=(const QCborValue &other)
456 { assign(*this, other); return *this; }
457 QCborValueRef &operator=(QCborValue &&other)
458 { assign(*this, std::move(other)); other.container = nullptr; return *this; }
459 QCborValueRef &operator=(const QCborValueRef &other)
460 { assign(*this, other); return *this; }
461
462 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](qint64 key);
463 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](QLatin1StringView key);
464 QT7_ONLY(Q_CORE_EXPORT) QCborValueRef operator[](const QString & key);
465
466#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
467 // retained for binary compatibility (due to the Q_CORE_EXPORT) because at
468 // least one compiler emits and exports all inlines in an exported class
469
470 operator QCborValue() const { return concrete(); }
471 QCborValue::Type type() const { return concreteType(); }
472 bool isInteger() const { return type() == QCborValue::Integer; }
473 bool isByteArray() const { return type() == QCborValue::ByteArray; }
474 bool isString() const { return type() == QCborValue::String; }
475 bool isArray() const { return type() == QCborValue::Array; }
476 bool isMap() const { return type() == QCborValue::Map; }
477 bool isTag() const { return QCborValue::isTag_helper(type()); }
478 bool isFalse() const { return type() == QCborValue::False; }
479 bool isTrue() const { return type() == QCborValue::True; }
480 bool isBool() const { return isFalse() || isTrue(); }
481 bool isNull() const { return type() == QCborValue::Null; }
482 bool isUndefined() const { return type() == QCborValue::Undefined; }
483 bool isDouble() const { return type() == QCborValue::Double; }
484 bool isDateTime() const { return type() == QCborValue::DateTime; }
485 bool isUrl() const { return type() == QCborValue::Url; }
486 bool isRegularExpression() const { return type() == QCborValue::RegularExpression; }
487 bool isUuid() const { return type() == QCborValue::Uuid; }
488 bool isInvalid() const { return type() == QCborValue::Invalid; }
489 bool isContainer() const { return isMap() || isArray(); }
490 bool isSimpleType() const
491 {
492 return type() >= QCborValue::SimpleType && type() < QCborValue::SimpleType + 0x100;
493 }
494 bool isSimpleType(QCborSimpleType st) const
495 {
496 return type() == QCborValue::type_helper(st);
497 }
498 QCborSimpleType toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined) const
499 {
500 return isSimpleType() ? QCborSimpleType(type() & 0xff) : defaultValue;
501 }
502
503 QCborTag tag(QCborTag defaultValue = QCborTag(-1)) const
504 { return concrete().tag(defaultValue); }
505 QCborValue taggedValue(const QCborValue &defaultValue = QCborValue()) const
506 { return concrete().taggedValue(defaultValue); }
507
508 qint64 toInteger(qint64 defaultValue = 0) const
509 { return concreteIntegral(*this, defaultValue); }
510 bool toBool(bool defaultValue = false) const
511 { return concreteBoolean(*this, defaultValue); }
512 double toDouble(double defaultValue = 0) const
513 { return concreteDouble(*this, defaultValue); }
514
515 QByteArray toByteArray(const QByteArray &defaultValue = {}) const
516 { return concreteByteArray(*this, defaultValue); }
517 QString toString(const QString &defaultValue = {}) const
518 { return concreteString(*this, defaultValue); }
519 QDateTime toDateTime(const QDateTime &defaultValue = {}) const
520 { return concrete().toDateTime(defaultValue); }
521#ifndef QT_BOOTSTRAPPED
522 QUrl toUrl(const QUrl &defaultValue = {}) const
523 { return concrete().toUrl(defaultValue); }
524# if QT_CONFIG(regularexpression)
525 QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const
526 { return concrete().toRegularExpression(defaultValue); }
527# endif
528 QUuid toUuid(const QUuid &defaultValue = {}) const
529 { return concrete().toUuid(defaultValue); }
530#endif
531
532 // only forward-declared, need split functions. Implemented in qcbor{array,map}.h
533 QCborArray toArray() const;
534 QCborArray toArray(const QCborArray &a) const;
535 QCborMap toMap() const;
536 QCborMap toMap(const QCborMap &m) const;
537
538 const QCborValue operator[](const QString &key) const;
539 const QCborValue operator[](QLatin1StringView key) const;
540 const QCborValue operator[](qint64 key) const;
541
542 int compare(const QCborValue &other) const
543 { return concrete().compare(other); }
544#if QT_CORE_REMOVED_SINCE(6, 8)
545 bool operator==(const QCborValue &other) const
546 { return compare(other) == 0; }
547 bool operator!=(const QCborValue &other) const
548 { return !operator==(other); }
549 bool operator<(const QCborValue &other) const
550 { return compare(other) < 0; }
551#endif
552
553 QVariant toVariant() const { return concrete().toVariant(); }
554 QJsonValue toJsonValue() const;
555
556#if QT_CONFIG(cborstreamwriter)
557 using QCborValueConstRef::toCbor;
558 QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation)
559 { return std::as_const(*this).toCbor(opt); }
560 void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
561#endif
562
564 QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact)
565 { return std::as_const(*this).toDiagnosticNotation(opt); }
566
567private:
568 static QCborValue concrete(QCborValueRef that) noexcept;
569 QCborValue concrete() const noexcept { return concrete(*this); }
570
571 static QCborValue::Type concreteType(QCborValueRef self) noexcept Q_DECL_PURE_FUNCTION;
572 QCborValue::Type concreteType() const noexcept { return concreteType(*this); }
573
574 // this will actually be invalid...
575 constexpr QCborValueRef() : QCborValueConstRef(nullptr, 0) {}
576
577 QCborValueRef(QCborContainerPrivate *dd, qsizetype ii)
578 : QCborValueConstRef(dd, ii)
579 {}
580#else
581private:
583#endif // < Qt 7
584
585 friend class QCborValue;
586 friend class QCborArray;
587 friend class QCborMap;
588 friend class QCborContainerPrivate;
589 friend class QCborValueConstRef;
590
591 // static so we can pass this by value
592 QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, const QCborValue &other);
593 QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, QCborValue &&other);
594 QT7_ONLY(Q_CORE_EXPORT) static void assign(QCborValueRef that, const QCborValueRef other);
595};
597Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::EncodingOptions)
598Q_DECLARE_OPERATORS_FOR_FLAGS(QCborValue::DiagnosticNotationOptions)
599
600Q_CORE_EXPORT size_t qHash(const QCborValue &value, size_t seed = 0);
601
602#if !defined(QT_NO_DEBUG_STREAM)
603Q_CORE_EXPORT QDebug operator<<(QDebug, const QCborValue &v);
604#endif
605
606#ifndef QT_NO_DATASTREAM
607#if QT_CONFIG(cborstreamwriter)
608Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QCborValue &);
609#endif
610Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QCborValue &);
611#endif
612
614
615#if defined(QT_X11_DEFINES_FOUND)
616# define True 1
617# define False 0
618#endif
619
620#endif // QCBORVALUE_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qcborarray.h:20
\inmodule QtCore\reentrant
Definition qcbormap.h:21
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
bool isBool() const
Definition qcborvalue.h:315
QVariant toVariant() const
Definition qcborvalue.h:375
bool isInteger() const
Definition qcborvalue.h:307
bool isDateTime() const
Definition qcborvalue.h:319
bool isDouble() const
Definition qcborvalue.h:318
bool isString() const
Definition qcborvalue.h:309
QCborValueConstRef & operator=(const QCborValueConstRef &)=delete
bool isUrl() const
Definition qcborvalue.h:320
bool isNull() const
Definition qcborvalue.h:316
bool isContainer() const
Definition qcborvalue.h:324
bool toBool(bool defaultValue=false) const
Definition qcborvalue.h:340
QCborValue taggedValue(const QCborValue &defaultValue=QCborValue()) const
Definition qcborvalue.h:335
bool isByteArray() const
Definition qcborvalue.h:308
QCborSimpleType toSimpleType(QCborSimpleType defaultValue=QCborSimpleType::Undefined) const
Definition qcborvalue.h:328
QDateTime toDateTime(const QDateTime &defaultValue={}) const
Definition qcborvalue.h:349
bool isMap() const
Definition qcborvalue.h:311
bool isSimpleType() const
Definition qcborvalue.h:325
bool isRegularExpression() const
Definition qcborvalue.h:321
bool isUndefined() const
Definition qcborvalue.h:317
QCborValue::Type type() const
Definition qcborvalue.h:306
bool isInvalid() const
Definition qcborvalue.h:323
QCborValueConstRef(const QCborValueConstRef &)=default
bool isUuid() const
Definition qcborvalue.h:322
QCborTag tag(QCborTag defaultValue=QCborTag(-1)) const
Definition qcborvalue.h:333
constexpr QCborValueConstRef()
Definition qcborvalue.h:440
QByteArray toByteArray(const QByteArray &defaultValue={}) const
Definition qcborvalue.h:345
qint64 toInteger(qint64 defaultValue=0) const
Definition qcborvalue.h:338
bool isSimpleType(QCborSimpleType st) const
Definition qcborvalue.h:326
bool isTrue() const
Definition qcborvalue.h:314
QUuid toUuid(const QUuid &defaultValue={}) const
Definition qcborvalue.h:358
QCborContainerPrivate * d
Definition qcborvalue.h:444
bool isFalse() const
Definition qcborvalue.h:313
friend bool comparesEqual(const QCborValueConstRef &lhs, const QCborValueConstRef &rhs) noexcept
Definition qcborvalue.h:399
bool isTag() const
Definition qcborvalue.h:312
friend bool comparesEqual(const QCborValueConstRef &lhs, const QCborValue &rhs) noexcept
Definition qcborvalue.h:415
QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt=QCborValue::Compact) const
Definition qcborvalue.h:385
bool isArray() const
Definition qcborvalue.h:310
int compare(const QCborValue &other) const
Definition qcborvalue.h:372
friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs, const QCborValue &rhs) noexcept
Definition qcborvalue.h:420
friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs, const QCborValueConstRef &rhs) noexcept
Definition qcborvalue.h:404
constexpr QCborValueConstRef(QCborContainerPrivate *dd, qsizetype ii)
Definition qcborvalue.h:441
QCborValue concrete() const noexcept
Definition qcborvalue.h:394
QString toString(const QString &defaultValue={}) const
Definition qcborvalue.h:347
QUrl toUrl(const QUrl &defaultValue={}) const
Definition qcborvalue.h:352
QJsonValue toJsonValue() const
double toDouble(double defaultValue=0) const
Definition qcborvalue.h:342
\inmodule QtCore\reentrant
Definition qcborvalue.h:47
bool isUndefined() const
Returns true if this QCborValue is of the undefined type.
Definition qcborvalue.h:165
friend Qt::strong_ordering compareThreeWay(const QCborValue &lhs, const QCborValue &rhs) noexcept
Definition qcborvalue.h:254
bool isSimpleType() const
Returns true if this QCborValue is of one of the CBOR simple types.
Definition qcborvalue.h:174
bool isDateTime() const
Returns true if this QCborValue is of the date/time type.
Definition qcborvalue.h:167
bool isString() const
Returns true if this QCborValue is of the string type.
Definition qcborvalue.h:157
EncodingOption
This enum is used in the options argument to toCbor(), modifying the behavior of the encoder.
Definition qcborvalue.h:50
@ NoTransformation
Definition qcborvalue.h:58
bool isNull() const
Returns true if this QCborValue is of the null type.
Definition qcborvalue.h:164
QCborValue(QCborSimpleType st)
Creates a QCborValue of simple type st.
Definition qcborvalue.h:107
QCborValue(QCborKnownTags t_, const QCborValue &tv=QCborValue())
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qcborvalue.h:121
QCborValue(double v)
Creates a QCborValue with floating point value d.
Definition qcborvalue.h:106
QCborValue(QCborValue &&other) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qcborvalue.h:140
QCborValue(Type t_)
Creates a QCborValue of type t_.
Definition qcborvalue.h:98
bool isUrl() const
Returns true if this QCborValue is of the URL type.
Definition qcborvalue.h:168
bool isByteArray() const
Returns true if this QCborValue is of the byte array type.
Definition qcborvalue.h:156
qint64 toInteger(qint64 defaultValue=0) const
Returns the integer value stored in this QCborValue, if it is of the integer type.
Definition qcborvalue.h:187
Type
This enum represents the QCborValue type.
Definition qcborvalue.h:70
@ RegularExpression
Definition qcborvalue.h:90
~QCborValue()
Disposes of the current QCborValue object and frees any associated resources.
Definition qcborvalue.h:134
bool isBool() const
Returns true if this QCborValue is a boolean.
Definition qcborvalue.h:163
bool isRegularExpression() const
Returns true if this QCborValue contains a regular expression's pattern.
Definition qcborvalue.h:169
bool isDouble() const
Returns true if this QCborValue is of the floating-point type.
Definition qcborvalue.h:166
bool isContainer() const
This convenience function returns true if the QCborValue is either an array or a map.
Definition qcborvalue.h:172
QCborValue(int i)
Definition qcborvalue.h:102
bool isInvalid() const
Returns true if this QCborValue is not of any valid type.
Definition qcborvalue.h:171
QCborValue(bool b_)
Creates a QCborValue with boolean value b.
Definition qcborvalue.h:100
bool isInteger() const
Returns true if this QCborValue is of the integer type.
Definition qcborvalue.h:155
Type type() const
Returns the type of this QCborValue.
Definition qcborvalue.h:154
double toDouble(double defaultValue=0) const
Returns the floating point value stored in this QCborValue, if it is of the Double type.
Definition qcborvalue.h:191
QCborSimpleType toSimpleType(QCborSimpleType defaultValue=QCborSimpleType::Undefined) const
Returns the simple type this QCborValue is of, if it is a simple type.
Definition qcborvalue.h:182
bool isTag() const
Returns true if this QCborValue is of the tag type.
Definition qcborvalue.h:160
bool isArray() const
Returns true if this QCborValue is of the array type.
Definition qcborvalue.h:158
QCborValue(qint64 i)
Creates a QCborValue with integer value i.
Definition qcborvalue.h:105
bool isUuid() const
Returns true if this QCborValue contains a UUID.
Definition qcborvalue.h:170
QCborValue(std::nullptr_t)
Creates a QCborValue of the \l {Type}{Null} type.
Definition qcborvalue.h:99
QCborValue(const void *)=delete
bool isTrue() const
Returns true if this QCborValue is a boolean with true value.
Definition qcborvalue.h:162
bool isFalse() const
Returns true if this QCborValue is a boolean with false value.
Definition qcborvalue.h:161
bool isSimpleType(QCborSimpleType st) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qcborvalue.h:178
QT_ASCII_CAST_WARN QCborValue(const char *s)
Definition qcborvalue.h:114
bool isMap() const
Returns true if this QCborValue is of the map type.
Definition qcborvalue.h:159
DiagnosticNotationOption
This enum is used in the option argument to toDiagnosticNotation(), to modify the output format.
Definition qcborvalue.h:62
QCborValue taggedValue(const QCborValue &defaultValue=QCborValue()) const
Returns the tagged value of this extended QCborValue object, if it is of the tag type,...
QCborValue(unsigned u)
Definition qcborvalue.h:103
bool toBool(bool defaultValue=false) const
Returns the boolean value stored in this QCborValue, if it is of a boolean type.
Definition qcborvalue.h:189
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore\reentrant
Definition qdatetime.h:283
\inmodule QtCore
\inmodule QtCore\reentrant
Definition qjsonvalue.h:25
\inmodule QtCore \reentrant
QSharedData & operator=(const QSharedData &)=delete
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition quuid.h:31
\inmodule QtCore
Definition qvariant.h:65
\inmodule QtCore \title Classes and helpers for defining comparison operators \keyword qtcompare
Definition qcompare.h:400
QStyleOptionButton opt
Combined button and popup list for selecting options.
bool isNull(const T &t)
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
void toByteArray(QByteArray &)
Definition qctf_p.h:76
QCborKnownTags
Definition qcborcommon.h:31
QCborTag
Definition qcborcommon.h:30
QCborSimpleType
Definition qcborcommon.h:23
QT_WARNING_PUSH class QT6_ONLY(Q_CORE_EXPORT) QCborValueRef QT_WARNING_POP Q_CORE_EXPORT size_t qHash(const QCborValue &value, size_t seed=0)
Q_CORE_EXPORT QDebug operator<<(QDebug, const QCborValue &v)
Q_CORE_EXPORT QDataStream & operator>>(QDataStream &, QCborValue &)
class QT6_ONLY(Q_CORE_EXPORT) QChar
Definition qchar.h:44
#define Q_DECLARE_STRONGLY_ORDERED(...)
#define Q_DECL_PURE_FUNCTION
#define QT_WARNING_POP
#define QT_WARNING_DISABLE_MSVC(number)
#define QT_WARNING_PUSH
constexpr bool operator!=(const timespec &t1, const timespec &t2)
AudioChannelLayoutTag tag
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError * error
bool comparesEqual(const QDir &lhs, const QDir &rhs)
Definition qdir.cpp:1819
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
quint32 Tag
@ Invalid
GLsizei const GLfloat * v
[13]
const GLfloat * m
GLuint64 key
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
GLenum GLuint GLintptr offset
GLfloat n
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLdouble GLdouble t
Definition qopenglext.h:243
GLenum GLsizei len
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2)
constexpr void qt_ptr_swap(T *&lhs, T *&rhs) noexcept
Definition qswap.h:29
#define QT_ASCII_CAST_WARN
#define Q_ENUM(x)
#define Q_GADGET
static int compare(quint64 a, quint64 b)
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
unsigned char quint8
Definition qtypes.h:46
QList< std::pair< QString, QString > > Map
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, JSToQVariantConversionBehavior conversionBehavior, V4ObjectSet *visitedObjects)
static double toDouble(Value v)
QByteArray ba
[0]
QUrl url("example.com")
[constructor-url-reference]
QObject::connect nullptr
QVariant variant
[1]
QCborValue(QCborTag(2), QByteArray("\x01\0\0\0\0\0\0\0\0", 9))
[0]
value toMap().value(key)
[3]
value isSimpleType(QCborSimpleType(12))
[1]
p rx()++
QSharedPointer< T > other(t)
[5]
this swap(other)
char * toString(const MyType &t)
[31]
\inmodule QtCore \inheaderfile QtCborCommon \reentrant
Definition qcborcommon.h:63
QString toString() const
Returns a text string that matches the error code in this QCborError object.
\inmodule QtCore\reentrant
Definition qcborvalue.h:37
QString errorString() const
\variable QCborParserError::offset
Definition qcborvalue.h:41
QCborError error
Definition qcborvalue.h:39
Definition moc.h:23
QT_BEGIN_NAMESPACE bool toBool(const QString &str)
Definition utils.h:14