summaryrefslogtreecommitdiff
path: root/src/declarative/qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml')
-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 46168f4a3f..5d287e07f2 100644
--- a/src/declarative/qml/ftw/qdeclarativerefcount_p.h
+++ b/src/declarative/qml/ftw/qdeclarativerefcount_p.h
@@ -68,7 +68,7 @@ public:
inline virtual ~QDeclarativeRefCount();
inline void addref();
inline void release();
-
+ inline bool isLastRef() const {return refCount.load() == 1;}
protected:
inline virtual void destroy();
@@ -90,6 +90,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; }
@@ -152,14 +153,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;
}
@@ -168,7 +179,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;
}
@@ -180,7 +196,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;
}