aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles Yin <charles.yin@nokia.com>2011-10-26 12:32:16 +1000
committerMichael Brasser <michael.brasser@nokia.com>2011-10-27 01:09:50 +0200
commitfa31479808e7fdf52df7831e951731b11ca086f6 (patch)
tree09766f26c5fcc1d4ce31448b8446a1bf4ab79ef1
parentff90f4691f7cdde19008cfc957b44f56e562fa47 (diff)
Improve QDeclarativeRefCount and QDeclarativeRefPointer
1) Add bool isLastRef() to QDeclarativeRefCount 2) Set actual pointer to 0 if isLastRef() after calling release() Change-Id: I9928a7171e759f4d56fb85d3c2f65fd1271d9ada Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
-rw-r--r--src/declarative/qml/ftw/qdeclarativerefcount_p.h31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/declarative/qml/ftw/qdeclarativerefcount_p.h b/src/declarative/qml/ftw/qdeclarativerefcount_p.h
index b9b32b24ac..765dbeaee1 100644
--- a/src/declarative/qml/ftw/qdeclarativerefcount_p.h
+++ b/src/declarative/qml/ftw/qdeclarativerefcount_p.h
@@ -69,7 +69,7 @@ public:
inline virtual ~QDeclarativeRefCount();
inline void addref();
inline void release();
-
+ inline bool isLastRef() const {return refCount == 1;}
protected:
inline virtual void destroy();
@@ -91,6 +91,7 @@ public:
inline bool isNull() const { return !o; }
+ inline bool operator()() const { return !isNull();}
inline T* operator->() const { return o; }
inline T& operator*() const { return *o; }
inline operator T*() const { return o; }
@@ -153,14 +154,24 @@ QDeclarativeRefPointer<T>::QDeclarativeRefPointer(const QDeclarativeRefPointer<T
template<class T>
QDeclarativeRefPointer<T>::~QDeclarativeRefPointer()
{
- if (o) o->release();
+ if (o) {
+ bool deleted = o->isLastRef();
+ o->release();
+ if (deleted)
+ o = 0;
+ }
}
template<class T>
QDeclarativeRefPointer<T> &QDeclarativeRefPointer<T>::operator=(const QDeclarativeRefPointer<T> &other)
{
if (other.o) other.o->addref();
- if (o) o->release();
+ if (o) {
+ bool deleted = o->isLastRef();
+ o->release();
+ if (deleted)
+ o = 0;
+ }
o = other.o;
return *this;
}
@@ -169,7 +180,12 @@ template<class T>
QDeclarativeRefPointer<T> &QDeclarativeRefPointer<T>::operator=(T *other)
{
if (other) other->addref();
- if (o) o->release();
+ if (o) {
+ bool deleted = o->isLastRef();
+ o->release();
+ if (deleted)
+ o = 0;
+ }
o = other;
return *this;
}
@@ -181,7 +197,12 @@ of the callers reference of other.
template<class T>
QDeclarativeRefPointer<T> &QDeclarativeRefPointer<T>::take(T *other)
{
- if (o) o->release();
+ if (o) {
+ bool deleted = o->isLastRef();
+ o->release();
+ if (deleted)
+ o = 0;
+ }
o = other;
return *this;
}