summaryrefslogtreecommitdiffstats
path: root/src/corelib/json/qjsonarray.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2017-02-22 11:49:24 +0000
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2017-04-19 04:50:26 +0000
commit8a375341cf7a7cf38ef427bc0c9f1abde05a471d (patch)
tree1b6d3d57b38756228dd5682cc3f0b8a3f7642949 /src/corelib/json/qjsonarray.h
parent6462f299ed188b3c3494d99d21e6563e37bd78e5 (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/qjsonarray.h')
-rw-r--r--src/corelib/json/qjsonarray.h22
1 files changed, 22 insertions, 0 deletions
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