Simplify creating QCFTypes from CFTypeRefs
Instead of forcing the user to cast: QCFType<CFFooRef> foo = (CFFooRef)CFFunctionReturningCFTypeRef()); We can do it for them, since we already know the expected type: auto foo = QCFType<CFFooRef>(CFFunctionReturningCFTypeRef)); Change-Id: I994d5d6530f220288b4bfd6ab16eae9f159ce3ef Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
191eb076a9
commit
f21ecb5657
@ -137,8 +137,10 @@ private:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class QCFType : public QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease>
|
class QCFType : public QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease>
|
||||||
{
|
{
|
||||||
|
using Base = QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease>;
|
||||||
public:
|
public:
|
||||||
using QAppleRefCounted<T, CFTypeRef, CFRetain, CFRelease>::QAppleRefCounted;
|
using Base::Base;
|
||||||
|
explicit QCFType(CFTypeRef r) : Base(static_cast<T>(r)) {}
|
||||||
template <typename X> X as() const { return reinterpret_cast<X>(this->value); }
|
template <typename X> X as() const { return reinterpret_cast<X>(this->value); }
|
||||||
static QCFType constructFromGet(const T &t)
|
static QCFType constructFromGet(const T &t)
|
||||||
{
|
{
|
||||||
@ -151,6 +153,7 @@ public:
|
|||||||
class Q_CORE_EXPORT QCFString : public QCFType<CFStringRef>
|
class Q_CORE_EXPORT QCFString : public QCFType<CFStringRef>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using QCFType<CFStringRef>::QCFType;
|
||||||
inline QCFString(const QString &str) : QCFType<CFStringRef>(0), string(str) {}
|
inline QCFString(const QString &str) : QCFType<CFStringRef>(0), string(str) {}
|
||||||
inline QCFString(const CFStringRef cfstr = 0) : QCFType<CFStringRef>(cfstr) {}
|
inline QCFString(const CFStringRef cfstr = 0) : QCFType<CFStringRef>(cfstr) {}
|
||||||
inline QCFString(const QCFType<CFStringRef> &other) : QCFType<CFStringRef>(other) {}
|
inline QCFString(const QCFType<CFStringRef> &other) : QCFType<CFStringRef>(other) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user