diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-06 14:28:44 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-12 09:12:37 (GMT) |
commit | 3111f3c31627466d35317cceeb535c7679f4d3fa (patch) | |
tree | ea1b0ca59d90f0639227541524e4224a9e6232a9 /src/corelib | |
parent | 171d92dc8b800b24d28c7b4abf34d6961763bbf4 (diff) | |
download | Qt-3111f3c31627466d35317cceeb535c7679f4d3fa.zip Qt-3111f3c31627466d35317cceeb535c7679f4d3fa.tar.gz Qt-3111f3c31627466d35317cceeb535c7679f4d3fa.tar.bz2 |
Add the typedefs to QSharedPointer and QWeakPointer to make template
usage simpler.
For example, this allows writing code like:
template <class Pointer>
typename Pointer::pointer getPointer(constPointer &p)
{ return p.data(); }
and that code will work for both QSharedPointer and QWeakPointer.
Reviewed-by: Harald Fernengel
Also add an operator- to make pointer operations possible.
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 7b3239b..ba479f9 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -121,6 +121,13 @@ namespace QtSharedPointer { typedef T *Basic:: *RestrictedBool; public: typedef T Type; + typedef T element_type; + typedef T value_type; + typedef value_type *pointer; + typedef const value_type *const_pointer; + typedef value_type &reference; + typedef const value_type &const_reference; + typedef ptrdiff_t difference_type; inline T *data() const { return value; } inline bool isNull() const { return !data(); } @@ -490,6 +497,14 @@ class QWeakPointer typedef QtSharedPointer::ExternalRefCountData Data; public: + typedef T element_type; + typedef T value_type; + typedef value_type *pointer; + typedef const value_type *const_pointer; + typedef value_type &reference; + typedef const value_type &const_reference; + typedef ptrdiff_t difference_type; + inline bool isNull() const { return d == 0 || d->strongref == 0 || value == 0; } inline operator RestrictedBool() const { return isNull() ? 0 : &QWeakPointer::value; } inline bool operator !() const { return isNull(); } @@ -634,6 +649,12 @@ bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2) return ptr2 != ptr1; } +template <class T, class X> +Q_INLINE_TEMPLATE typename T::difference_type operator-(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2) +{ + return ptr1.data() - ptr2.data(); +} + template <class T> Q_INLINE_TEMPLATE QWeakPointer<T> QSharedPointer<T>::toWeakRef() const { |