language/duchain
TypePtr< T > Class Template Reference
Can be used to control the lifetime of an object that has derived QSharedData. More...
#include <TypePtr>

Public Member Functions | |
| TypePtr (const TypePtr &o) | |
| TypePtr (T *p) | |
| TypePtr () | |
| ~TypePtr () | |
| void | attach (T *p) |
| template<class U > | |
| TypePtr< U > | cast (U *=0) const |
| void | clear () |
| const T * | constData () const |
| int | count () const |
| bool | isNull () const |
| bool | isUnique () const |
| operator bool () const | |
| bool | operator!= (const T *p) const |
| bool | operator!= (const TypePtr &o) const |
| T & | operator* () |
| const T & | operator* () const |
| T * | operator-> () |
| const T * | operator-> () const |
| bool | operator< (const TypePtr &o) const |
| TypePtr< T > & | operator= (T *p) |
| TypePtr< T > & | operator= (const TypePtr &o) |
| bool | operator== (const T *p) const |
| bool | operator== (const TypePtr &o) const |
| const T * | unsafeData () const |
| T * | unsafeData () |
Static Public Member Functions | |
| template<class U > | |
| static TypePtr< T > | dynamicCast (const TypePtr< U > &o) |
| template<class U > | |
| static TypePtr< T > | staticCast (const TypePtr< U > &o) |
Protected Attributes | |
| T * | d |
Detailed Description
template<class T>
class TypePtr< T >
Can be used to control the lifetime of an object that has derived QSharedData.
As long a someone holds a TypePtr on some QSharedData object it won't become deleted but is deleted once its reference count is 0. This struct emulates C++ pointers virtually perfectly. So just use it like a simple C++ pointer.
The difference with using QSharedDataPointer is that QSharedDataPointer is a building block for implementing a value class with implicit sharing (like QString), whereas TypePtr provides refcounting to code that uses pointers.
Definition at line 54 of file typepointer.h.
Constructor & Destructor Documentation
Creates a null pointer.
Definition at line 60 of file typepointer.h.
Unreferences the object that this pointer points to.
If it was the last reference, the object will be deleted.
Definition at line 81 of file typepointer.h.
Member Function Documentation
| Q_INLINE_TEMPLATE void TypePtr< T >::attach | ( | T * | p | ) | [inline] |
Attach the given pointer to the current TypePtr.
If the previous shared pointer is not owned by any TypePtr, it is deleted.
Definition at line 212 of file typepointer.h.
Uses dynamic_cast to cast this pointer to the given type.
Definition at line 161 of file typepointer.h.
| Q_INLINE_TEMPLATE void TypePtr< T >::clear | ( | ) | [inline] |
| const T* TypePtr< T >::constData | ( | ) | const [inline] |
- Returns:
- a const pointer to the shared object.
Definition at line 118 of file typepointer.h.
| int TypePtr< T >::count | ( | ) | const [inline] |
Returns the number of references.
- Returns:
- the number of references
Definition at line 141 of file typepointer.h.
| static TypePtr<T> TypePtr< T >::dynamicCast | ( | const TypePtr< U > & | o | ) | [inline, static] |
Convert TypePtr<U> to TypePtr<T>, using a dynamic_cast.
This will compile whenever T* and U* are compatible, i.e. T is a subclass of U or vice-versa. Example syntax: TypePtr<T> tPtr; TypePtr<U> uPtr = TypePtr<U>::dynamicCast( tPtr ); Since a dynamic_cast is used, if U derives from T, and tPtr isn't an instance of U, uPtr will be 0.
Definition at line 191 of file typepointer.h.
| bool TypePtr< T >::isNull | ( | ) | const [inline] |
Test if the shared pointer is null.
- Returns:
- true if the pointer is null, false otherwise.
- See also:
- opertor (bool)
Definition at line 148 of file typepointer.h.
| bool TypePtr< T >::isUnique | ( | ) | const [inline] |
- Returns:
- Whether this is the only shared pointer pointing to to the pointee, or whether it's shared among multiple shared pointers.
Definition at line 155 of file typepointer.h.
| TypePtr< T >::operator bool | ( | ) | const [inline] |
Test if the shared pointer is NOT null.
- Returns:
- true if the shared pointer is NOT null, false otherwise.
- See also:
- isNull
Definition at line 97 of file typepointer.h.
| static TypePtr<T> TypePtr< T >::staticCast | ( | const TypePtr< U > & | o | ) | [inline, static] |
Convert TypePtr<U> to TypePtr<T>, using a static_cast.
This will compile whenever T* and U* are compatible, i.e. T is a subclass of U or vice-versa. Example syntax: TypePtr<T> tPtr; TypePtr<U> uPtr = TypePtr<U>::staticCast( tPtr );
Definition at line 176 of file typepointer.h.
| const T* TypePtr< T >::unsafeData | ( | ) | const [inline] |
- Returns:
- the pointer
- Warning:
- Since often TypePtr is used only temporarily, it is dangerous to work with the pointer directly, because as soon as the TypePtr gets out of scope, the type instance is deleted. Make sure you have a TypePtr that holds the type alive.
Definition at line 113 of file typepointer.h.
| T* TypePtr< T >::unsafeData | ( | ) | [inline] |
- Returns:
- the pointer
- Warning:
- Since often TypePtr is used only temporarily, it is dangerous to work with the pointer directly, because as soon as the TypePtr gets out of scope, the type instance is deleted. Make sure you have a TypePtr that holds the type alive.
Definition at line 105 of file typepointer.h.
The documentation for this class was generated from the following file:
KDE 4.4 API Reference