summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-03-06 12:11:25 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-22 17:45:47 +0100
commit3f7741fbe7ab4140f8f971c0cf88bb04e7feea6b (patch)
treeb5457b93c6ff142032cc5cc819a6c2e67baa887f /src
parent6a54344e223b23f3334409930b7a072d257dd947 (diff)
QPointer: some optimisations
Implement QPointer in terms of QPointerBase, a non-template roughly the same as QPointer<QObject>, to reduce the amount of template code being generated. Also mark QPointer as movable, fake an isNull() for qdoc, and remove qpointer.h's content from QT_NO_QOBJECT builds (some indirect include hits the missing QWeakPointer(QObject*) constructor when bootstrapping; worked before b/c QPointer is a template; QPointerBase isn't, though). Change-Id: I657826601f570f954d80b84bb0334dd3a7452859 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qpointer.h58
1 files changed, 40 insertions, 18 deletions
diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h
index 836c13e3fc..a3035ebc94 100644
--- a/src/corelib/kernel/qpointer.h
+++ b/src/corelib/kernel/qpointer.h
@@ -44,40 +44,60 @@
#include <QtCore/qsharedpointer.h>
+#ifndef QT_NO_QOBJECT
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-template <class T>
-class QPointer
+class QPointerBase
{
- QWeakPointer<T> wp;
+ QWeakPointer<QObject> wp;
-public:
- inline QPointer() : wp() { }
- inline QPointer(T *p) : wp(p) { }
- inline QPointer(const QPointer<T> &p) : wp(p.wp) { }
- inline ~QPointer() { }
+protected:
+ inline QPointerBase() : wp() { }
+ inline QPointerBase(QObject *p) : wp(p) { }
+ // compiler-generated copy/move ctor/assignment operators are fine! (even though public)
+ inline ~QPointerBase() { }
- inline QPointer<T> &operator=(const QPointer<T> &p)
- { wp = p.wp; return *this; }
- inline QPointer<T> &operator=(T* p)
- { wp = p; return *this; }
+ inline QObject* data() const
+ { return wp.data(); }
+
+ inline void assign(QObject *p)
+ { wp = p; }
inline bool isNull() const
{ return wp.isNull(); }
+};
+
+template <class T>
+class QPointer : private QPointerBase
+{
+public:
+ inline QPointer() { }
+ inline QPointer(T *p) : QPointerBase(p) { }
+ // compiler-generated copy/move ctor/assignment operators are fine!
+ inline ~QPointer() { }
+
+ inline QPointer<T> &operator=(T* p)
+ { QPointerBase::assign(p); return *this; }
+ inline T* data() const
+ { return static_cast<T*>(QPointerBase::data()); }
inline T* operator->() const
- { return wp.data(); }
+ { return data(); }
inline T& operator*() const
- { return *wp.data(); }
+ { return *data(); }
inline operator T*() const
- { return wp.data(); }
- inline T* data() const
- { return wp.data(); }
+ { return data(); }
+#ifdef qdoc
+ inline bool isNull() const;
+#else
+ using QPointerBase::isNull;
+#endif
};
-
+template <class T> Q_DECLARE_TYPEINFO_BODY(QPointer<T>, Q_MOVABLE_TYPE);
#if (!defined(Q_CC_SUN) || (__SUNPRO_CC >= 0x580)) // ambiguity between const T * and T *
@@ -163,4 +183,6 @@ QT_END_NAMESPACE
QT_END_HEADER
+#endif // QT_NO_QOBJECT
+
#endif // QPOINTER_H