Fix up QAppleRefCounted API
- Add proper move semantics. - Use better variable names. Change-Id: I9d13e4474414593a451d3ccf34c034cb7ab7f60d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
384f6ca96a
commit
0c4eb097ed
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user