Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qjsondocument.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:critical reason:data-parser
4
5#ifndef QJSONDOCUMENT_H
6#define QJSONDOCUMENT_H
7
8#include <QtCore/qcompare.h>
9#include <QtCore/qjsonparseerror.h>
10#if (QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)) || defined(QT_BOOTSTRAPPED)
11#include <QtCore/qjsonvalue.h>
12#endif
13#include <QtCore/qlatin1stringview.h>
14#include <QtCore/qscopedpointer.h>
15#include <QtCore/qstringview.h>
16
18
19class QDebug;
20class QCborValue;
21class QJsonArray;
22class QJsonObject;
23class QJsonValue;
24
25namespace QJsonPrivate { class Parser; }
26
28class Q_CORE_EXPORT QJsonDocument
29{
30public:
31#ifdef Q_LITTLE_ENDIAN
32 static const uint BinaryFormatTag = ('q') | ('b' << 8) | ('j' << 16) | ('s' << 24);
33#else
34 static const uint BinaryFormatTag = ('q' << 24) | ('b' << 16) | ('j' << 8) | ('s');
35#endif
36
37 QJsonDocument();
38 explicit QJsonDocument(const QJsonObject &object);
39 explicit QJsonDocument(QJsonObject &&object);
40 explicit QJsonDocument(const QJsonArray &array);
41 explicit QJsonDocument(QJsonArray &&array);
42 ~QJsonDocument();
43
44 QJsonDocument(const QJsonDocument &other);
45 QJsonDocument &operator =(const QJsonDocument &other);
46
47 QT_CORE_INLINE_SINCE(6, 12)
48 QJsonDocument(QJsonDocument &&other) noexcept;
49 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QJsonDocument)
50
51 QT_CORE_INLINE_SINCE(6, 12)
52 void swap(QJsonDocument &other) noexcept;
53
54 static QJsonDocument fromVariant(const QVariant &variant);
55 QVariant toVariant() const;
56
57#if (QT_VERSION < QT_VERSION_CHECK(7, 0, 0)) && !defined(QT_BOOTSTRAPPED)
58 enum JsonFormat {
59 Indented,
60 Compact
61 };
62#else
63 using JsonFormat = QJsonValue::JsonFormat;
64# ifdef __cpp_using_enum
65 using enum QJsonValue::JsonFormat;
66# else
67 // keep in sync with qjsonvalue.h
68 static constexpr auto Indented = JsonFormat::Indented;
69 static constexpr auto Compact = JsonFormat::Compact;
70# endif
71#endif
72
73 static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = nullptr);
74
75 QByteArray toJson(JsonFormat format = JsonFormat::Indented) const;
76
77 bool isEmpty() const;
78 bool isArray() const;
79 bool isObject() const;
80
81 QJsonObject object() const;
82 QJsonArray array() const;
83
84 void setObject(const QJsonObject &object);
85 void setArray(const QJsonArray &array);
86
87 const QJsonValue operator[](const QString &key) const;
88 const QJsonValue operator[](QStringView key) const;
89 const QJsonValue operator[](QLatin1StringView key) const;
90 const QJsonValue operator[](qsizetype i) const;
91#if QT_CORE_REMOVED_SINCE(6, 8)
92 bool operator==(const QJsonDocument &other) const;
93 bool operator!=(const QJsonDocument &other) const { return !operator==(other); }
94#endif
95 bool isNull() const;
96
97private:
98 friend class QJsonValue;
99 friend class QJsonPrivate::Parser;
100 friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &);
101 friend Q_CORE_EXPORT bool comparesEqual(const QJsonDocument &lhs,
102 const QJsonDocument &rhs) noexcept;
103 Q_DECLARE_EQUALITY_COMPARABLE(QJsonDocument)
104
105 inline explicit QJsonDocument(QCborValue data);
106
107 QJsonDocumentPrivate *d = nullptr;
108};
109
111
112#if QT_CORE_INLINE_IMPL_SINCE(6, 12)
113QJsonDocument::QJsonDocument(QJsonDocument &&other) noexcept
114 : d(std::exchange(other.d, nullptr))
115{
116}
117
118void QJsonDocument::swap(QJsonDocument &other) noexcept
119{
120 qt_ptr_swap(d, other.d);
121}
122#endif
123
124#if !defined(QT_NO_DEBUG_STREAM)
125Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &);
126#endif
127
128#ifndef QT_NO_DATASTREAM
129Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QJsonDocument &);
130Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QJsonDocument &);
131#endif
132
133QT_END_NAMESPACE
134
135#endif // QJSONDOCUMENT_H
\inmodule QtCore\reentrant
Definition qcborarray.h:21
\inmodule QtCore\reentrant
Definition qcbormap.h:35
bool isBool() const
Definition qcborvalue.h:323
QCborArray toArray(const QCborArray &a) const
Definition qcborarray.h:384
QCborMap toMap(const QCborMap &m) const
Definition qcbormap.h:495
QCborMap toMap() const
Definition qcbormap.h:490
QVariant toVariant() const
Definition qcborvalue.h:387
bool isInteger() const
Definition qcborvalue.h:315
bool isDateTime() const
Definition qcborvalue.h:327
bool isDouble() const
Definition qcborvalue.h:326
bool isString() const
Definition qcborvalue.h:317
QCborValueConstRef & operator=(const QCborValueConstRef &)=delete
bool isUrl() const
Definition qcborvalue.h:328
bool isNull() const
Definition qcborvalue.h:324
QCborArray toArray() const
Definition qcborarray.h:379
bool isContainer() const
Definition qcborvalue.h:332
bool toBool(bool defaultValue=false) const
Definition qcborvalue.h:348
QCborValue taggedValue(const QCborValue &defaultValue=QCborValue()) const
Definition qcborvalue.h:343
bool isByteArray() const
Definition qcborvalue.h:316
QCborSimpleType toSimpleType(QCborSimpleType defaultValue=QCborSimpleType::Undefined) const
Definition qcborvalue.h:336
bool isMap() const
Definition qcborvalue.h:319
bool isSimpleType() const
Definition qcborvalue.h:333
bool isRegularExpression() const
Definition qcborvalue.h:329
bool isUndefined() const
Definition qcborvalue.h:325
QCborValue::Type type() const
Definition qcborvalue.h:314
bool isInvalid() const
Definition qcborvalue.h:331
QCborValueConstRef(const QCborValueConstRef &)=default
bool isUuid() const
Definition qcborvalue.h:330
QCborTag tag(QCborTag defaultValue=QCborTag(-1)) const
Definition qcborvalue.h:341
constexpr QCborValueConstRef()
Definition qcborvalue.h:458
QByteArray toByteArray(const QByteArray &defaultValue={}) const
Definition qcborvalue.h:353
qint64 toInteger(qint64 defaultValue=0) const
Definition qcborvalue.h:346
bool isSimpleType(QCborSimpleType st) const
Definition qcborvalue.h:334
bool isTrue() const
Definition qcborvalue.h:322
QUuid toUuid(const QUuid &defaultValue={}) const
Definition qcborvalue.h:370
QCborContainerPrivate * d
Definition qcborvalue.h:462
bool isFalse() const
Definition qcborvalue.h:321
QAnyStringView toStringView(QAnyStringView defaultValue={}) const
Definition qcborvalue.h:357
friend bool comparesEqual(const QCborValueConstRef &lhs, const QCborValueConstRef &rhs) noexcept
Definition qcborvalue.h:415
bool isTag() const
Definition qcborvalue.h:320
friend bool comparesEqual(const QCborValueConstRef &lhs, const QCborValue &rhs) noexcept
Definition qcborvalue.h:431
QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt=QCborValue::Compact) const
Definition qcborvalue.h:397
bool isArray() const
Definition qcborvalue.h:318
int compare(const QCborValue &other) const
Definition qcborvalue.h:384
friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs, const QCborValue &rhs) noexcept
Definition qcborvalue.h:436
operator QCborValue() const
Definition qcborvalue.h:312
friend Qt::strong_ordering compareThreeWay(const QCborValueConstRef &lhs, const QCborValueConstRef &rhs) noexcept
Definition qcborvalue.h:420
constexpr QCborValueConstRef(QCborContainerPrivate *dd, qsizetype ii)
Definition qcborvalue.h:459
QCborValue concrete() const noexcept
Definition qcborvalue.h:406
QString toString(const QString &defaultValue={}) const
Definition qcborvalue.h:355
QUrl toUrl(const QUrl &defaultValue={}) const
Definition qcborvalue.h:364
QJsonValue toJsonValue() const
friend size_t qHash(const QCborValueConstRef &key, size_t seed=0) noexcept
Definition qcborvalue.h:408
double toDouble(double defaultValue=0) const
Definition qcborvalue.h:350
\inmodule QtCore\reentrant
Definition qcborvalue.h:48
\inmodule QtCore\reentrant
Definition qdatastream.h:50
\inmodule QtCore
Definition qhash.h:843
\inmodule QtCore\reentrant
Definition qjsonarray.h:19
\inmodule QtCore\reentrant
Definition qlist.h:81
void remove(int from, int to)
bool insertIfNotContains(Key k, const T &f)
bool contains(Key k) const
const T * function(Key k) const
\inmodule QtCore\reentrant
Definition qpoint.h:232
\inmodule QtCore\reentrant
Definition qpoint.h:30
LegacyRegisterOp legacyRegisterOp
Definition qmetatype.h:313
\keyword 16-bit Floating Point Support\inmodule QtCore \inheaderfile QFloat16
Definition qfloat16.h:57
Combined button and popup list for selecting options.
QMutableListIterator< QByteArray > QMutableByteArrayListIterator
QCborSimpleType
Definition qcborcommon.h:29
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
QList< QVariant > QVariantList
Definition qjsonarray.h:16
#define qCWarning(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
#define CONVERT_CBOR_AND_JSON(To)
#define NS(x)
Definition qmetatype.cpp:73
#define QMETATYPE_CONVERTER_ASSIGN_QCHAR(From)
#define QMETATYPE_CONVERTER_ASSIGN_DOUBLE(To, From)
#define INTEGRAL_CONVERTER(To)
static bool tryConvertBuiltinTypes(const void *from, int fromTypeId, void *to, int toTypeId)
#define QMETATYPE_CONVERTER_ASSIGN_NUMBER(To, From)
static bool qIntegerConversionFromFPHelper(From from, To *to)
#define FLOAT_CONVERTER(To)
#define QT_FOR_EACH_STATIC_CORE_POINTER(F)
Definition qmetatype.h:138
#define QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)
Definition qmetatype.h:71
#define QT_FOR_EACH_STATIC_PRIMITIVE_NON_VOID_TYPE(F)
Definition qmetatype.h:51
#define QT_FOR_EACH_STATIC_CORE_TEMPLATE(F)
Definition qmetatype.h:152
#define QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(F)
Definition qmetatype.h:75
#define QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TAG)
Definition qmetatype.h:1375
#define QT_FOR_EACH_STATIC_CORE_CLASS(F)
Definition qmetatype.h:106
#define QT_FOR_EACH_STATIC_ALIAS_TYPE(F)
Definition qmetatype.h:194
#define QT_FOR_EACH_STATIC_TYPE(F)
Definition qmetatype.h:224
#define QMETATYPE_CONVERTER(To, From, assign_and_return)
Definition qmetatype_p.h:24
#define QMETATYPE_CONVERTER_ASSIGN(To, From)
Definition qmetatype_p.h:35
#define QStringLiteral(str)
Definition qstring.h:1825
\inmodule QtCore\reentrant
Definition qcborvalue.h:38
QString errorString() const
\variable QCborParserError::offset
Definition qcborvalue.h:42
QCborError error
Definition qcborvalue.h:40
QListSpecialMethods & operator=(const QListSpecialMethods &)=default
QListSpecialMethods(QListSpecialMethods &&)=default
QListSpecialMethods & operator=(QListSpecialMethods &&)=default
QListSpecialMethods(const QListSpecialMethods &)=default
QByteArray join(QByteArrayView sep={}) const
static T value(const Iterator &it)
Definition qcbormap.h:27
static T value(Iterator &it)
Definition qcbormap.h:28
static QCborValueConstRef key(Iterator &it)
Definition qcbormap.h:26
static QCborValueConstRef key(const Iterator &it)
Definition qcbormap.h:25