DUNE-FEM (unstable)
interface for objects capable of reference counting More...
#include <dune/fem/storage/referencecounter.hh>
Public Member Functions | |
void | addReference () const |
add a reference to this object More... | |
void | deleteObject () |
delete to object More... | |
const ObjectType & | getObject () const |
access the real object (const version) More... | |
ObjectType & | getObject () |
access the real object (non-const version) More... | |
void | removeReference () const |
remove a reference to this object More... | |
Detailed Description
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()
|
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()
|
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]
|
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]
|
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()
|
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:
- dune/fem/storage/referencecounter.hh