diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-07-28 08:39:34 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-07-29 02:35:45 (GMT) |
commit | 35bf26aba421eb36d8d308a0a5138388faf67ef4 (patch) | |
tree | b4bfac33cc445ab2f065a98c009bd552cb612302 | |
parent | d4740963fa6284407c74c49ea587b0511c9bc4c9 (diff) | |
download | Qt-35bf26aba421eb36d8d308a0a5138388faf67ef4.zip Qt-35bf26aba421eb36d8d308a0a5138388faf67ef4.tar.gz Qt-35bf26aba421eb36d8d308a0a5138388faf67ef4.tar.bz2 |
Fix alias warnings in QDeclarativeGuard
-rw-r--r-- | src/declarative/qml/qdeclarativedata_p.h | 30 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeengine.cpp | 2 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeguard_p.h | 107 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativestate_p_p.h | 4 |
4 files changed, 88 insertions, 55 deletions
diff --git a/src/declarative/qml/qdeclarativedata_p.h b/src/declarative/qml/qdeclarativedata_p.h index 2a5eace..4f22b8f 100644 --- a/src/declarative/qml/qdeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedata_p.h @@ -55,10 +55,10 @@ #include <QtScript/qscriptvalue.h> #include <private/qobject_p.h> -#include "private/qdeclarativeguard_p.h" QT_BEGIN_NAMESPACE +class QDeclarativeGuardImpl; class QDeclarativeCompiledData; class QDeclarativeAbstractBinding; class QDeclarativeContext; @@ -134,7 +134,7 @@ public: quint32 objectDataRefCount; QDeclarativePropertyCache *propertyCache; - QDeclarativeGuard<QObject> *guards; + QDeclarativeGuardImpl *guards; static QDeclarativeData *get(const QObject *object, bool create = false) { QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object)); @@ -160,32 +160,6 @@ private: mutable QDeclarativeDataExtended *extendedData; }; -template<class T> -void QDeclarativeGuard<T>::addGuard() -{ - Q_ASSERT(!prev); - - if (QObjectPrivate::get(o)->wasDeleted) - return; - - QDeclarativeData *data = QDeclarativeData::get(o, true); - next = data->guards; - if (next) reinterpret_cast<QDeclarativeGuard<T> *>(next)->prev = &next; - data->guards = reinterpret_cast<QDeclarativeGuard<QObject> *>(this); - prev = &data->guards; -} - -template<class T> -void QDeclarativeGuard<T>::remGuard() -{ - Q_ASSERT(prev); - - if (next) reinterpret_cast<QDeclarativeGuard<T> *>(next)->prev = prev; - *prev = next; - next = 0; - prev = 0; -} - QT_END_NAMESPACE #endif // QDECLARATIVEDATA_P_H diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index e9feff4..1899b34 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1154,7 +1154,7 @@ void QDeclarativeData::destroyed(QObject *object) context->destroy(); while (guards) { - QDeclarativeGuard<QObject> *guard = guards; + QDeclarativeGuard<QObject> *guard = static_cast<QDeclarativeGuard<QObject> *>(guards); *guard = (QObject *)0; guard->objectDestroyed(object); } diff --git a/src/declarative/qml/qdeclarativeguard_p.h b/src/declarative/qml/qdeclarativeguard_p.h index a085258..393f2b0 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 diff --git a/src/declarative/util/qdeclarativestate_p_p.h b/src/declarative/util/qdeclarativestate_p_p.h index ec18f59..195b935 100644 --- a/src/declarative/util/qdeclarativestate_p_p.h +++ b/src/declarative/util/qdeclarativestate_p_p.h @@ -206,7 +206,9 @@ public: struct OperationGuard : public QDeclarativeGuard<QDeclarativeStateOperation> { - OperationGuard(QObject *obj, QList<OperationGuard> *l) : list(l) { (QDeclarativeGuard<QObject>&)*this = obj; } + OperationGuard(QObject *obj, QList<OperationGuard> *l) : list(l) { + setObject(static_cast<QDeclarativeStateOperation *>(obj)); + } QList<OperationGuard> *list; void objectDestroyed(QDeclarativeStateOperation *) { // we assume priv will always be destroyed after objectDestroyed calls |