Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Arcane::ReferenceCounter< T > Class Template Reference

Encapsulation of a pointer with a reference counter. More...

#include </__w/arcaneframework.github.io/arcaneframework.github.io/framework/arccore/src/base/arccore/base/ReferenceCounter.h>

Inheritance diagram for Arcane::ReferenceCounter< T >:
Collaboration diagram for Arcane::ReferenceCounter< T >:

Public Types

typedef CheckedPointer< T > BaseClass
 Type of the base class.

Public Member Functions

 ReferenceCounter ()
 Constructs an instance without a reference.
 ReferenceCounter (T *t)
 Constructs an instance referencing t.
 ReferenceCounter (const ReferenceCounter< T > &from)
 Constructs a reference referencing from.
ReferenceCounter< T > & operator= (const ReferenceCounter< T > &from)
 Copy operator.
ReferenceCounter< T > & operator= (T *new_value)
 Assigns the value new_value to the instance.
 ~ReferenceCounter ()
 Destructor. Decrements the reference counter of the pointed object.
Public Member Functions inherited from Arcane::CheckedPointer< T >
 CheckedPointer ()
 Constructs an instance without a reference.
 CheckedPointer (T *t)
 Constructs an instance referring to t.
 operator bool () const
T * operator-> () const
 Returns the object referenced by the instance.
T & operator* () const
 Returns the object referenced by the instance.
T * get () const
 Returns the object referenced by the instance.
bool isNull () const

Public Attributes

T * m_value
 Pointer to the referenced object.

Private Member Functions

void _removeRef ()
 Removes a reference to the encapsulated object if not null.
void _changeValue (T *new_value)
 Changes the referenced object to new_value.

Additional Inherited Members

Protected Member Functions inherited from Arcane::CheckedPointer< T >
const CheckedPointer< T > & operator= (const CheckedPointer< T > &from)
 Copy operator.
template<typename T2>
const CheckedPointer< T > & operator= (const CheckedPointer< T2 > &from)
const CheckedPointer< T > & operator= (T *new_value)
 Assigns the value new_value to the instance.
 CheckedPointer (const CheckedPointer< T > &from)
 Constructs a reference referring to from.
template<typename T2>
 CheckedPointer (const CheckedPointer< T2 > &from)
 Constructs a reference referring to from.
Protected Attributes inherited from Arcane::CheckedPointer< T >
T * m_value
 Pointer to the referenced object.

Detailed Description

template<class T>
class Arcane::ReferenceCounter< T >

Encapsulation of a pointer with a reference counter.

This class holds a pointer of a type that must implement the following methods:

  • addReference() to add a reference
  • removeReference() to remove a reference.

Unlike std::shared_ptr, the reference counter is managed internally by the type T. This class performs no action based on the reference counter value. the eventual destruction of the object when the reference counter reaches zero is handled by the object itself.

Definition at line 44 of file ReferenceCounter.h.

Member Typedef Documentation

◆ BaseClass

template<class T>
typedef CheckedPointer<T> Arcane::ReferenceCounter< T >::BaseClass

Type of the base class.

Definition at line 50 of file ReferenceCounter.h.

Constructor & Destructor Documentation

◆ ReferenceCounter() [1/3]

template<class T>
Arcane::ReferenceCounter< T >::ReferenceCounter ( )
inline

Constructs an instance without a reference.

Definition at line 57 of file ReferenceCounter.h.

◆ ReferenceCounter() [2/3]

template<class T>
Arcane::ReferenceCounter< T >::ReferenceCounter ( T * t)
inlineexplicit

Constructs an instance referencing t.

Definition at line 61 of file ReferenceCounter.h.

◆ ReferenceCounter() [3/3]

template<class T>
Arcane::ReferenceCounter< T >::ReferenceCounter ( const ReferenceCounter< T > & from)
inline

Constructs a reference referencing from.

Definition at line 67 of file ReferenceCounter.h.

◆ ~ReferenceCounter()

template<class T>
Arcane::ReferenceCounter< T >::~ReferenceCounter ( )
inline

Destructor. Decrements the reference counter of the pointed object.

Definition at line 88 of file ReferenceCounter.h.

Member Function Documentation

◆ _changeValue()

template<class T>
void Arcane::ReferenceCounter< T >::_changeValue ( T * new_value)
inlineprivate

Changes the referenced object to new_value.

Definition at line 99 of file ReferenceCounter.h.

Referenced by Arcane::ReferenceCounter< IModuleFactoryInfo >::operator=(), Arcane::ReferenceCounter< IModuleFactoryInfo >::operator=(), Arcane::ReferenceCounter< IModuleFactoryInfo >::ReferenceCounter(), and Arcane::ReferenceCounter< IModuleFactoryInfo >::ReferenceCounter().

Here is the caller graph for this function:

◆ _removeRef()

template<class T>
void Arcane::ReferenceCounter< T >::_removeRef ( )
inlineprivate

Removes a reference to the encapsulated object if not null.

Definition at line 93 of file ReferenceCounter.h.

Referenced by Arcane::ReferenceCounter< IModuleFactoryInfo >::_changeValue(), and Arcane::ReferenceCounter< IModuleFactoryInfo >::~ReferenceCounter().

Here is the caller graph for this function:

◆ operator=() [1/2]

template<class T>
ReferenceCounter< T > & Arcane::ReferenceCounter< T >::operator= ( const ReferenceCounter< T > & from)
inline

Copy operator.

Definition at line 74 of file ReferenceCounter.h.

◆ operator=() [2/2]

template<class T>
ReferenceCounter< T > & Arcane::ReferenceCounter< T >::operator= ( T * new_value)
inline

Assigns the value new_value to the instance.

Definition at line 81 of file ReferenceCounter.h.

Member Data Documentation

◆ m_value

template<class T>
T* Arcane::CheckedPointer< T >::m_value

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