Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Arcane::Ref< InstanceType > Class Template Reference

Reference to an instance. More...

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

Inheritance diagram for Arcane::Ref< InstanceType >:
Collaboration diagram for Arcane::Ref< InstanceType >:

Public Member Functions

template<typename T>
 Ref (const Ref< T > &rhs) noexcept
 Constructs a reference from another reference of a compatible type.
 Ref (const ThatClass &rhs)=default
ThatClass & operator= (const ThatClass &rhs)=default
Public Member Functions inherited from Arcane::RefImpl< InstanceType, Ref< InstanceType >, RefTraits< InstanceType >::TagId >
 RefImpl (const Ref< T > &rhs) noexcept
 Constructs a reference from another reference of a compatible type.
 RefImpl (const ThatClass &rhs)=default
ThatClass & operator= (const ThatClass &rhs)=default
 operator bool () const
InstanceType * get () const
 Associated instance or nullptr if none.
bool isNull () const
 Indicates if the counter references a non-null instance.
InstanceType * operator-> () const
void reset ()
 Positions the instance to the null pointer.
InstanceType * _release ()
 Releases the reference counter pointer without destroying it. This is only allowed if the implementation uses 'std::shared_ptr'.
const ImplType & _internalInstance () const

Static Public Member Functions

static ThatClass create (InstanceType *t)
 Creates a reference from the instance t.
template<typename PointerType, typename... Args>
static Ref< InstanceType > createRef (Args &&... args)
static ThatClass createWithHandle (InstanceType *t, Internal::ExternalRef handle)
 Creates a reference from an instance having an external reference.
static ThatClass _createNoDestroy (InstanceType *t)

Private Types

using Base = RefImpl<InstanceType, Ref<InstanceType>, RefTraits<InstanceType>::TagId>
using ImplType = Base::ImplType
using ThatClass = Ref<InstanceType>
template<typename... _Args>
using _IsRefConstructible = typename std::enable_if<std::is_constructible<ImplType, _Args...>::value>::type

Private Member Functions

 Ref (InstanceType *t)
 Ref (InstanceType *t, Internal::ExternalRef handle)
 Ref (InstanceType *t, bool no_destroy)

Static Private Member Functions

static void _destroyInstance (InstanceType *t)

Private Attributes

friend Base

Additional Inherited Members

Public Types inherited from Arcane::RefImpl< InstanceType, Ref< InstanceType >, RefTraits< InstanceType >::TagId >
using ThatClass
using ImplType
Static Public Attributes inherited from Arcane::RefImpl< InstanceType, Ref< InstanceType >, RefTraits< InstanceType >::TagId >
static constexpr int RefType

Detailed Description

template<typename InstanceType>
class Arcane::Ref< InstanceType >

Reference to an instance.

This class uses a reference counter to manage the lifetime of a C++ instance. It works similarly to std::shared_ptr.

When the last instance of this class is destroyed, the referenced instance is destroyed. The way the associated instance is destroyed is specified when creating the first reference via a call to one of the methods create() or createWithHandle().

There are two possible implementations for counting references. By default, 'std::shared_ptr' is used. It is also possible to use an internal reference counter in the class, which allows compatibility with the ReferenceCounter class and also allows retrieving a reference from the instance itself. This second implementation is accessible by specializing the type RefTraits so that it defines a ReferenceCounterTagType equal to ReferenceCounterTag.

Definition at line 323 of file arccore/src/base/arccore/base/Ref.h.

Member Typedef Documentation

◆ _IsRefConstructible

template<typename InstanceType>
template<typename... _Args>
using Arcane::Ref< InstanceType >::_IsRefConstructible = typename std::enable_if<std::is_constructible<ImplType, _Args...>::value>::type
private

Definition at line 332 of file arccore/src/base/arccore/base/Ref.h.

◆ Base

template<typename InstanceType>
using Arcane::Ref< InstanceType >::Base = RefImpl<InstanceType, Ref<InstanceType>, RefTraits<InstanceType>::TagId>
private

Definition at line 326 of file arccore/src/base/arccore/base/Ref.h.

◆ ImplType

template<typename InstanceType>
using Arcane::Ref< InstanceType >::ImplType = Base::ImplType
private

Definition at line 327 of file arccore/src/base/arccore/base/Ref.h.

◆ ThatClass

template<typename InstanceType>
using Arcane::Ref< InstanceType >::ThatClass = Ref<InstanceType>
private

Definition at line 328 of file arccore/src/base/arccore/base/Ref.h.

Constructor & Destructor Documentation

◆ Ref() [1/4]

template<typename InstanceType>
Arcane::Ref< InstanceType >::Ref ( InstanceType * t)
inlineexplicitprivate

Definition at line 336 of file arccore/src/base/arccore/base/Ref.h.

◆ Ref() [2/4]

template<typename InstanceType>
Arcane::Ref< InstanceType >::Ref ( InstanceType * t,
Internal::ExternalRef< InstanceType > handle )
inlineprivate

Definition at line 339 of file arccore/src/base/arccore/base/Ref.h.

◆ Ref() [3/4]

template<typename InstanceType>
Arcane::Ref< InstanceType >::Ref ( InstanceType * t,
bool no_destroy )
inlineprivate

Definition at line 342 of file arccore/src/base/arccore/base/Ref.h.

◆ Ref() [4/4]

template<typename InstanceType>
template<typename T>
Arcane::Ref< InstanceType >::Ref ( const Ref< T > & rhs)
inlinenoexcept

Constructs a reference from another reference of a compatible type.

Conversion is allowed if an instance of 'ImplType' can be constructed from an instance of Ref<T>::ImplType.

Definition at line 356 of file arccore/src/base/arccore/base/Ref.h.

Member Function Documentation

◆ _createNoDestroy()

template<typename InstanceType>
ThatClass Arcane::Ref< InstanceType >::_createNoDestroy ( InstanceType * t)
inlinestatic

Definition at line 398 of file arccore/src/base/arccore/base/Ref.h.

◆ _destroyInstance()

template<typename InstanceType>
void Arcane::Ref< InstanceType >::_destroyInstance ( InstanceType * t)
inlinestaticprivate

Definition at line 405 of file arccore/src/base/arccore/base/Ref.h.

◆ create()

template<typename InstanceType>
ThatClass Arcane::Ref< InstanceType >::create ( InstanceType * t)
inlinestatic

Creates a reference from the instance t.

This method is internal to Arccore.

The instance t must have been created by the 'operator new' operator and will be destroyed by the 'operator delete' operator

Definition at line 375 of file arccore/src/base/arccore/base/Ref.h.

Referenced by Arcane::makeRef(), and Arcane::makeRefFromInstance().

Here is the caller graph for this function:

◆ createRef()

template<typename InstanceType>
template<typename PointerType, typename... Args>
Ref< InstanceType > Arcane::Ref< InstanceType >::createRef ( Args &&... args)
inlinestatic

Definition at line 382 of file arccore/src/base/arccore/base/Ref.h.

◆ createWithHandle()

template<typename InstanceType>
ThatClass Arcane::Ref< InstanceType >::createWithHandle ( InstanceType * t,
Internal::ExternalRef< InstanceType > handle )
inlinestatic

Creates a reference from an instance having an external reference.

Definition at line 393 of file arccore/src/base/arccore/base/Ref.h.

Member Data Documentation

◆ Base

template<typename InstanceType>
friend Arcane::Ref< InstanceType >::Base
private

Definition at line 329 of file arccore/src/base/arccore/base/Ref.h.


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