![]() |
Chemical Data Processing Library C++ API - Version 1.4.0
|
A smart pointer managing the lifetime of allocated Cairo 2D Graphics Library data structures. More...
#include <CairoPointer.hpp>
Inheritance diagram for CDPL::Vis::CairoPointer< T >: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 managed object. More... | |
| T * | operator-> () const throw () |
| Returns a pointer to the managed object. More... | |
| T * | get () const throw () |
| Returns a pointer to the managed object. More... | |
| T * | release () throw () |
| Releases the currently managed object. More... | |
| void | reset (T *ptr=0) throw () |
| Replaces the currently managed object with the object pointed to by ptr. More... | |
A smart pointer managing the lifetime of allocated Cairo 2D Graphics Library data structures.
Data structures required for interfacing with the 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 Vis::CairoPointerTraits 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 currently managed object will be replaced by the object managed by ptr. The reference count of the previously managed object will be decremented and the reference count of the new object 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 object is incremented by 1 and the reference count of the previously managed 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 managed object.
const reference to the managed object. | T * CDPL::Vis::CairoPointer< T >::operator-> | |||
| throw | ( | ||
| ) | |||
| T * CDPL::Vis::CairoPointer< T >::get | |||
| throw | ( | ||
| ) | |||
Returns a pointer to the managed object.
nullptr if no object is referenced. | T * CDPL::Vis::CairoPointer< T >::release | |||
| throw | ( | ||
| ) | |||
Releases the currently managed object.
nullptr if no object was referenced. nullptr. | void CDPL::Vis::CairoPointer< T >::reset | ( | T * | ptr = 0 | ) | |
| throw | ( | ||||
| ) | |||||
Replaces the currently managed object with the object pointed to by ptr.
The method has no effect if the currently managed object and the object pointed to by ptr are identical.