summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-04-12 21:40:02 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-04-26 19:56:07 +0000
commit1f27dc68717daf22ba5dab4634c60eda3eadab9c (patch)
treeed5735b16654cca51f75c2186fc3a459d953e9e3 /src/sql
parent204f1764ca6f4b670eaa87a775ded09a72a07aba (diff)
QSqlField: add move ctor & move operator
Add the move ctor and move operator for QSqlField Task-number: QTBUG-109938 Change-Id: Ib66eff76c3a920de9cfb3288f4219555005e7ae5 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/kernel/qsqlfield.cpp42
-rw-r--r--src/sql/kernel/qsqlfield.h12
2 files changed, 17 insertions, 37 deletions
diff --git a/src/sql/kernel/qsqlfield.cpp b/src/sql/kernel/qsqlfield.cpp
index c407137e7e..9fdb24f330 100644
--- a/src/sql/kernel/qsqlfield.cpp
+++ b/src/sql/kernel/qsqlfield.cpp
@@ -2,36 +2,20 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsqlfield.h"
-#include "qatomic.h"
#include "qdebug.h"
QT_BEGIN_NAMESPACE
-class QSqlFieldPrivate
+class QSqlFieldPrivate : public QSharedData
{
public:
QSqlFieldPrivate(const QString &name,
QMetaType type, const QString &tableName) :
- ref(1), nm(name), table(tableName), def(QVariant()), type(type),
+ nm(name), table(tableName), def(QVariant()), type(type),
req(QSqlField::Unknown), len(-1), prec(-1), tp(-1),
ro(false), gen(true), autoval(false)
{}
- QSqlFieldPrivate(const QSqlFieldPrivate &other)
- : ref(1),
- nm(other.nm),
- table(other.table),
- def(other.def),
- type(other.type),
- req(other.req),
- len(other.len),
- prec(other.prec),
- tp(other.tp),
- ro(other.ro),
- gen(other.gen),
- autoval(other.autoval)
- {}
-
bool operator==(const QSqlFieldPrivate& other) const
{
return (nm == other.nm
@@ -46,7 +30,6 @@ public:
&& autoval == other.autoval);
}
- QAtomicInt ref;
QString nm;
QString table;
QVariant def;
@@ -59,6 +42,7 @@ public:
bool gen: 1;
bool autoval: 1;
};
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QSqlFieldPrivate)
/*!
@@ -151,23 +135,14 @@ QSqlField::QSqlField(const QString &fieldName, QMetaType type, const QString &ta
*/
QSqlField::QSqlField(const QSqlField &other)
- : val(other.val),
- d(other.d)
-{
- d->ref.ref();
-}
+ = default;
/*!
Sets the field equal to \a other.
*/
QSqlField& QSqlField::operator=(const QSqlField& other)
-{
- qAtomicAssign(d, other.d);
- val = other.val;
- return *this;
-}
-
+ = default;
/*! \fn bool QSqlField::operator!=(const QSqlField &other) const
Returns \c true if the field is unequal to \a other; otherwise returns
@@ -189,10 +164,7 @@ bool QSqlField::operator==(const QSqlField& other) const
*/
QSqlField::~QSqlField()
-{
- if (!d->ref.deref())
- delete d;
-}
+ = default;
/*!
Sets the required status of this field to \a required.
@@ -426,7 +398,7 @@ bool QSqlField::isNull() const
*/
void QSqlField::detach()
{
- qAtomicDetach(d);
+ d.detach();
}
/*!
diff --git a/src/sql/kernel/qsqlfield.h b/src/sql/kernel/qsqlfield.h
index 67aed772bd..1b43d41485 100644
--- a/src/sql/kernel/qsqlfield.h
+++ b/src/sql/kernel/qsqlfield.h
@@ -5,6 +5,7 @@
#define QSQLFIELD_H
#include <QtSql/qtsqlglobal.h>
+#include <QtCore/qshareddata.h>
#include <QtCore/qvariant.h>
#include <QtCore/qstring.h>
@@ -12,6 +13,7 @@ QT_BEGIN_NAMESPACE
class QSqlFieldPrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QSqlFieldPrivate, Q_SQL_EXPORT)
class Q_SQL_EXPORT QSqlField
{
@@ -22,9 +24,14 @@ public:
QSqlField(const QSqlField& other);
QSqlField& operator=(const QSqlField& other);
+ QSqlField(QSqlField &&other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlField)
+ ~QSqlField();
+
+ void swap(QSqlField &other) noexcept { val.swap(other.val); d.swap(other.d); }
+
bool operator==(const QSqlField& other) const;
inline bool operator!=(const QSqlField &other) const { return !operator==(other); }
- ~QSqlField();
void setValue(const QVariant& value);
inline QVariant value() const
@@ -76,8 +83,9 @@ public:
private:
void detach();
+ // ### Qt7: move to private class
QVariant val;
- QSqlFieldPrivate* d;
+ QExplicitlySharedDataPointer<QSqlFieldPrivate> d;
};
#ifndef QT_NO_DEBUG_STREAM