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

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...
 
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 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...
 

Detailed Description

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

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:

Template Parameters
TThe type of the managed Cairo data structure.
See also
[CAIRO]

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 specified 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 managed by ptr is incremented by 1.

◆ ~CairoPointer()

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

Destroys the CairoPointer.

Postcondition
The reference count of the managed 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 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.

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 object is incremented by 1 and the reference count of the previously managed 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 managed object.

Returns
A non-const reference to the managed 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 managed object.

The method is equivalent to get().

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

◆ get()

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

Returns a pointer to the managed object.

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

◆ release()

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

Releases the currently managed object.

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

◆ reset()

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

Postcondition
The reference count of the previously managed is decremented by 1. The newly managed object is the object specified by ptr.

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