From 35bf26aba421eb36d8d308a0a5138388faf67ef4 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 28 Jul 2011 18:39:34 +1000 Subject: Fix alias warnings in QDeclarativeGuard --- src/declarative/qml/qdeclarativedata_p.h | 30 +------- src/declarative/qml/qdeclarativeengine.cpp | 2 +- src/declarative/qml/qdeclarativeguard_p.h | 107 ++++++++++++++++++++------- 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 #include -#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 *guards; + QDeclarativeGuardImpl *guards; static QDeclarativeData *get(const QObject *object, bool create = false) { QObjectPrivate *priv = QObjectPrivate::get(const_cast(object)); @@ -160,32 +160,6 @@ private: mutable QDeclarativeDataExtended *extendedData; }; -template -void QDeclarativeGuard::addGuard() -{ - Q_ASSERT(!prev); - - if (QObjectPrivate::get(o)->wasDeleted) - return; - - QDeclarativeData *data = QDeclarativeData::get(o, true); - next = data->guards; - if (next) reinterpret_cast *>(next)->prev = &next; - data->guards = reinterpret_cast *>(this); - prev = &data->guards; -} - -template -void QDeclarativeGuard::remGuard() -{ - Q_ASSERT(prev); - - if (next) reinterpret_cast *>(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 *guard = guards; + QDeclarativeGuard *guard = static_cast *>(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 #include +#include 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 QDeclarativeGuard +class QDeclarativeGuard : private QDeclarativeGuardImpl { - QObject *o; - QDeclarativeGuard *next; - QDeclarativeGuard **prev; friend class QDeclarativeData; public: inline QDeclarativeGuard(); @@ -74,6 +88,9 @@ public: inline QDeclarativeGuard &operator=(const QDeclarativeGuard &o); inline QDeclarativeGuard &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) -#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 QDeclarativeGuard::QDeclarativeGuard() -: o(0), next(0), prev(0) { } template QDeclarativeGuard::QDeclarativeGuard(T *g) -: o(g), next(0), prev(0) +: QDeclarativeGuardImpl(g) { - if (o) addGuard(); } template QDeclarativeGuard::QDeclarativeGuard(const QDeclarativeGuard &g) -: o(g.o), next(0), prev(0) +: QDeclarativeGuardImpl(g) { - if (o) addGuard(); } template QDeclarativeGuard::~QDeclarativeGuard() { - if (prev) remGuard(); - o = 0; } template QDeclarativeGuard &QDeclarativeGuard::operator=(const QDeclarativeGuard &g) { - if (g.o != o) { - if (prev) remGuard(); - o = g.o; - if (o) addGuard(); - } + setObject(g.object()); return *this; } template QDeclarativeGuard &QDeclarativeGuard::operator=(T *g) { + setObject(g); + return *this; +} + +template +T *QDeclarativeGuard::object() const +{ + return static_cast(o); +}; + +template +void QDeclarativeGuard::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 { - OperationGuard(QObject *obj, QList *l) : list(l) { (QDeclarativeGuard&)*this = obj; } + OperationGuard(QObject *obj, QList *l) : list(l) { + setObject(static_cast(obj)); + } QList *list; void objectDestroyed(QDeclarativeStateOperation *) { // we assume priv will always be destroyed after objectDestroyed calls -- cgit v0.12