Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:26:32

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