123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 | // Copyright (C) 2016 The Qt Company Ltd.// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only#ifndef QJSONDOCUMENT_H#define QJSONDOCUMENT_H#include <QtCore/qcompare.h>#include <QtCore/qjsonparseerror.h>#if (QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)) || defined(QT_BOOTSTRAPPED)#include <QtCore/qjsonvalue.h>#endif#include <QtCore/qlatin1stringview.h>#include <QtCore/qscopedpointer.h>#include <QtCore/qstringview.h>#include <memory> QT_BEGIN_NAMESPACE class QDebug;class QCborValue;class QJsonArray;class QJsonObject;class QJsonValue;namespace QJsonPrivate {class Parser; }class QJsonDocumentPrivate;class Q_CORE_EXPORT QJsonDocument {public:#ifdef Q_LITTLE_ENDIANstatic const uint BinaryFormatTag = ('q') | ('b'<<8) | ('j'<<16) | ('s'<<24);#elsestatic const uint BinaryFormatTag = ('q'<<24) | ('b'<<16) | ('j'<<8) | ('s');#endifQJsonDocument();explicitQJsonDocument(const QJsonObject &object);explicitQJsonDocument(const QJsonArray &array);~QJsonDocument();QJsonDocument(const QJsonDocument &other); QJsonDocument &operator=(const QJsonDocument &other);QJsonDocument(QJsonDocument &&other) noexcept; QJsonDocument &operator=(QJsonDocument &&other) noexcept {swap(other);return*this;}voidswap(QJsonDocument &other) noexcept;static QJsonDocument fromVariant(const QVariant &variant); QVariant toVariant()const;#if (QT_VERSION < QT_VERSION_CHECK(7, 0, 0)) && !defined(QT_BOOTSTRAPPED)enum JsonFormat { Indented, Compact };#elseusing JsonFormat =QJsonValue::JsonFormat;# ifdef __cpp_using_enumusingenumQJsonValue::JsonFormat;# else// keep in sync with qjsonvalue.hstaticconstexpr auto Indented =JsonFormat::Indented;staticconstexpr auto Compact =JsonFormat::Compact;# endif#endifstatic QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error =nullptr); QByteArray toJson(JsonFormat format =JsonFormat::Indented)const;boolisEmpty()const;boolisArray()const;boolisObject()const; QJsonObject object()const; QJsonArray array()const;voidsetObject(const QJsonObject &object);voidsetArray(const QJsonArray &array);const QJsonValue operator[](const QString &key)const;const QJsonValue operator[](QStringView key)const;const QJsonValue operator[](QLatin1StringView key)const;const QJsonValue operator[](qsizetype i)const;#if QT_CORE_REMOVED_SINCE(6, 8)booloperator==(const QJsonDocument &other)const;booloperator!=(const QJsonDocument &other)const{return!operator==(other); }#endifboolisNull()const;private:friend class QJsonValue;friend class QJsonPrivate::Parser;friend Q_CORE_EXPORT QDebug operator<<(QDebug,const QJsonDocument &);friend Q_CORE_EXPORT boolcomparesEqual(const QJsonDocument &lhs,const QJsonDocument &rhs) noexcept;Q_DECLARE_EQUALITY_COMPARABLE(QJsonDocument)QJsonDocument(const QCborValue &data);std::unique_ptr<QJsonDocumentPrivate> d;};Q_DECLARE_SHARED(QJsonDocument)#if !defined(QT_NO_DEBUG_STREAM) Q_CORE_EXPORT QDebug operator<<(QDebug,const QJsonDocument &);#endif#ifndef QT_NO_DATASTREAM Q_CORE_EXPORT QDataStream &operator<<(QDataStream &,const QJsonDocument &); Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QJsonDocument &);#endif QT_END_NAMESPACE #endif// QJSONDOCUMENT_H
|