diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2017-02-22 11:49:24 +0000 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2017-04-19 04:50:26 +0000 |
commit | 8a375341cf7a7cf38ef427bc0c9f1abde05a471d (patch) | |
tree | 1b6d3d57b38756228dd5682cc3f0b8a3f7642949 /src/corelib/json | |
parent | 6462f299ed188b3c3494d99d21e6563e37bd78e5 (diff) |
QJson*: value semantics cleanup
Re-add the move operations, add a swap(), mark as shared
(we're already using them in containers).
QJsonValue is slightly tricky, because it has an anonymous union,
which can't be easily moved in C++. Use the implementation of
the copy constructor as inspiration for the move.
[ChangeLog][QtCore][JSON] QJsonArray, QJsonDocument, QJsonObject
and QJsonValue now have move operations and a swap() member function.
Change-Id: Idfb94a93370ace96100efbd6559ef05b4c5adc39
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/json')
-rw-r--r-- | src/corelib/json/qjsonarray.cpp | 21 | ||||
-rw-r--r-- | src/corelib/json/qjsonarray.h | 22 | ||||
-rw-r--r-- | src/corelib/json/qjsondocument.cpp | 22 | ||||
-rw-r--r-- | src/corelib/json/qjsondocument.h | 19 | ||||
-rw-r--r-- | src/corelib/json/qjsonobject.cpp | 22 | ||||
-rw-r--r-- | src/corelib/json/qjsonobject.h | 21 | ||||
-rw-r--r-- | src/corelib/json/qjsonvalue.cpp | 21 | ||||
-rw-r--r-- | src/corelib/json/qjsonvalue.h | 25 |
8 files changed, 173 insertions, 0 deletions
diff --git a/src/corelib/json/qjsonarray.cpp b/src/corelib/json/qjsonarray.cpp index d4cc4b81df..c5a5aaf39d 100644 --- a/src/corelib/json/qjsonarray.cpp +++ b/src/corelib/json/qjsonarray.cpp @@ -212,6 +212,27 @@ QJsonArray &QJsonArray::operator =(const QJsonArray &other) return *this; } +/*! + \fn QJsonArray::QJsonArray(QJsonArray &&other) + \since 5.10 + + Move-constructs a QJsonArray from \a other. +*/ + +/*! + \fn QJsonArray &QJsonArray::operator =(QJsonArray &&other) + \since 5.10 + + Move-assigns \a other to this array. +*/ + +/*! + \fn void QJsonArray::swap(QJsonArray &other) + \since 5.10 + + Swaps the array \a other with this. This operation is very fast and never fails. +*/ + /*! \fn QJsonArray &QJsonArray::operator+=(const QJsonValue &value) Appends \a value to the array, and returns a reference to the array itself. diff --git a/src/corelib/json/qjsonarray.h b/src/corelib/json/qjsonarray.h index 3b6fa37cfa..ddba2ca78e 100644 --- a/src/corelib/json/qjsonarray.h +++ b/src/corelib/json/qjsonarray.h @@ -72,6 +72,20 @@ public: QJsonArray(const QJsonArray &other); QJsonArray &operator =(const QJsonArray &other); + QJsonArray(QJsonArray &&other) Q_DECL_NOTHROW + : d(other.d), + a(other.a) + { + other.d = nullptr; + other.a = nullptr; + } + + QJsonArray &operator =(QJsonArray &&other) Q_DECL_NOTHROW + { + swap(other); + return *this; + } + static QJsonArray fromStringList(const QStringList &list); static QJsonArray fromVariantList(const QVariantList &list); QVariantList toVariantList() const; @@ -101,6 +115,12 @@ public: bool operator==(const QJsonArray &other) const; bool operator!=(const QJsonArray &other) const; + void swap(QJsonArray &other) Q_DECL_NOTHROW + { + qSwap(d, other.d); + qSwap(a, other.a); + } + class const_iterator; class iterator { @@ -243,6 +263,8 @@ private: QJsonPrivate::Array *a; }; +Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QJsonArray) + #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonArray &); #endif diff --git a/src/corelib/json/qjsondocument.cpp b/src/corelib/json/qjsondocument.cpp index ed454d5442..d1169d90e3 100644 --- a/src/corelib/json/qjsondocument.cpp +++ b/src/corelib/json/qjsondocument.cpp @@ -153,6 +153,28 @@ QJsonDocument &QJsonDocument::operator =(const QJsonDocument &other) return *this; } +/*! + \fn QJsonDocument::QJsonDocument(QJsonDocument &&other) + \since 5.10 + + Move-constructs a QJsonDocument from \a other. +*/ + +/*! + \fn QJsonDocument &QJsonDocument::operator =(QJsonDocument &&other) + \since 5.10 + + Move-assigns \a other to this document. +*/ + +/*! + \fn void QJsonDocument::swap(QJsonDocument &other) + \since 5.10 + + Swaps the document \a other with this. This operation is very fast and never fails. +*/ + + /*! \enum QJsonDocument::DataValidation This value is used to tell QJsonDocument whether to validate the binary data diff --git a/src/corelib/json/qjsondocument.h b/src/corelib/json/qjsondocument.h index 19885a8d56..82f223709e 100644 --- a/src/corelib/json/qjsondocument.h +++ b/src/corelib/json/qjsondocument.h @@ -93,6 +93,23 @@ public: QJsonDocument(const QJsonDocument &other); QJsonDocument &operator =(const QJsonDocument &other); + QJsonDocument(QJsonDocument &&other) Q_DECL_NOTHROW + : d(other.d) + { + other.d = nullptr; + } + + QJsonDocument &operator =(QJsonDocument &&other) Q_DECL_NOTHROW + { + swap(other); + return *this; + } + + void swap(QJsonDocument &other) Q_DECL_NOTHROW + { + qSwap(d, other.d); + } + enum DataValidation { Validate, BypassValidation @@ -147,6 +164,8 @@ private: QJsonPrivate::Data *d; }; +Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QJsonDocument) + #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonDocument &); #endif diff --git a/src/corelib/json/qjsonobject.cpp b/src/corelib/json/qjsonobject.cpp index b5b6f36bc6..4a316c8a6f 100644 --- a/src/corelib/json/qjsonobject.cpp +++ b/src/corelib/json/qjsonobject.cpp @@ -194,6 +194,28 @@ QJsonObject &QJsonObject::operator =(const QJsonObject &other) } /*! + \fn QJsonObject::QJsonObject(QJsonObject &&other) + \since 5.10 + + Move-constructs a QJsonObject from \a other. +*/ + +/*! + \fn QJsonObject &QJsonObject::operator =(QJsonObject &&other) + \since 5.10 + + Move-assigns \a other to this object. +*/ + +/*! + \fn void QJsonObject::swap(QJsonObject &other) + \since 5.10 + + Swaps the object \a other with this. This operation is very fast and never fails. +*/ + + +/*! Converts the variant map \a map to a QJsonObject. The keys in \a map will be used as the keys in the JSON object, diff --git a/src/corelib/json/qjsonobject.h b/src/corelib/json/qjsonobject.h index e238c84d98..c77e2164a8 100644 --- a/src/corelib/json/qjsonobject.h +++ b/src/corelib/json/qjsonobject.h @@ -74,6 +74,25 @@ public: QJsonObject(const QJsonObject &other); QJsonObject &operator =(const QJsonObject &other); + QJsonObject(QJsonObject &&other) Q_DECL_NOTHROW + : d(other.d), o(other.o) + { + other.d = nullptr; + other.o = nullptr; + } + + QJsonObject &operator =(QJsonObject &&other) Q_DECL_NOTHROW + { + swap(other); + return *this; + } + + void swap(QJsonObject &other) Q_DECL_NOTHROW + { + qSwap(d, other.d); + qSwap(o, other.o); + } + static QJsonObject fromVariantMap(const QVariantMap &map); QVariantMap toVariantMap() const; static QJsonObject fromVariantHash(const QVariantHash &map); @@ -241,6 +260,8 @@ private: QJsonPrivate::Object *o; }; +Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QJsonObject) + #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonObject &); #endif diff --git a/src/corelib/json/qjsonvalue.cpp b/src/corelib/json/qjsonvalue.cpp index 4b52014db1..cd7c1c63fc 100644 --- a/src/corelib/json/qjsonvalue.cpp +++ b/src/corelib/json/qjsonvalue.cpp @@ -284,6 +284,27 @@ QJsonValue &QJsonValue::operator =(const QJsonValue &other) } /*! + \fn QJsonValue::QJsonValue(QJsonValue &&other) + \since 5.10 + + Move-constructs a QJsonValue from \a other. +*/ + +/*! + \fn QJsonValue &QJsonValue::operator =(QJsonValue &&other) + \since 5.10 + + Move-assigns \a other to this value. +*/ + +/*! + \fn void QJsonValue::swap(QJsonValue &other) + \since 5.10 + + Swaps the value \a other with this. This operation is very fast and never fails. +*/ + +/*! \fn bool QJsonValue::isNull() const Returns \c true if the value is null. diff --git a/src/corelib/json/qjsonvalue.h b/src/corelib/json/qjsonvalue.h index a853acaddd..96ccd34b6e 100644 --- a/src/corelib/json/qjsonvalue.h +++ b/src/corelib/json/qjsonvalue.h @@ -92,6 +92,29 @@ public: QJsonValue(const QJsonValue &other); QJsonValue &operator =(const QJsonValue &other); + QJsonValue(QJsonValue &&other) Q_DECL_NOTHROW + : ui(other.ui), + d(other.d), + t(other.t) + { + other.ui = 0; + other.d = nullptr; + other.t = Null; + } + + QJsonValue &operator =(QJsonValue &&other) Q_DECL_NOTHROW + { + swap(other); + return *this; + } + + void swap(QJsonValue &other) Q_DECL_NOTHROW + { + qSwap(ui, other.ui); + qSwap(d, other.d); + qSwap(t, other.t); + } + static QJsonValue fromVariant(const QVariant &variant); QVariant toVariant() const; @@ -217,6 +240,8 @@ public: }; #endif +Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QJsonValue) + #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonValue &); #endif |