From 32edd16e2bc4ae5a3503f9d8100f689cceea7590 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 23 May 2012 18:39:36 +0200 Subject: Merge QtSharedPointer::Basic into QtSharedPointer::ExternalRefCount The basic class existed for legacy only, when internal reference counting was a goal. Since it isn't anymore, we can remove the distinction and simply merge the two classes. Change-Id: Ib7a1c4158a8d71e71fa6afa447938b8b85ddae87 Reviewed-by: Lars Knoll Reviewed-by: Bradley T. Hughes --- src/corelib/tools/qsharedpointer_impl.h | 81 +++++++++++---------------------- 1 file changed, 27 insertions(+), 54 deletions(-) (limited to 'src/corelib/tools/qsharedpointer_impl.h') diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 942bbadcce..c5396dcc6e 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -122,49 +122,6 @@ namespace QtSharedPointer { template struct RemovePointer > { typedef T Type; }; template struct RemovePointer > { typedef T Type; }; - // This class provides the basic functionality of a pointer wrapper. - // Its existence is mostly legacy, since originally QSharedPointer - // could also be used for internally-refcounted objects. - template - class Basic - { - typedef T *Basic:: *RestrictedBool; - public: - typedef T Type; - typedef T element_type; - typedef T value_type; - typedef value_type *pointer; - typedef const value_type *const_pointer; - typedef value_type &reference; - typedef const value_type &const_reference; - typedef qptrdiff difference_type; - - inline T *data() const { return value; } - inline bool isNull() const { return !data(); } - inline operator RestrictedBool() const { return isNull() ? 0 : &Basic::value; } - inline bool operator !() const { return isNull(); } - inline T &operator*() const { return *data(); } - inline T *operator->() const { return data(); } - - protected: - inline Basic(T *ptr = 0) : value(ptr) { } - inline Basic(Qt::Initialization) { } - // ~Basic(); - - inline void internalConstruct(T *ptr) - { - value = ptr; - } - -#if defined(Q_NO_TEMPLATE_FRIENDS) - public: -#else - template friend class QT_PREPEND_NAMESPACE(QWeakPointer); -#endif - - Type *value; - }; - // This class is the d-pointer of QSharedPointer and QWeakPointer. // // It is a reference-counted reference counter. "strongref" is the inner @@ -315,11 +272,28 @@ namespace QtSharedPointer { // This is the main body of QSharedPointer. It implements the // external reference counting functionality. template - class ExternalRefCount: public Basic + class ExternalRefCount { - protected: + typedef T *ExternalRefCount:: *RestrictedBool; typedef ExternalRefCountData Data; + public: + typedef T Type; + typedef T element_type; + typedef T value_type; + typedef value_type *pointer; + typedef const value_type *const_pointer; + typedef value_type &reference; + typedef const value_type &const_reference; + typedef qptrdiff difference_type; + inline T *data() const { return value; } + inline bool isNull() const { return !data(); } + inline operator RestrictedBool() const { return isNull() ? 0 : &ExternalRefCount::value; } + inline bool operator !() const { return isNull(); } + inline T &operator*() const { return *data(); } + inline T *operator->() const { return data(); } + + protected: inline void deref() { deref(d); } static inline void deref(Data *d) @@ -344,31 +318,29 @@ namespace QtSharedPointer { inline void internalCreate() { - T *ptr; - d = ExternalRefCountWithContiguousData::create(&ptr); - Basic::internalConstruct(ptr); + d = ExternalRefCountWithContiguousData::create(&value); } inline void internalFinishConstruction(T *ptr) { - Basic::internalConstruct(ptr); + value = ptr; if (ptr) d->setQObjectShared(ptr, true); #ifdef QT_SHAREDPOINTER_TRACK_POINTERS if (ptr) internalSafetyCheckAdd(d, ptr); #endif } - inline ExternalRefCount() : d(0) { } - inline ExternalRefCount(Qt::Initialization i) : Basic(i) { } + inline ExternalRefCount() : value(0), d(0) { } + inline ExternalRefCount(Qt::Initialization) { } template - inline ExternalRefCount(T *ptr, Deleter deleter) : Basic(Qt::Uninitialized) // throws + inline ExternalRefCount(T *ptr, Deleter deleter) // throws { internalConstruct(ptr, deleter); } - inline ExternalRefCount(const ExternalRefCount &other) : Basic(other), d(other.d) + inline ExternalRefCount(const ExternalRefCount &other) : value(other.value), d(other.d) { if (d) ref(); } template - inline ExternalRefCount(const ExternalRefCount &other) : Basic(other.value), d(other.d) + inline ExternalRefCount(const ExternalRefCount &other) : value(other.value), d(other.d) { if (d) ref(); } inline ~ExternalRefCount() { deref(); } @@ -429,6 +401,7 @@ namespace QtSharedPointer { deref(o); } + Type *value; Data *d; }; } // namespace QtSharedPointer -- cgit v1.2.3