Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Arcane::CheckedPointer< T > Class Template Reference

Encapsulation of a pointer. More...

#include <arccore/base/CheckedPointer.h>

Public Member Functions

 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

Protected Member Functions

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

T * m_value
 Pointer to the referenced object.

Friends

template<typename T2>
bool operator== (const CheckedPointer< T > &v1, const CheckedPointer< T2 > &v2)
 Compares the objects referenced by v1 and v2 The comparison is done pointer by pointer.
template<typename T2>
bool operator!= (const CheckedPointer< T > &v1, const CheckedPointer< T2 > &v2)
 Compares the objects referenced by v1 and v2 The comparison is done pointer by pointer.

Detailed Description

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

Encapsulation of a pointer.

This class does nothing special other than encapsulating a pointer of any type. It serves as a base class for other classes that provide more advanced features like AutoRefT.

To prevent accidental copies, the copy constructor and copy operators are protected.

In debug mode, it checks that a null pointer is not accessed.

The template parameter does not need to be defined. This class can therefore be instantiated for an opaque type.

Definition at line 44 of file CheckedPointer.h.

Constructor & Destructor Documentation

◆ CheckedPointer() [1/4]

template<class T>
Arcane::CheckedPointer< T >::CheckedPointer ( const CheckedPointer< T > & from)
inlineprotected

Constructs a reference referring to from.

Definition at line 70 of file CheckedPointer.h.

References CheckedPointer(), and m_value.

Referenced by CheckedPointer(), CheckedPointer(), operator!=, operator=(), operator=(), and operator==.

◆ CheckedPointer() [2/4]

template<class T>
template<typename T2>
Arcane::CheckedPointer< T >::CheckedPointer ( const CheckedPointer< T2 > & from)
inlineprotected

Constructs a reference referring to from.

Definition at line 76 of file CheckedPointer.h.

References CheckedPointer(), and m_value.

◆ CheckedPointer() [3/4]

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

Constructs an instance without a reference.

Definition at line 83 of file CheckedPointer.h.

References m_value.

◆ CheckedPointer() [4/4]

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

Constructs an instance referring to t.

Definition at line 88 of file CheckedPointer.h.

References m_value.

Member Function Documentation

◆ get()

template<class T>
T * Arcane::CheckedPointer< T >::get ( ) const
inline

Returns the object referenced by the instance.

Warning
In general, caution must be used when using this function and the returned pointer should not be retained.

Definition at line 124 of file CheckedPointer.h.

References m_value.

Referenced by operator!=, and operator==.

◆ isNull()

template<class T>
bool Arcane::CheckedPointer< T >::isNull ( ) const
inline

Definition at line 129 of file CheckedPointer.h.

◆ operator bool()

template<class T>
Arcane::CheckedPointer< T >::operator bool ( ) const
inlineexplicit

Definition at line 94 of file CheckedPointer.h.

◆ operator*()

template<class T>
T & Arcane::CheckedPointer< T >::operator* ( ) const
inline

Returns the object referenced by the instance.

Definition at line 109 of file CheckedPointer.h.

References Arcane::arccoreNullPointerError(), and m_value.

◆ operator->()

template<class T>
T * Arcane::CheckedPointer< T >::operator-> ( ) const
inline

Returns the object referenced by the instance.

Definition at line 99 of file CheckedPointer.h.

References Arcane::arccoreNullPointerError(), and m_value.

◆ operator=() [1/3]

template<class T>
const CheckedPointer< T > & Arcane::CheckedPointer< T >::operator= ( const CheckedPointer< T > & from)
inlineprotected

Copy operator.

Definition at line 49 of file CheckedPointer.h.

References CheckedPointer(), and m_value.

◆ operator=() [2/3]

template<class T>
template<typename T2>
const CheckedPointer< T > & Arcane::CheckedPointer< T >::operator= ( const CheckedPointer< T2 > & from)
inlineprotected

Definition at line 56 of file CheckedPointer.h.

◆ operator=() [3/3]

template<class T>
const CheckedPointer< T > & Arcane::CheckedPointer< T >::operator= ( T * new_value)
inlineprotected

Assigns the value new_value to the instance.

Definition at line 63 of file CheckedPointer.h.

References CheckedPointer(), and m_value.

◆ operator!=

template<class T>
template<typename T2>
bool operator!= ( const CheckedPointer< T > & v1,
const CheckedPointer< T2 > & v2 )
friend

Compares the objects referenced by v1 and v2 The comparison is done pointer by pointer.

Return values
falseif they are equal
trueotherwise

Definition at line 153 of file CheckedPointer.h.

References CheckedPointer(), and get().

◆ operator==

template<class T>
template<typename T2>
bool operator== ( const CheckedPointer< T > & v1,
const CheckedPointer< T2 > & v2 )
friend

Compares the objects referenced by v1 and v2 The comparison is done pointer by pointer.

Return values
trueif they are equal
falseotherwise

Definition at line 141 of file CheckedPointer.h.

References CheckedPointer(), and get().

Member Data Documentation

◆ m_value

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

Pointer to the referenced object.

Definition at line 160 of file CheckedPointer.h.

Referenced by CheckedPointer(), CheckedPointer(), CheckedPointer(), CheckedPointer(), get(), operator*(), operator->(), operator=(), and operator=().


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