Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/qjsonobject.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 QJSONOBJECT_H
0005 #define QJSONOBJECT_H
0006 
0007 #include <QtCore/qjsonvalue.h>
0008 #include <QtCore/qiterator.h>
0009 #include <QtCore/qpair.h>
0010 #include <QtCore/qshareddata.h>
0011 #include <initializer_list>
0012 
0013 QT_BEGIN_NAMESPACE
0014 
0015 class QDebug;
0016 
0017 class QCborContainerPrivate;
0018 
0019 class Q_CORE_EXPORT QJsonObject
0020 {
0021 public:
0022     QJsonObject();
0023 
0024     QJsonObject(std::initializer_list<std::pair<QString, QJsonValue> > args);
0025 
0026     ~QJsonObject();
0027 
0028     QJsonObject(const QJsonObject &other) noexcept;
0029     QJsonObject &operator =(const QJsonObject &other) noexcept;
0030 
0031     QJsonObject(QJsonObject &&other) noexcept;
0032 
0033     QJsonObject &operator =(QJsonObject &&other) noexcept
0034     {
0035         swap(other);
0036         return *this;
0037     }
0038 
0039     void swap(QJsonObject &other) noexcept
0040     {
0041         o.swap(other.o);
0042     }
0043 
0044     static QJsonObject fromVariantMap(const QVariantMap &map);
0045     QVariantMap toVariantMap() const;
0046     static QJsonObject fromVariantHash(const QVariantHash &map);
0047     QVariantHash toVariantHash() const;
0048 
0049     QStringList keys() const;
0050     qsizetype size() const;
0051     inline qsizetype count() const { return size(); }
0052     inline qsizetype length() const { return size(); }
0053     bool isEmpty() const;
0054 
0055     QJsonValue value(const QString &key) const;
0056     QJsonValue operator[] (const QString &key) const;
0057     QJsonValueRef operator[] (const QString &key);
0058     QJsonValue value(QStringView key) const;
0059     QJsonValue value(QLatin1StringView key) const;
0060     QJsonValue operator[] (QStringView key) const { return value(key); }
0061     QJsonValue operator[] (QLatin1StringView key) const { return value(key); }
0062     QJsonValueRef operator[] (QStringView key);
0063     QJsonValueRef operator[] (QLatin1StringView key);
0064 
0065     void remove(const QString &key);
0066     QJsonValue take(const QString &key);
0067     bool contains(const QString &key) const;
0068     void remove(QStringView key);
0069     void remove(QLatin1StringView key);
0070     QJsonValue take(QStringView key);
0071     QJsonValue take(QLatin1StringView key);
0072     bool contains(QStringView key) const;
0073     bool contains(QLatin1StringView key) const;
0074 
0075     bool operator==(const QJsonObject &other) const;
0076     bool operator!=(const QJsonObject &other) const;
0077 
0078     class const_iterator;
0079 
0080     class iterator
0081     {
0082         friend class const_iterator;
0083         friend class QJsonObject;
0084         QJsonValueRef item;
0085 
0086     public:
0087         typedef std::random_access_iterator_tag iterator_category;
0088         typedef qsizetype difference_type;
0089         typedef QJsonValue value_type;
0090         typedef QJsonValueRef reference;
0091         typedef QJsonValueRef *pointer;
0092 
0093         inline iterator() : item(static_cast<QJsonObject*>(nullptr), 0) { }
0094         inline iterator(QJsonObject *obj, qsizetype index) : item(obj, index) { }
0095 
0096         constexpr iterator(const iterator &other) = default;
0097         iterator &operator=(const iterator &other)
0098         {
0099             item.rebind(other.item);
0100             return *this;
0101         }
0102 
0103         inline QString key() const { return item.objectKey(); }
0104         inline QJsonValueRef value() const { return item; }
0105         inline QJsonValueRef operator*() const { return item; }
0106         inline const QJsonValueConstRef *operator->() const { return &item; }
0107         inline QJsonValueRef *operator->() { return &item; }
0108         inline QJsonValueRef operator[](qsizetype j) const { return *(*this + j); }
0109 
0110         inline bool operator==(const iterator &other) const
0111         { return item.d == other.item.d && item.index == other.item.index; }
0112         inline bool operator!=(const iterator &other) const { return !(*this == other); }
0113         bool operator<(const iterator& other) const
0114         { Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; }
0115         bool operator<=(const iterator& other) const
0116         { Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; }
0117         bool operator>(const iterator& other) const { return !(*this <= other); }
0118         bool operator>=(const iterator& other) const { return !(*this < other); }
0119 
0120         inline iterator &operator++() { ++item.index; return *this; }
0121         inline iterator operator++(int) { iterator r = *this; ++item.index; return r; }
0122         inline iterator &operator--() { --item.index; return *this; }
0123         inline iterator operator--(int) { iterator r = *this; --item.index; return r; }
0124         inline iterator operator+(qsizetype j) const { iterator r = *this; return r += j; }
0125         inline iterator operator-(qsizetype j) const { return operator+(-j); }
0126         inline iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
0127         inline iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
0128         qsizetype operator-(iterator j) const { return item.index - j.item.index; }
0129 
0130     public:
0131         inline bool operator==(const const_iterator &other) const
0132         { return item.d == other.item.d && item.index == other.item.index; }
0133         inline bool operator!=(const const_iterator &other) const { return !(*this == other); }
0134         bool operator<(const const_iterator& other) const
0135         { Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; }
0136         bool operator<=(const const_iterator& other) const
0137         { Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; }
0138         bool operator>(const const_iterator& other) const { return !(*this <= other); }
0139         bool operator>=(const const_iterator& other) const { return !(*this < other); }
0140     };
0141     friend class iterator;
0142 
0143     class const_iterator
0144     {
0145         friend class iterator;
0146         QJsonValueConstRef item;
0147 
0148     public:
0149         typedef std::random_access_iterator_tag iterator_category;
0150         typedef qsizetype difference_type;
0151         typedef QJsonValue value_type;
0152         typedef const QJsonValueConstRef reference;
0153         typedef const QJsonValueConstRef *pointer;
0154 
0155         inline const_iterator() : item(static_cast<QJsonObject*>(nullptr), 0) { }
0156         inline const_iterator(const QJsonObject *obj, qsizetype index)
0157             : item(const_cast<QJsonObject*>(obj), index) { }
0158         inline const_iterator(const iterator &other)
0159             : item(other.item) { }
0160 
0161         constexpr const_iterator(const const_iterator &other) = default;
0162         const_iterator &operator=(const const_iterator &other)
0163         {
0164             item.rebind(other.item);
0165             return *this;
0166         }
0167 
0168         inline QString key() const { return item.objectKey(); }
0169         inline QJsonValueConstRef value() const { return item; }
0170         inline const QJsonValueConstRef operator*() const { return item; }
0171         inline const QJsonValueConstRef *operator->() const { return &item; }
0172         inline QJsonValueConstRef operator[](qsizetype j) const { return *(*this + j); }
0173 
0174         inline bool operator==(const const_iterator &other) const
0175         { return item.d == other.item.d && item.index == other.item.index; }
0176         inline bool operator!=(const const_iterator &other) const { return !(*this == other); }
0177         bool operator<(const const_iterator& other) const
0178         { Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; }
0179         bool operator<=(const const_iterator& other) const
0180         { Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; }
0181         bool operator>(const const_iterator& other) const { return !(*this <= other); }
0182         bool operator>=(const const_iterator& other) const { return !(*this < other); }
0183 
0184         inline const_iterator &operator++() { ++item.index; return *this; }
0185         inline const_iterator operator++(int) { const_iterator r = *this; ++item.index; return r; }
0186         inline const_iterator &operator--() { --item.index; return *this; }
0187         inline const_iterator operator--(int) { const_iterator r = *this; --item.index; return r; }
0188         inline const_iterator operator+(qsizetype j) const { const_iterator r = *this; return r += j; }
0189         inline const_iterator operator-(qsizetype j) const { return operator+(-j); }
0190         inline const_iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
0191         inline const_iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
0192         qsizetype operator-(const_iterator j) const { return item.index - j.item.index; }
0193 
0194         inline bool operator==(const iterator &other) const
0195         { return item.d == other.item.d && item.index == other.item.index; }
0196         inline bool operator!=(const iterator &other) const { return !(*this == other); }
0197         bool operator<(const iterator& other) const
0198         { Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; }
0199         bool operator<=(const iterator& other) const
0200         { Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; }
0201         bool operator>(const iterator& other) const { return !(*this <= other); }
0202         bool operator>=(const iterator& other) const { return !(*this < other); }
0203     };
0204     friend class const_iterator;
0205 
0206     // STL style
0207     inline iterator begin() { detach(); return iterator(this, 0); }
0208     inline const_iterator begin() const { return const_iterator(this, 0); }
0209     inline const_iterator constBegin() const { return const_iterator(this, 0); }
0210     inline iterator end() { detach(); return iterator(this, size()); }
0211     inline const_iterator end() const { return const_iterator(this, size()); }
0212     inline const_iterator constEnd() const { return const_iterator(this, size()); }
0213     iterator erase(iterator it);
0214 
0215     // more Qt
0216     typedef iterator Iterator;
0217     typedef const_iterator ConstIterator;
0218     iterator find(const QString &key);
0219     const_iterator find(const QString &key) const { return constFind(key); }
0220     const_iterator constFind(const QString &key) const;
0221     iterator insert(const QString &key, const QJsonValue &value);
0222     iterator find(QStringView key);
0223     iterator find(QLatin1StringView key);
0224     const_iterator find(QStringView key) const { return constFind(key); }
0225     const_iterator find(QLatin1StringView key) const { return constFind(key); }
0226     const_iterator constFind(QStringView key) const;
0227     const_iterator constFind(QLatin1StringView key) const;
0228     iterator insert(QStringView key, const QJsonValue &value);
0229     iterator insert(QLatin1StringView key, const QJsonValue &value);
0230 
0231     // STL compatibility
0232     typedef QJsonValue mapped_type;
0233     typedef QString key_type;
0234     typedef qsizetype size_type;
0235 
0236     inline bool empty() const { return isEmpty(); }
0237 
0238 private:
0239     friend class QJsonValue;
0240     friend class QJsonDocument;
0241     friend class QJsonPrivate::Value;
0242     friend class QJsonValueConstRef;
0243     friend class QJsonValueRef;
0244     friend class QCborMap;
0245     friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonObject &);
0246 
0247     QJsonObject(QCborContainerPrivate *object);
0248     bool detach(qsizetype reserve = 0);
0249 
0250     template <typename T> QJsonValue valueImpl(T key) const;
0251     template <typename T> QJsonValueRef atImpl(T key);
0252     template <typename T> void removeImpl(T key);
0253     template <typename T> QJsonValue takeImpl(T key);
0254     template <typename T> bool containsImpl(T key) const;
0255     template <typename T> iterator findImpl(T key);
0256     template <typename T> const_iterator constFindImpl(T key) const;
0257     template <typename T> iterator insertImpl(T key, const QJsonValue &value);
0258 
0259 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
0260     QString keyAt(qsizetype i) const;
0261     QJsonValue valueAt(qsizetype i) const;
0262     void setValueAt(qsizetype i, const QJsonValue &val);
0263 #endif
0264     void removeAt(qsizetype i);
0265     template <typename T> iterator insertAt(qsizetype i, T key, const QJsonValue &val, bool exists);
0266 
0267     QExplicitlySharedDataPointer<QCborContainerPrivate> o;
0268 };
0269 
0270 Q_DECLARE_SHARED(QJsonObject)
0271 
0272 #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED)
0273 inline QJsonValueConstRef::QJsonValueConstRef(QJsonObject *o, qsizetype idx)
0274     : d(o ? o->o.data() : nullptr), is_object(true), index(idx)
0275 {}
0276 #endif
0277 
0278 Q_CORE_EXPORT size_t qHash(const QJsonObject &object, size_t seed = 0);
0279 
0280 #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)
0281 Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonObject &);
0282 #endif
0283 
0284 #ifndef QT_NO_DATASTREAM
0285 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QJsonObject &);
0286 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QJsonObject &);
0287 #endif
0288 
0289 QT_END_NAMESPACE
0290 
0291 #endif // QJSONOBJECT_H