summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@qt.io>2016-06-21 12:59:41 -0700
committerJake Petroules <jake.petroules@qt.io>2017-04-01 15:19:11 +0000
commit0c4eb097eda5301b64f6a12d5219bc9d2c43ab1d (patch)
treeca81fdecc634d66cbfac49d8b8642b1c62e4a4c4 /src
parent384f6ca96a0a969c910f9ea1f556aa4235354244 (diff)
Fix up QAppleRefCounted API
- Add proper move semantics. - Use better variable names. Change-Id: I9d13e4474414593a451d3ccf34c034cb7ab7f60d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qcore_mac.cpp10
-rw-r--r--src/corelib/kernel/qcore_mac_p.h31
2 files changed, 19 insertions, 22 deletions
diff --git a/src/corelib/kernel/qcore_mac.cpp b/src/corelib/kernel/qcore_mac.cpp
index c689f47d8f..bfb3b2ff07 100644
--- a/src/corelib/kernel/qcore_mac.cpp
+++ b/src/corelib/kernel/qcore_mac.cpp
@@ -45,16 +45,16 @@ QT_BEGIN_NAMESPACE
QCFString::operator QString() const
{
- if (string.isEmpty() && type)
- const_cast<QCFString*>(this)->string = QString::fromCFString(type);
+ if (string.isEmpty() && value)
+ const_cast<QCFString*>(this)->string = QString::fromCFString(value);
return string;
}
QCFString::operator CFStringRef() const
{
- if (!type)
- const_cast<QCFString*>(this)->type = string.toCFString();
- return type;
+ if (!value)
+ const_cast<QCFString*>(this)->value = string.toCFString();
+ return value;
}
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index 881212a224..c2c5a519aa 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -80,23 +80,20 @@ template <typename T, typename U, U (*RetainFunction)(U), void (*ReleaseFunction
class QAppleRefCounted
{
public:
- QAppleRefCounted(const T &t = T()) : type(t) {}
- QAppleRefCounted(const QAppleRefCounted &helper) : type(helper.type) { if (type) RetainFunction(type); }
- ~QAppleRefCounted() { if (type) ReleaseFunction(type); }
- operator T() { return type; }
- QAppleRefCounted &operator=(const QAppleRefCounted &helper)
- {
- if (helper.type)
- RetainFunction(helper.type);
- T type2 = type;
- type = helper.type;
- if (type2)
- ReleaseFunction(type2);
- return *this;
- }
- T *operator&() { return &type; }
+ QAppleRefCounted(const T &t = T()) : value(t) {}
+ QAppleRefCounted(QAppleRefCounted &&other) : value(other.value) { other.value = T(); }
+ QAppleRefCounted(const QAppleRefCounted &other) : value(other.value) { if (value) RetainFunction(value); }
+ ~QAppleRefCounted() { if (value) ReleaseFunction(value); }
+ operator T() { return value; }
+ void swap(QAppleRefCounted &other) Q_DECL_NOEXCEPT_EXPR(noexcept(qSwap(value, other.value)))
+ { qSwap(value, other.value); }
+ QAppleRefCounted &operator=(const QAppleRefCounted &other)
+ { QAppleRefCounted copy(other); swap(copy); return *this; }
+ QAppleRefCounted &operator=(QAppleRefCounted &&other)
+ { QAppleRefCounted moved(std::move(other)); swap(moved); return *this; }
+ T *operator&() { return &value; }
protected:
- T type;
+ T value;
};
/*
@@ -116,7 +113,7 @@ class QCFType : public QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease>
{
public:
using QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease>::QAppleRefCounted;
- template <typename X> X as() const { return reinterpret_cast<X>(this->type); }
+ template <typename X> X as() const { return reinterpret_cast<X>(this->value); }
static QCFType constructFromGet(const T &t)
{
CFRetain(t);