Chemical Data Processing Library C++ API - Version 1.1.1
Public Member Functions | List of all members
CDPL::Vis::CairoPointer< T > Class Template Reference

A smart pointer managing the lifetime of allocated Cairo 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...
 
CairoPointeroperator= (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...
 

Detailed Description

template<typename T>
class CDPL::Vis::CairoPointer< T >

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:

Template Parameters
TThe type of the managed Cairo data structure.

Constructor & Destructor Documentation

◆ CairoPointer() [1/2]

template<typename T >
CDPL::Vis::CairoPointer< T >::CairoPointer ( T *  ptr = 0)
throw (
)
explicit

Constructs a CairoPointer that manages the reference count of the object pointed to by ptr.

Parameters
ptrA pointer to the object whose reference count has to be managed.
Note
The reference count of the object pointed to by ptr is not incremented.

◆ CairoPointer() [2/2]

template<typename T >
CDPL::Vis::CairoPointer< T >::CairoPointer ( const CairoPointer< T > &  ptr)
throw (
)

Constructs a copy of the CairoPointer ptr.

Parameters
ptrThe other CairoPointer to copy.
Postcondition
The reference count of the object pointed to by ptr is incremented by 1.

◆ ~CairoPointer()

template<typename T >
CDPL::Vis::CairoPointer< T >::~CairoPointer

Destroys the CairoPointer.

Postcondition
The reference count of the pointed-to object is decremented by 1.

Member Function Documentation

◆ operator=()

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

Parameters
ptrThe other CairoPointer to copy.
Returns
A reference to itself.
Postcondition
The 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.

◆ operator!()

template<typename T >
bool CDPL::Vis::CairoPointer< T >::operator!
throw (
)

Tells whether this CairoPointer references an object or holds a null pointer.

Returns
false if an object is referenced, and true otherwise.

◆ operator*()

template<typename T >
T & CDPL::Vis::CairoPointer< T >::operator*
throw (
)

Returns a non-const reference to the pointed-to object.

Returns
A non-const reference to the pointed-to object.
Note
A null pointer check is not performed.

◆ operator->()

template<typename T >
T * CDPL::Vis::CairoPointer< T >::operator->
throw (
)

Returns a pointer to the referenced object.

The method is equivalent to get().

Returns
A pointer to the referenced object, or null if no object is referenced.
See also
get()

◆ get()

template<typename T >
T * CDPL::Vis::CairoPointer< T >::get
throw (
)

Returns a pointer to the referenced object.

Returns
A pointer to the referenced object, or null if no object is referenced.

◆ release()

template<typename T >
T * CDPL::Vis::CairoPointer< T >::release
throw (
)

Releases the currently referenced object.

Returns
A pointer to the formerly referenced object, or null if no object was referenced.
Postcondition
The reference count of the previously pointed-to object is decremented by 1 and the internal pointer to the referenced object is set to null.

◆ reset()

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

Postcondition
The reference count of the previously pointed-to object is decremented by 1. The newly referenced object is the object pointed to by ptr.

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