Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:26

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 QJSONARRAY_H
0005 #define QJSONARRAY_H
0006 
0007 #include <QtCore/qjsonvalue.h>
0008 #include <QtCore/qiterator.h>
0009 #include <QtCore/qshareddata.h>
0010 #include <initializer_list>
0011 
0012 QT_BEGIN_NAMESPACE
0013 
0014 class QDebug;
0015 typedef QList<QVariant> QVariantList;
0016 
0017 class Q_CORE_EXPORT QJsonArray
0018 {
0019 public:
0020     QJsonArray();
0021 
0022     QJsonArray(std::initializer_list<QJsonValue> args);
0023 
0024     ~QJsonArray();
0025 
0026     QJsonArray(const QJsonArray &other) noexcept;
0027     QJsonArray &operator =(const QJsonArray &other) noexcept;
0028 
0029     QJsonArray(QJsonArray &&other) noexcept;
0030 
0031     QJsonArray &operator =(QJsonArray &&other) noexcept
0032     {
0033         swap(other);
0034         return *this;
0035     }
0036 
0037     static QJsonArray fromStringList(const QStringList &list);
0038     static QJsonArray fromVariantList(const QVariantList &list);
0039     QVariantList toVariantList() const;
0040 
0041     qsizetype size() const;
0042     inline qsizetype count() const { return size(); }
0043 
0044     bool isEmpty() const;
0045     QJsonValue at(qsizetype i) const;
0046     QJsonValue first() const;
0047     QJsonValue last() const;
0048 
0049     void prepend(const QJsonValue &value);
0050     void append(const QJsonValue &value);
0051     void removeAt(qsizetype i);
0052     QJsonValue takeAt(qsizetype i);
0053     inline void removeFirst() { removeAt(0); }
0054     inline void removeLast() { removeAt(size() - 1); }
0055 
0056     void insert(qsizetype i, const QJsonValue &value);
0057     void replace(qsizetype i, const QJsonValue &value);
0058 
0059     bool contains(const QJsonValue &element) const;
0060     QJsonValueRef operator[](qsizetype i);
0061     QJsonValue operator[](qsizetype i) const;
0062 
0063     bool operator==(const QJsonArray &other) const;
0064     bool operator!=(const QJsonArray &other) const;
0065 
0066     void swap(QJsonArray &other) noexcept
0067     {
0068         a.swap(other.a);
0069     }
0070 
0071     class const_iterator;
0072 
0073     class iterator {
0074     public:
0075         typedef std::random_access_iterator_tag  iterator_category;
0076         typedef qsizetype difference_type;
0077         typedef QJsonValue value_type;
0078         typedef QJsonValueRef reference;
0079         typedef QJsonValueRef *pointer;
0080 
0081         inline iterator() : item(static_cast<QJsonArray *>(nullptr), 0) { }
0082         explicit inline iterator(QJsonArray *array, qsizetype index) : item(array, index) { }
0083 
0084         constexpr iterator(const iterator &other) = default;
0085         iterator &operator=(const iterator &other)
0086         {
0087             item.rebind(other.item);
0088             return *this;
0089         }
0090 
0091         inline QJsonValueRef operator*() const { return item; }
0092         inline const QJsonValueConstRef *operator->() const { return &item; }
0093         inline QJsonValueRef *operator->() { return &item; }
0094         inline QJsonValueRef operator[](qsizetype j) const { return *(*this + j); }
0095 
0096         inline bool operator==(const iterator &o) const
0097         { return item.d == o.item.d && item.index == o.item.index; }
0098         inline bool operator!=(const iterator &o) const { return !(*this == o); }
0099         inline bool operator<(const iterator &other) const
0100         { Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; }
0101         inline bool operator<=(const iterator &other) const
0102         { Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; }
0103         inline bool operator>(const iterator &other) const { return !(*this <= other); }
0104         inline bool operator>=(const iterator &other) const { return !(*this < other); }
0105         inline bool operator==(const const_iterator &o) const
0106         { return item.d == o.item.d && item.index == o.item.index; }
0107         inline bool operator!=(const const_iterator &o) const { return !(*this == o); }
0108         inline bool operator<(const const_iterator &other) const
0109         { Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; }
0110         inline bool operator<=(const const_iterator &other) const
0111         { Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; }
0112         inline bool operator>(const const_iterator &other) const { return !(*this <= other); }
0113         inline bool operator>=(const const_iterator &other) const { return !(*this < other); }
0114         inline iterator &operator++() { ++item.index; return *this; }
0115         inline iterator operator++(int) { iterator n = *this; ++item.index; return n; }
0116         inline iterator &operator--() { item.index--; return *this; }
0117         inline iterator operator--(int) { iterator n = *this; item.index--; return n; }
0118         inline iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
0119         inline iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
0120         inline iterator operator+(qsizetype j) const { iterator r = *this; return r += j; }
0121         inline iterator operator-(qsizetype j) const { return operator+(-j); }
0122         inline qsizetype operator-(iterator j) const { return item.index - j.item.index; }
0123 
0124     private:
0125         QJsonValueRef item;
0126         friend class QJsonArray;
0127     };
0128     friend class iterator;
0129 
0130     class const_iterator {
0131     public:
0132         typedef std::random_access_iterator_tag  iterator_category;
0133         typedef qptrdiff difference_type;
0134         typedef QJsonValue value_type;
0135         typedef const QJsonValueRef reference;
0136         typedef const QJsonValueRef *pointer;
0137 
0138         inline const_iterator() : item(static_cast<QJsonArray *>(nullptr), 0) { }
0139         explicit inline const_iterator(const QJsonArray *array, qsizetype index)
0140             : item(const_cast<QJsonArray *>(array), index) { }
0141         inline const_iterator(const iterator &o) : item(o.item) { }
0142 
0143         constexpr const_iterator(const const_iterator &other) = default;
0144         const_iterator &operator=(const const_iterator &other)
0145         {
0146             item.rebind(other.item);
0147             return *this;
0148         }
0149 
0150         inline const QJsonValueConstRef operator*() const { return item; }
0151         inline const QJsonValueConstRef *operator->() const { return &item; }
0152 
0153         inline QJsonValueConstRef operator[](qsizetype j) const { return *(*this + j); }
0154         inline bool operator==(const const_iterator &o) const
0155         { return item.d == o.item.d && item.index == o.item.index; }
0156         inline bool operator!=(const const_iterator &o) const { return !(*this == o); }
0157         inline bool operator<(const const_iterator &other) const
0158         { Q_ASSERT(item.d == other.item.d); return item.index < other.item.index; }
0159         inline bool operator<=(const const_iterator &other) const
0160         { Q_ASSERT(item.d == other.item.d); return item.index <= other.item.index; }
0161         inline bool operator>(const const_iterator &other) const { return !(*this <= other); }
0162         inline bool operator>=(const const_iterator &other) const { return !(*this < other); }
0163         inline const_iterator &operator++() { ++item.index; return *this; }
0164         inline const_iterator operator++(int) { const_iterator n = *this; ++item.index; return n; }
0165         inline const_iterator &operator--() { item.index--; return *this; }
0166         inline const_iterator operator--(int) { const_iterator n = *this; item.index--; return n; }
0167         inline const_iterator &operator+=(qsizetype j) { item.index += quint64(j); return *this; }
0168         inline const_iterator &operator-=(qsizetype j) { item.index -= quint64(j); return *this; }
0169         inline const_iterator operator+(qsizetype j) const { const_iterator r = *this; return r += j; }
0170         inline const_iterator operator-(qsizetype j) const { return operator+(-j); }
0171         inline qsizetype operator-(const_iterator j) const { return item.index - j.item.index; }
0172 
0173     private:
0174         QJsonValueConstRef item;
0175         friend class QJsonArray;
0176     };
0177     friend class const_iterator;
0178 
0179     // stl style
0180     inline iterator begin() { detach(); return iterator(this, 0); }
0181     inline const_iterator begin() const { return const_iterator(this, 0); }
0182     inline const_iterator constBegin() const { return const_iterator(this, 0); }
0183     inline const_iterator cbegin() const { return const_iterator(this, 0); }
0184     inline iterator end() { detach(); return iterator(this, size()); }
0185     inline const_iterator end() const { return const_iterator(this, size()); }
0186     inline const_iterator constEnd() const { return const_iterator(this, size()); }
0187     inline const_iterator cend() const { return const_iterator(this, size()); }
0188     iterator insert(iterator before, const QJsonValue &value)
0189     { insert(before.item.index, value); return before; }
0190     iterator erase(iterator it)
0191     { removeAt(it.item.index); return it; }
0192 
0193     // more Qt
0194     typedef iterator Iterator;
0195     typedef const_iterator ConstIterator;
0196 
0197     // convenience
0198     inline QJsonArray operator+(const QJsonValue &v) const
0199     { QJsonArray n = *this; n += v; return n; }
0200     inline QJsonArray &operator+=(const QJsonValue &v)
0201     { append(v); return *this; }
0202     inline QJsonArray &operator<< (const QJsonValue &v)
0203     { append(v); return *this; }
0204 
0205     // stl compatibility
0206     inline void push_back(const QJsonValue &t) { append(t); }
0207     inline void push_front(const QJsonValue &t) { prepend(t); }
0208     inline void pop_front() { removeFirst(); }
0209     inline void pop_back() { removeLast(); }
0210     inline bool empty() const { return isEmpty(); }
0211     typedef qsizetype size_type;
0212     typedef QJsonValue value_type;
0213     typedef value_type *pointer;
0214     typedef const value_type *const_pointer;
0215     typedef QJsonValueRef reference;
0216     typedef QJsonValue const_reference;
0217     typedef qsizetype difference_type;
0218 
0219 private:
0220     friend class QJsonValue;
0221     friend class QJsonValueConstRef;
0222     friend class QJsonValueRef;
0223     friend class QJsonPrivate::Value;
0224     friend class QJsonDocument;
0225     friend class QCborArray;
0226     friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonArray &);
0227 
0228     QJsonArray(QCborContainerPrivate *array);
0229     bool detach(qsizetype reserve = 0);
0230 
0231     QExplicitlySharedDataPointer<QCborContainerPrivate> a;
0232 };
0233 
0234 Q_DECLARE_SHARED(QJsonArray)
0235 
0236 #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED)
0237 inline QJsonValueConstRef::QJsonValueConstRef(QJsonArray *a, qsizetype idx)
0238     : d(a ? a->a.data() : nullptr), is_object(false), index(idx)
0239 {}
0240 #endif
0241 
0242 Q_CORE_EXPORT size_t qHash(const QJsonArray &array, size_t seed = 0);
0243 
0244 #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)
0245 Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonArray &);
0246 #endif
0247 
0248 #ifndef QT_NO_DATASTREAM
0249 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QJsonArray &);
0250 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QJsonArray &);
0251 #endif
0252 
0253 QT_END_NAMESPACE
0254 
0255 #endif // QJSONARRAY_H