Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-06 10:21:20

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:critical reason:data-parser
0004 
0005 #ifndef QJSONDOCUMENT_H
0006 #define QJSONDOCUMENT_H
0007 
0008 #include <QtCore/qcompare.h>
0009 #include <QtCore/qjsonparseerror.h>
0010 #if (QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)) || defined(QT_BOOTSTRAPPED)
0011 #include <QtCore/qjsonvalue.h>
0012 #endif
0013 #include <QtCore/qlatin1stringview.h>
0014 #include <QtCore/qscopedpointer.h>
0015 #include <QtCore/qstringview.h>
0016 
0017 #include <memory>
0018 
0019 QT_BEGIN_NAMESPACE
0020 
0021 class QDebug;
0022 class QCborValue;
0023 class QJsonArray;
0024 class QJsonObject;
0025 class QJsonValue;
0026 
0027 namespace QJsonPrivate { class Parser; }
0028 
0029 class QJsonDocumentPrivate;
0030 class Q_CORE_EXPORT QJsonDocument
0031 {
0032 public:
0033 #ifdef Q_LITTLE_ENDIAN
0034     static const uint BinaryFormatTag = ('q') | ('b' << 8) | ('j' << 16) | ('s' << 24);
0035 #else
0036     static const uint BinaryFormatTag = ('q' << 24) | ('b' << 16) | ('j' << 8) | ('s');
0037 #endif
0038 
0039     QJsonDocument();
0040     explicit QJsonDocument(const QJsonObject &object);
0041     explicit QJsonDocument(const QJsonArray &array);
0042     ~QJsonDocument();
0043 
0044     QJsonDocument(const QJsonDocument &other);
0045     QJsonDocument &operator =(const QJsonDocument &other);
0046 
0047     QJsonDocument(QJsonDocument &&other) noexcept;
0048 
0049     QJsonDocument &operator =(QJsonDocument &&other) noexcept
0050     {
0051         swap(other);
0052         return *this;
0053     }
0054 
0055     void swap(QJsonDocument &other) noexcept;
0056 
0057     static QJsonDocument fromVariant(const QVariant &variant);
0058     QVariant toVariant() const;
0059 
0060 #if (QT_VERSION < QT_VERSION_CHECK(7, 0, 0)) && !defined(QT_BOOTSTRAPPED)
0061     enum JsonFormat {
0062         Indented,
0063         Compact
0064     };
0065 #else
0066     using JsonFormat = QJsonValue::JsonFormat;
0067 #  ifdef __cpp_using_enum
0068     using enum QJsonValue::JsonFormat;
0069 #  else
0070     // keep in sync with qjsonvalue.h
0071     static constexpr auto Indented = JsonFormat::Indented;
0072     static constexpr auto Compact = JsonFormat::Compact;
0073 #  endif
0074 #endif
0075 
0076     static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = nullptr);
0077 
0078     QByteArray toJson(JsonFormat format = JsonFormat::Indented) const;
0079 
0080     bool isEmpty() const;
0081     bool isArray() const;
0082     bool isObject() const;
0083 
0084     QJsonObject object() const;
0085     QJsonArray array() const;
0086 
0087     void setObject(const QJsonObject &object);
0088     void setArray(const QJsonArray &array);
0089 
0090     const QJsonValue operator[](const QString &key) const;
0091     const QJsonValue operator[](QStringView key) const;
0092     const QJsonValue operator[](QLatin1StringView key) const;
0093     const QJsonValue operator[](qsizetype i) const;
0094 #if QT_CORE_REMOVED_SINCE(6, 8)
0095     bool operator==(const QJsonDocument &other) const;
0096     bool operator!=(const QJsonDocument &other) const { return !operator==(other); }
0097 #endif
0098     bool isNull() const;
0099 
0100 private:
0101     friend class QJsonValue;
0102     friend class QJsonPrivate::Parser;
0103     friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &);
0104     friend Q_CORE_EXPORT bool comparesEqual(const QJsonDocument &lhs,
0105                                             const QJsonDocument &rhs) noexcept;
0106     Q_DECLARE_EQUALITY_COMPARABLE(QJsonDocument)
0107 
0108     QJsonDocument(const QCborValue &data);
0109 
0110     std::unique_ptr<QJsonDocumentPrivate> d;
0111 };
0112 
0113 Q_DECLARE_SHARED(QJsonDocument)
0114 
0115 #if !defined(QT_NO_DEBUG_STREAM)
0116 Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &);
0117 #endif
0118 
0119 #ifndef QT_NO_DATASTREAM
0120 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QJsonDocument &);
0121 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QJsonDocument &);
0122 #endif
0123 
0124 QT_END_NAMESPACE
0125 
0126 #endif // QJSONDOCUMENT_H