DUNE-FEM (unstable)

Dune::Fem::ReferenceCounterInterface< RCT > Class Template Reference

interface for objects capable of reference counting More...

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

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 More...
 
void deleteObject ()
 delete to object More...
 
const ObjectTypegetObject () const
 access the real object (const version) More...
 
ObjectTypegetObject ()
 access the real object (non-const version) More...
 
void removeReference () const
 remove a reference to this object More...
 

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

References Dune::Fem::ReferenceCounterInterface< RCT >::addReference(), and CHECK_AND_CALL_INTERFACE_IMPLEMENTATION.

Referenced by Dune::Fem::ReferenceCounterInterface< RCT >::addReference().

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

References CHECK_AND_CALL_INTERFACE_IMPLEMENTATION, and Dune::Fem::ReferenceCounterInterface< RCT >::deleteObject().

Referenced by Dune::Fem::ReferenceCounterInterface< RCT >::deleteObject().

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

References CHECK_AND_CALL_INTERFACE_IMPLEMENTATION, and Dune::Fem::ReferenceCounterInterface< RCT >::removeReference().

Referenced by Dune::Fem::ReferenceCounterInterface< RCT >::removeReference().


The documentation for this class was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)