diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-03-06 08:37:33 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-16 19:27:59 +0100 |
commit | 0ebca8f46fdfb8c99926cf28717b62c8cd741858 (patch) | |
tree | 5d94df9183a062c28f85fb422834b58003c86396 /src/corelib | |
parent | 0731c90eec594224954ea1c6677e6bf2cff50e51 (diff) |
QSharedPointer: add reset() member functions
These have been added for std::shared_ptr compatibility,
but in particular to allow tst_qnetworkreply && friends
to drop the implicit conversions added to QSP by
inheritance, so QSP can become final.
Change-Id: I0f0401b02125d65622e52393b40a3b10bd9a850c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 29 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer.h | 5 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 7 |
3 files changed, 41 insertions, 0 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 58c62f0a3e..50e555d968 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -698,6 +698,35 @@ */ /*! + \fn void QSharedPointer::reset() + \since 5.0 + + Same as clear(). For std::shared_ptr compatibility. +*/ + +/*! + \fn void QSharedPointer::reset(T *t) + \since 5.0 + + Resets this QSharedPointer object to point to \a t + instead. Equivalent to: + \code + QSharedPointer<T> other(t); this->swap(other); + \endcode +*/ + +/*! + \fn void QSharedPointer::reset(T *t, Deleter deleter) + \since 5.0 + + Resets this QSharedPointer object to point to \a t + instead, with deleter \a deleter. Equivalent to: + \code + QSharedPointer<T> other(t, deleter); this->swap(other); + \endcode +*/ + +/*! \fn QWeakPointer::QWeakPointer() Creates a QWeakPointer that points to nothing. diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h index 4033b5d422..b0a1b7619d 100644 --- a/src/corelib/tools/qsharedpointer.h +++ b/src/corelib/tools/qsharedpointer.h @@ -85,6 +85,11 @@ public: void clear(); + void reset(); + void reset(T *t); + template <typename Deleter> + void reset(T *t, Deleter deleter); + // casts: template <class X> QSharedPointer<X> staticCast() const; template <class X> QSharedPointer<X> dynamicCast() const; diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 81ce17889e..fadb4e0586 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -510,6 +510,13 @@ public: inline void swap(QSharedPointer &other) { QSharedPointer<T>::internalSwap(other); } + inline void reset() { clear(); } + inline void reset(T *t) + { QSharedPointer copy(t); swap(copy); } + template <typename Deleter> + inline void reset(T *t, Deleter deleter) + { QSharedPointer copy(t, deleter); swap(copy); } + template <class X> QSharedPointer<X> staticCast() const { |