OpenCurves  0.9
plotutil::RefCountPtr< T > Class Template Reference

A pointer wrapper for a reference counted object such as RefCountObject. More...

#include <refcountptr.h>

Public Member Functions

 RefCountPtr ()
 Default constructor to a null pointer.
 
 RefCountPtr (T *ptr)
 Constructor using the template type, incrementing the reference count of ptr. More...
 
template<class Q >
 RefCountPtr (Q *ptr)
 Constructor using a different pointer type. More...
 
 RefCountPtr (const RefCountPtr &other)
 Copy constructor. More...
 
template<class Q >
 RefCountPtr (const RefCountPtr< Q > &other)
 Copy constructor using a different pointer type. More...
 
 RefCountPtr (RefCountPtr &&other)
 Move constructor. More...
 
 ~RefCountPtr ()
 Destructor: calls release().
 
void release ()
 Explicitly releases the internal pointer, making this object null. More...
 
T * ptr ()
 Access the internal pointer. More...
 
const T * ptr () const
 Access the internal pointer. More...
 
T & operator* ()
 Dereference operator. More...
 
const T & operator* () const
 Dereference operator. More...
 
T * operator-> ()
 Dereference call operator. More...
 
const T * operator-> () const
 Dereference call operator. More...
 
 operator bool () const
 Cast to bool operator. More...
 
bool operator! () const
 Negation operator. More...
 
bool operator== (const RefCountPtr &other)
 Equality operator. More...
 
bool operator!= (const RefCountPtr &other)
 Inequality operator. More...
 
RefCountPtroperator= (const RefCountPtr &other)
 Assignment operator. More...
 
RefCountPtroperator= (T *ptr)
 Assignment operator. More...
 
template<class Q >
RefCountPtroperator= (Q *ptr)
 Assignment operator to a derivation of T. More...
 
template<class Q >
RefCountPtr< T > & operator= (Q *ptr)
 

Detailed Description

template<class T>
class plotutil::RefCountPtr< T >

A pointer wrapper for a reference counted object such as RefCountObject.

The template type must support the following:

  • Construction with an appropriate reference count. See below.
  • addReference() method : increment the reference count by 1.
  • decReference() method : decrement the reference count by 1, deleting the object when zero.

It is recommended that the supported type be constructed with a reference count of zero, allowing the RefCountPtr to increment it to 1.

Constructor & Destructor Documentation

template<class T>
plotutil::RefCountPtr< T >::RefCountPtr ( T *  ptr)
inline

Constructor using the template type, incrementing the reference count of ptr.

Parameters
ptrThe object to point to. Null is handled (equivalent to the default constructor).
template<class T >
template<class Q >
plotutil::RefCountPtr< T >::RefCountPtr ( Q *  ptr)
inline

Constructor using a different pointer type.

Type Q must be able to be up-cast to T.

Template Parameters
QThe object type to construct from. T must be in the inheritance hierarchy of Q.
Parameters
ptrThe object to point to. Null is handled (equivalent to the default constructor).
template<class T>
plotutil::RefCountPtr< T >::RefCountPtr ( const RefCountPtr< T > &  other)
inline

Copy constructor.

Parameters
otherThe object to copy.
template<class T>
template<class Q >
plotutil::RefCountPtr< T >::RefCountPtr ( const RefCountPtr< Q > &  other)

Copy constructor using a different pointer type.

Type Q must be able to be up-cast to T.

Template Parameters
QThe object type to construct from. T must be in the inheritance hierarchy of Q.
Parameters
otherThe object to copy.
template<class T>
plotutil::RefCountPtr< T >::RefCountPtr ( RefCountPtr< T > &&  other)
inline

Move constructor.

Parameters
otherThe object to move construct from.

Member Function Documentation

template<class T>
plotutil::RefCountPtr< T >::operator bool ( ) const
inline

Cast to bool operator.

True if non null.

Returns
True if non null, false if null.
template<class T>
bool plotutil::RefCountPtr< T >::operator! ( ) const
inline

Negation operator.

True if null.

Returns
True if null, false if non null.
template<class T>
bool plotutil::RefCountPtr< T >::operator!= ( const RefCountPtr< T > &  other)
inline

Inequality operator.

Parameters
otherThe object to compare to.
Returns
True if the pointers do not match, including null pointers.
template<class T>
T& plotutil::RefCountPtr< T >::operator* ( )
inline

Dereference operator.

Do not use if null.

Returns
A reference the internal object.
template<class T>
const T& plotutil::RefCountPtr< T >::operator* ( ) const
inline

Dereference operator.

Do not use if null.

Returns
A reference the internal object.
template<class T>
T* plotutil::RefCountPtr< T >::operator-> ( )
inline

Dereference call operator.

Do not use if null.

Returns
A pointer the internal object.
template<class T>
const T* plotutil::RefCountPtr< T >::operator-> ( ) const
inline

Dereference call operator.

Do not use if null.

Returns
A pointer the internal object.
template<class T >
RefCountPtr< T > & plotutil::RefCountPtr< T >::operator= ( const RefCountPtr< T > &  other)
inline

Assignment operator.

Releases current reference and attains new reference as required.

Parameters
otherThe new object to point to.
template<class T>
RefCountPtr< T > & plotutil::RefCountPtr< T >::operator= ( T *  ptr)
inline

Assignment operator.

Releases current reference and attains new reference as required.

Parameters
ptrThe new object to point to. Handles null pointers.
template<class T>
template<class Q >
RefCountPtr& plotutil::RefCountPtr< T >::operator= ( Q *  ptr)

Assignment operator to a derivation of T.

Releases current reference and attains new reference as required.

Template Parameters
QThe object type to construct from. T must be in the inheritance hierarchy of Q.
Parameters
ptrThe object to point to. Null is handled (equivalent to the default constructor).
template<class T>
bool plotutil::RefCountPtr< T >::operator== ( const RefCountPtr< T > &  other)
inline

Equality operator.

Parameters
otherThe object to compare to.
Returns
True if the pointers match, including null pointers.
template<class T>
T* plotutil::RefCountPtr< T >::ptr ( )
inline

Access the internal pointer.

Returns
A pointer the internal object.
template<class T>
const T* plotutil::RefCountPtr< T >::ptr ( ) const
inline

Access the internal pointer.

Returns
A pointer the internal object.
template<class T >
void plotutil::RefCountPtr< T >::release ( )
inline

Explicitly releases the internal pointer, making this object null.

The reference count is decremented as needed.


The documentation for this class was generated from the following file: