• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

TypePtr< T > Class Template Reference

Can be used to control the lifetime of an object that has derived QSharedData. More...

#include <TypePtr>

Inheritance diagram for TypePtr< T >:
Inheritance graph
[legend]

List of all members.

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.

Author:
Waldo Bastian <bastian@kde.org>

Definition at line 54 of file typepointer.h.


Constructor & Destructor Documentation

template<class T>
TypePtr< T >::TypePtr (  )  [inline]

Creates a null pointer.

Definition at line 60 of file typepointer.h.

template<class T>
TypePtr< T >::TypePtr ( T *  p  )  [inline, explicit]

Creates a new pointer.

Parameters:
p the pointer

Definition at line 67 of file typepointer.h.

template<class T>
TypePtr< T >::TypePtr ( const TypePtr< T > &  o  )  [inline]

Copies a pointer.

Parameters:
o the pointer to copy

Definition at line 74 of file typepointer.h.

template<class T>
TypePtr< T >::~TypePtr (  )  [inline]

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

template<class T>
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.

template<class T>
template<class U >
TypePtr<U> TypePtr< T >::cast ( U *  = 0  )  const [inline]

Uses dynamic_cast to cast this pointer to the given type.

Definition at line 161 of file typepointer.h.

template<class T >
Q_INLINE_TEMPLATE void TypePtr< T >::clear (  )  [inline]

Clear the pointer, i.e.

make it a null pointer.

Definition at line 223 of file typepointer.h.

template<class T>
const T* TypePtr< T >::constData (  )  const [inline]
Returns:
a const pointer to the shared object.

Definition at line 118 of file typepointer.h.

template<class T>
int TypePtr< T >::count (  )  const [inline]

Returns the number of references.

Returns:
the number of references

Definition at line 141 of file typepointer.h.

template<class T>
template<class U >
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.

template<class T>
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.

template<class T>
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.

template<class T>
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.

template<class T>
template<class U >
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.

template<class T>
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.

template<class T>
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:
  • typepointer.h

language/duchain

Skip menu "language/duchain"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal