aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativeguard_p.h
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2011-07-28 18:39:34 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-29 05:28:25 +0200
commit4a9c50b9c119dc47cf35a4e96a007ce4dd3825e2 (patch)
tree10c03fe49a8bd6b5f96f72476a36715f6af6a294 /src/declarative/qml/qdeclarativeguard_p.h
parentd08fb44d8f1414bbf519875fd872d742c41300ec (diff)
Fix alias warnings in QDeclarativeGuard
Task-number: QTBUG-19736 QTBUG-19693 Change-Id: Id3aefe56bc1e33757b8c407f2022b49cc136f00b Reviewed-on: http://codereview.qt.nokia.com/2359 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/declarative/qml/qdeclarativeguard_p.h')
-rw-r--r--src/declarative/qml/qdeclarativeguard_p.h107
1 files changed, 82 insertions, 25 deletions
diff --git a/src/declarative/qml/qdeclarativeguard_p.h b/src/declarative/qml/qdeclarativeguard_p.h
index a085258774..393f2b0ee7 100644
--- a/src/declarative/qml/qdeclarativeguard_p.h
+++ b/src/declarative/qml/qdeclarativeguard_p.h
@@ -55,16 +55,30 @@
#include <QtCore/qglobal.h>
#include <QtCore/qvariant.h>
+#include <private/qdeclarativedata_p.h>
QT_BEGIN_NAMESPACE
+class QDeclarativeGuardImpl
+{
+public:
+ inline QDeclarativeGuardImpl();
+ inline QDeclarativeGuardImpl(QObject *);
+ inline QDeclarativeGuardImpl(const QDeclarativeGuardImpl &);
+ inline ~QDeclarativeGuardImpl();
+
+ QObject *o;
+ QDeclarativeGuardImpl *next;
+ QDeclarativeGuardImpl **prev;
+
+ inline void addGuard();
+ inline void remGuard();
+};
+
class QObject;
template<class T>
-class QDeclarativeGuard
+class QDeclarativeGuard : private QDeclarativeGuardImpl
{
- QObject *o;
- QDeclarativeGuard<QObject> *next;
- QDeclarativeGuard<QObject> **prev;
friend class QDeclarativeData;
public:
inline QDeclarativeGuard();
@@ -74,6 +88,9 @@ public:
inline QDeclarativeGuard<T> &operator=(const QDeclarativeGuard<T> &o);
inline QDeclarativeGuard<T> &operator=(T *);
+
+ inline T *object() const;
+ inline void setObject(T *g);
inline bool isNull() const
{ return !o; }
@@ -89,67 +106,107 @@ public:
protected:
virtual void objectDestroyed(T *) {}
-
-private:
- inline void addGuard();
- inline void remGuard();
};
-QT_END_NAMESPACE
-
Q_DECLARE_METATYPE(QDeclarativeGuard<QObject>)
-#include "private/qdeclarativedata_p.h"
+QDeclarativeGuardImpl::QDeclarativeGuardImpl()
+: o(0), next(0), prev(0)
+{
+}
-QT_BEGIN_NAMESPACE
+QDeclarativeGuardImpl::QDeclarativeGuardImpl(QObject *g)
+: o(g), next(0), prev(0)
+{
+ if (o) addGuard();
+}
+
+QDeclarativeGuardImpl::QDeclarativeGuardImpl(const QDeclarativeGuardImpl &g)
+: o(g.o), next(0), prev(0)
+{
+ if (o) addGuard();
+}
+
+QDeclarativeGuardImpl::~QDeclarativeGuardImpl()
+{
+ if (prev) remGuard();
+ o = 0;
+}
+
+void QDeclarativeGuardImpl::addGuard()
+{
+ Q_ASSERT(!prev);
+
+ if (QObjectPrivate::get(o)->wasDeleted)
+ return;
+
+ QDeclarativeData *data = QDeclarativeData::get(o, true);
+ next = data->guards;
+ if (next) next->prev = &next;
+ data->guards = this;
+ prev = &data->guards;
+}
+
+void QDeclarativeGuardImpl::remGuard()
+{
+ Q_ASSERT(prev);
+
+ if (next) next->prev = prev;
+ *prev = next;
+ next = 0;
+ prev = 0;
+}
template<class T>
QDeclarativeGuard<T>::QDeclarativeGuard()
-: o(0), next(0), prev(0)
{
}
template<class T>
QDeclarativeGuard<T>::QDeclarativeGuard(T *g)
-: o(g), next(0), prev(0)
+: QDeclarativeGuardImpl(g)
{
- if (o) addGuard();
}
template<class T>
QDeclarativeGuard<T>::QDeclarativeGuard(const QDeclarativeGuard<T> &g)
-: o(g.o), next(0), prev(0)
+: QDeclarativeGuardImpl(g)
{
- if (o) addGuard();
}
template<class T>
QDeclarativeGuard<T>::~QDeclarativeGuard()
{
- if (prev) remGuard();
- o = 0;
}
template<class T>
QDeclarativeGuard<T> &QDeclarativeGuard<T>::operator=(const QDeclarativeGuard<T> &g)
{
- if (g.o != o) {
- if (prev) remGuard();
- o = g.o;
- if (o) addGuard();
- }
+ setObject(g.object());
return *this;
}
template<class T>
QDeclarativeGuard<T> &QDeclarativeGuard<T>::operator=(T *g)
{
+ setObject(g);
+ return *this;
+}
+
+template<class T>
+T *QDeclarativeGuard<T>::object() const
+{
+ return static_cast<T *>(o);
+};
+
+template<class T>
+void QDeclarativeGuard<T>::setObject(T *g)
+{
if (g != o) {
if (prev) remGuard();
o = g;
if (o) addGuard();
}
- return *this;
}
QT_END_NAMESPACE