diff options
Diffstat (limited to 'src/corelib/serialization/qjsonobject.h')
-rw-r--r-- | src/corelib/serialization/qjsonobject.h | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/src/corelib/serialization/qjsonobject.h b/src/corelib/serialization/qjsonobject.h index 80fe6b2f3f..05463f6f36 100644 --- a/src/corelib/serialization/qjsonobject.h +++ b/src/corelib/serialization/qjsonobject.h @@ -42,10 +42,8 @@ #include <QtCore/qjsonvalue.h> #include <QtCore/qiterator.h> -#ifdef Q_COMPILER_INITIALIZER_LISTS #include <QtCore/qpair.h> #include <initializer_list> -#endif QT_BEGIN_NAMESPACE @@ -60,34 +58,32 @@ class Q_CORE_EXPORT QJsonObject public: QJsonObject(); -#if defined(Q_COMPILER_INITIALIZER_LISTS) || defined(Q_QDOC) QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args) { initialize(); for (std::initializer_list<QPair<QString, QJsonValue> >::const_iterator i = args.begin(); i != args.end(); ++i) insert(i->first, i->second); } -#endif ~QJsonObject(); QJsonObject(const QJsonObject &other); QJsonObject &operator =(const QJsonObject &other); - QJsonObject(QJsonObject &&other) Q_DECL_NOTHROW + QJsonObject(QJsonObject &&other) noexcept : d(other.d), o(other.o) { other.d = nullptr; other.o = nullptr; } - QJsonObject &operator =(QJsonObject &&other) Q_DECL_NOTHROW + QJsonObject &operator =(QJsonObject &&other) noexcept { swap(other); return *this; } - void swap(QJsonObject &other) Q_DECL_NOTHROW + void swap(QJsonObject &other) noexcept { qSwap(d, other.d); qSwap(o, other.o); @@ -104,16 +100,28 @@ public: inline int length() const { return size(); } bool isEmpty() const; +#if QT_STRINGVIEW_LEVEL < 2 QJsonValue value(const QString &key) const; - QJsonValue value(QLatin1String key) const; QJsonValue operator[] (const QString &key) const; - QJsonValue operator[] (QLatin1String key) const { return value(key); } QJsonValueRef operator[] (const QString &key); +#endif + QJsonValue value(QStringView key) const; + QJsonValue value(QLatin1String key) const; + QJsonValue operator[] (QStringView key) const { return value(key); } + QJsonValue operator[] (QLatin1String key) const { return value(key); } + QJsonValueRef operator[] (QStringView key); QJsonValueRef operator[] (QLatin1String key); +#if QT_STRINGVIEW_LEVEL < 2 void remove(const QString &key); QJsonValue take(const QString &key); bool contains(const QString &key) const; +#endif + void remove(QStringView key); + void remove(QLatin1String key); + QJsonValue take(QStringView key); + QJsonValue take(QLatin1String key); + bool contains(QStringView key) const; bool contains(QLatin1String key) const; bool operator==(const QJsonObject &other) const; @@ -222,13 +230,20 @@ public: // more Qt typedef iterator Iterator; typedef const_iterator ConstIterator; +#if QT_STRINGVIEW_LEVEL < 2 iterator find(const QString &key); - iterator find(QLatin1String key); const_iterator find(const QString &key) const { return constFind(key); } - const_iterator find(QLatin1String key) const { return constFind(key); } const_iterator constFind(const QString &key) const; - const_iterator constFind(QLatin1String key) const; iterator insert(const QString &key, const QJsonValue &value); +#endif + iterator find(QStringView key); + iterator find(QLatin1String key); + const_iterator find(QStringView key) const { return constFind(key); } + const_iterator find(QLatin1String key) const { return constFind(key); } + const_iterator constFind(QStringView key) const; + const_iterator constFind(QLatin1String key) const; + iterator insert(QStringView key, const QJsonValue &value); + iterator insert(QLatin1String key, const QJsonValue &value); // STL compatibility typedef QJsonValue mapped_type; @@ -251,10 +266,22 @@ private: void detach(uint reserve = 0); bool detach2(uint reserve = 0); void compact(); + void compactIfNeeded(); + + template <typename T> QJsonValue valueImpl(T key) const; + template <typename T> QJsonValueRef atImpl(T key); + template <typename T> void removeImpl(T key); + template <typename T> QJsonValue takeImpl(T key); + template <typename T> bool containsImpl(T key) const; + template <typename T> iterator findImpl(T key); + template <typename T> const_iterator constFindImpl(T key) const; + template <typename T> iterator insertImpl(T key, const QJsonValue &value); QString keyAt(int i) const; QJsonValue valueAt(int i) const; void setValueAt(int i, const QJsonValue &val); + void removeAt(int i); + template <typename T> iterator insertAt(int i, T key, const QJsonValue &val, bool exists); QJsonPrivate::Data *d; QJsonPrivate::Object *o; |