Chemical Data Processing Library C++ API - Version 1.1.1
|
A smart pointer managing the lifetime of allocated Cairo data structures. More...
#include <CairoPointer.hpp>
Public Member Functions | |
CairoPointer (T *ptr=0) throw () | |
Constructs a CairoPointer that manages the reference count of the object pointed to by ptr. More... | |
CairoPointer (const CairoPointer &ptr) throw () | |
Constructs a copy of the CairoPointer ptr. More... | |
~CairoPointer () | |
Destroys the CairoPointer . More... | |
CairoPointer & | operator= (const CairoPointer &ptr) throw () |
Assignment operator. More... | |
bool | operator! () const throw () |
Tells whether this CairoPointer references an object or holds a null pointer. More... | |
T & | operator* () const throw () |
Returns a non-const reference to the pointed-to object. More... | |
T * | operator-> () const throw () |
Returns a pointer to the referenced object. More... | |
T * | get () const throw () |
Returns a pointer to the referenced object. More... | |
T * | release () throw () |
Releases the currently referenced object. More... | |
void | reset (T *ptr=0) throw () |
Replaces the current object reference with a reference to the object pointed to by ptr. More... | |
A smart pointer managing the lifetime of allocated Cairo data structures.
Data structures required for interfacing with the Cairo 2D Graphics Library [CAIRO] generally have to be allocated dynamically via specialized functions and are passed as pointers from and to the Cairo library. The lifetime of an allocated data structure is determined by its reference count which has to be managed explicitely by the client code. CairoPointer
automatizes the reference count management by incrementing the reference count of the wrapped object whenever a CairoPointer
instance is copied, and decrementing the reference count if the CairoPointer
is destroyed or gets overwritten by assignment of another pointer instance of the same type.
Since the Cairo library is written in C and functions for changing the reference count of different Cairo data structures are named differently, CairoPointer
relies on the traits class CairoPointerTraits<T>
which has to be specialized for a particular data type and performs the actual work of incrementing and decrementing the reference count by calling the appropriate functions. Note that only a Cairo data structure for which such a specialization exists can be managed by a CairoPointer
. An attempt to instantiate CairoPointer
with an unsupported type will result in a compile time error.
Currently specializations for the following types are provided:
cairo_t
cairo_surface_t
cairo_pattern_t
T | The type of the managed Cairo data structure. |
|
explicit |
Constructs a CairoPointer
that manages the reference count of the object pointed to by ptr.
ptr | A pointer to the object whose reference count has to be managed. |
CDPL::Vis::CairoPointer< T >::CairoPointer | ( | const CairoPointer< T > & | ptr | ) | |
throw | ( | ||||
) |
Constructs a copy of the CairoPointer
ptr.
ptr | The other CairoPointer to copy. |
CDPL::Vis::CairoPointer< T >::~CairoPointer |
Destroys the CairoPointer
.
CDPL::Vis::CairoPointer< T > & CDPL::Vis::CairoPointer< T >::operator= | ( | const CairoPointer< T > & | ptr | ) | |
throw | ( | ||||
) |
Assignment operator.
The pointer to the currently referenced object will be replaced by a pointer to the object referenced by ptr. The reference count of the currently pointed-to object will be decremented and the reference count of the object pointed to by ptr is incremented. A self assignment has no effect.
ptr | The other CairoPointer to copy. |
CairoPointer
references the same object as ptr. The reference count of the new pointed-to object is incremented by 1 and the reference count of the old pointed-to object is decremented by 1. bool CDPL::Vis::CairoPointer< T >::operator! | |||
throw | ( | ||
) |
Tells whether this CairoPointer
references an object or holds a null pointer.
false
if an object is referenced, and true
otherwise. T & CDPL::Vis::CairoPointer< T >::operator* | |||
throw | ( | ||
) |
Returns a non-const
reference to the pointed-to object.
const
reference to the pointed-to object. T * CDPL::Vis::CairoPointer< T >::operator-> | |||
throw | ( | ||
) |
T * CDPL::Vis::CairoPointer< T >::get | |||
throw | ( | ||
) |
Returns a pointer to the referenced object.
T * CDPL::Vis::CairoPointer< T >::release | |||
throw | ( | ||
) |
Releases the currently referenced object.
void CDPL::Vis::CairoPointer< T >::reset | ( | T * | ptr = 0 | ) | |
throw | ( | ||||
) |
Replaces the current object reference with a reference to the object pointed to by ptr.
The method has no effect if the currently referenced object and the object pointed to by ptr are identical.