QSDK 1.1 Documentation
Main Page | Modules | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

Com::Ptr< T > Struct Template Reference
[QCom]

#include <Q/com.h>

List of all members.

Public Member Functions

 Ptr ()
 Ptr (T *p, bool doAddRef=true)
 Ptr (const Ptr< T > &p)
 ~Ptr ()
bool valid () const
 operator T * () const
T * operator-> () const
T & operator * () const
T ** operator & ()
T *const * operator & () const
Ptr< T > & operator= (const Ptr< T > &p)
Ptr< T > & operator= (T *p)


Detailed Description

template<class T>
struct Com::Ptr< T >

This template class can be used to ease the implementation of reference counting. It is used as a 'smart pointer' and automatically calls methods from the Unknown interface when instances of the template are constructed, assigned and destroyed. The Ptr<T> template should be instantiated with a class derived from Unknown. For the reference counting to be reliable, a user should use instances of Ptr<T> for every long-lived reference to an object (such as class members or global variables). There is a cost associated with the reference count maintenance so care should be taken in the use of Ptr<T> in time-critical algorithms.


Constructor & Destructor Documentation

template<class T>
Com::Ptr< T >::Ptr  )  [inline]
 

Create a new smart pointer. The pointer is initialised to zero.

template<class T>
Com::Ptr< T >::Ptr T *  p,
bool  doAddRef = true
[inline]
 

Create a new smart pointer with the pointer initialised to p. The reference count of p will be increased by one if the value of doAddRef is true (this is the default).

template<class T>
Com::Ptr< T >::Ptr const Ptr< T > &  p  )  [inline]
 

Create a new smart pointer with the pointer initialised from p. The reference count of p will be increased by one.

template<class T>
Com::Ptr< T >::~Ptr  )  [inline]
 

Destroy a smart pointer. The reference count of the interface being pointed to (if any) is decreased by one by calling its Unknown::release method.


Member Function Documentation

template<class T>
T* const* Com::Ptr< T >::operator &  )  const [inline]
 

The compiler calls this method automatically when the appropriate language construct is used. This makes the smart pointer behave as if it was a regular pointer.

template<class T>
T** Com::Ptr< T >::operator &  )  [inline]
 

The compiler calls this method automatically when the appropriate language construct is used. This makes the smart pointer behave as if it was a regular pointer.

template<class T>
T& Com::Ptr< T >::operator *  )  const [inline]
 

The compiler calls this method automatically when the appropriate language construct is used. This makes the smart pointer behave as if it was a regular pointer.

template<class T>
Com::Ptr< T >::operator T *  )  const [inline]
 

The compiler calls this method automatically when the appropriate language construct is used. This makes the smart pointer behave as if it was a regular pointer.

template<class T>
T* Com::Ptr< T >::operator->  )  const [inline]
 

The compiler calls this method automatically when the appropriate language construct is used. This makes the smart pointer behave as if it was a regular pointer.

template<class T>
Ptr<T>& Com::Ptr< T >::operator= T *  p  )  [inline]
 

Assign one pointer to another by copying the underlying pointer, adjusting reference counts as appropriate.

template<class T>
Ptr<T>& Com::Ptr< T >::operator= const Ptr< T > &  p  )  [inline]
 

Assign one pointer to another by copying the underlying pointer, adjusting reference counts as appropriate.

template<class T>
bool Com::Ptr< T >::valid  )  const [inline]
 

Return true if the reference is valid (i.e. if the pointer is non-zero).

Return to QSDK documentation Contents page. Contact details for support, information and fault-reporting.
Qube Software Limited © 2000-2004