dune-fem 2.8.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
Dune::Fem::ReferenceCounterInterface< RCT > Class Template Reference

interface for objects capable of reference counting More...

#include <dune/fem/storage/referencecounter.hh>

Inheritance diagram for Dune::Fem::ReferenceCounterInterface< RCT >:
Inheritance graph

Public Types

typedef RCT Traits
 type of the traits
 
typedef Traits::ReferenceCounterType ReferenceCounterType
 type of the implementation (Barton-Nackman)
 
typedef ThisType ReferenceCounterInterfaceType
 type of the reference counter interface
 
typedef Traits::ObjectType ObjectType
 type of the object, this is a reference counter for
 

Public Member Functions

void addReference () const
 add a reference to this object
 
void deleteObject ()
 delete to object
 
const ObjectTypegetObject () const
 access the real object (const version)
 
ObjectTypegetObject ()
 access the real object (non-const version)
 
void removeReference () const
 remove a reference to this object
 

Protected Member Functions

const Implementation & asImp () const
 
Implementation & asImp ()
 

Static Protected Member Functions

static const Implementation & asImp (const ThisType &other)
 
static Implementation & asImp (ThisType &other)
 
static const RCT::ReferenceCounterType & asImp (const ThisType &other)
 
static RCT::ReferenceCounterType & asImp (ThisType &other)
 

Detailed Description

template<class RCT>
class Dune::Fem::ReferenceCounterInterface< RCT >

interface for objects capable of reference counting

In many situations it has to be decided, whether an object is still required or must be freed. A simple approach to this decision is to count all references to an object. When the last reference is released, the object is freed.

The ReferenceCounterInterface provides methods, an object needs to support reference counting. Classes implementing this interface can be used with ObjectReference and ObjectPointer. Both will implicitly call addReference when they start pointing to an object and removeReference when they stop pointing to it.

Note
Reference counting is not a good mehtod for garbage collection, since it does not detect cycles. So be careful when using reference counters!

Member Typedef Documentation

◆ ObjectType

template<class RCT >
typedef Traits::ObjectType Dune::Fem::ReferenceCounterInterface< RCT >::ObjectType

type of the object, this is a reference counter for

◆ ReferenceCounterInterfaceType

template<class RCT >
typedef ThisType Dune::Fem::ReferenceCounterInterface< RCT >::ReferenceCounterInterfaceType

type of the reference counter interface

◆ ReferenceCounterType

template<class RCT >
typedef Traits::ReferenceCounterType Dune::Fem::ReferenceCounterInterface< RCT >::ReferenceCounterType

type of the implementation (Barton-Nackman)

◆ Traits

template<class RCT >
typedef RCT Dune::Fem::ReferenceCounterInterface< RCT >::Traits

type of the traits

Member Function Documentation

◆ addReference()

template<class RCT >
void Dune::Fem::ReferenceCounterInterface< RCT >::addReference ( ) const
inline

add a reference to this object

This method should be called whenever a permanent reference to this object is established (a pointer counts as a reference, too)

Note
This method is declared const, since we want to be able to add references to const objects, too. Hence, the reference coutner must be declared mutable.

◆ asImp() [1/6]

template<class RCT >
Implementation & Dune::Fem::BartonNackmanInterface< Interface, Implementation >::asImp ( )
inlineprotected

◆ asImp() [2/6]

template<class RCT >
const Implementation & Dune::Fem::BartonNackmanInterface< Interface, Implementation >::asImp ( ) const
inlineprotected

◆ asImp() [3/6]

static const RCT::ReferenceCounterType & Dune::Fem::BartonNackmanInterface< ReferenceCounterInterface< RCT > , RCT::ReferenceCounterType >::asImp ( const ThisType other)
inlinestaticprotectedinherited

◆ asImp() [4/6]

template<class RCT >
static const Implementation & Dune::Fem::BartonNackmanInterface< Interface, Implementation >::asImp ( const ThisType other)
inlinestaticprotected

◆ asImp() [5/6]

static RCT::ReferenceCounterType & Dune::Fem::BartonNackmanInterface< ReferenceCounterInterface< RCT > , RCT::ReferenceCounterType >::asImp ( ThisType other)
inlinestaticprotectedinherited

◆ asImp() [6/6]

template<class RCT >
static Implementation & Dune::Fem::BartonNackmanInterface< Interface, Implementation >::asImp ( ThisType other)
inlinestaticprotected

◆ deleteObject()

template<class RCT >
void Dune::Fem::ReferenceCounterInterface< RCT >::deleteObject ( )
inline

delete to object

This method is used by the default implementation to free the object when the reference counter becomes zero.

Note
For the implementor's convenience, this method is not declared const. The caller (usually the default implementation's removeReference method) is responsible for performing a necessary const_cast.

◆ getObject() [1/2]

template<class RCT >
ObjectType & Dune::Fem::ReferenceCounterInterface< RCT >::getObject ( )
inline

access the real object (non-const version)

Sometimes the reference counter just wraps the object for which it counts references. In such cases, this method returns the wrapped object. Otherwise, the object itself may be returned.

Returns
a reference to the real object

◆ getObject() [2/2]

template<class RCT >
const ObjectType & Dune::Fem::ReferenceCounterInterface< RCT >::getObject ( ) const
inline

access the real object (const version)

Sometimes the reference counter just wraps the object for which it counts references. In such cases, this method returns the wrapped object. Otherwise, the object itself may be returned.

Returns
a constant reference to the real object

◆ removeReference()

template<class RCT >
void Dune::Fem::ReferenceCounterInterface< RCT >::removeReference ( ) const
inline

remove a reference to this object

This method should be called whenever a previously added reference to this object is released.

Note
This method is declared const, since we want to be able to remove references to const objects, too. Hence, the reference coutner must be declared mutable.

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