refPtr< T > Class Template Reference

A class for managing references or pointers (no reference counting) More...

Inheritance diagram for refPtr< T >:
[legend]

Public Types

typedef T element_type
 Type of object being managed or referenced. More...
 
typedef Tpointer
 Pointer to type of object being managed or referenced. More...
 
typedef Foam::refCount::zero refCount
 Null reference counter class. More...
 

Public Member Functions

constexpr refPtr () noexcept
 Construct with no managed pointer. More...
 
constexpr refPtr (std::nullptr_t) noexcept
 Construct with no managed pointer (literal nullptr). More...
 
constexpr refPtr (T *p) noexcept
 Construct, taking ownership of the pointer. More...
 
 refPtr (autoPtr< T > &&ptr) noexcept
 Move construct from autoPtr, transferring ownership. More...
 
 refPtr (std::unique_ptr< T > &&ptr) noexcept
 Move construct from unique_ptr, transferring ownership. More...
 
constexpr refPtr (const T &obj) noexcept
 Construct for a const reference to an object. More...
 
 refPtr (refPtr< T > &&rhs) noexcept
 Move construct, transferring ownership. More...
 
 refPtr (const refPtr< T > &rhs)
 Copy construct (shallow copy) More...
 
 refPtr (const refPtr< T > &rhs, bool reuse)
 Copy/move construct. Optionally reusing pointer. More...
 
 ~refPtr ()
 Destructor: deletes managed pointer. More...
 
bool good () const noexcept
 True if pointer/reference is non-null. More...
 
bool is_const () const noexcept
 If the stored/referenced content is const. More...
 
bool is_pointer () const noexcept
 True if this is a managed pointer (not a reference) More...
 
bool movable () const noexcept
 True if this is a non-null managed pointer. More...
 
Tget () noexcept
 Return pointer without nullptr checking. More...
 
const Tget () const noexcept
 Return const pointer without nullptr checking. More...
 
const Tcref () const
 
Tref () const
 
TconstCast () const
 
refPtr< TshallowClone () const noexcept
 
Trelease () noexcept
 
Tptr () const
 Return managed pointer for reuse, or clone() the object reference. More...
 
void clear () const noexcept
 
void reset (refPtr< T > &&other) noexcept
 Clear existing and transfer ownership. More...
 
void reset (T *p=nullptr) noexcept
 Delete managed pointer and set to new given pointer. More...
 
void reset (autoPtr< T > &&other) noexcept
 Clear existing and transfer ownership from autoPtr. More...
 
void reset (std::unique_ptr< T > &&other)
 Clear existing and transfer ownership from unique_ptr. More...
 
void cref (const refPtr< T > &other) noexcept
 Clear existing and set (const) reference from other. More...
 
void cref (const T &obj) noexcept
 Clear existing and set (const) reference. More...
 
void cref (const T *p) noexcept
 Clear existing and set (const) reference to pointer content. More...
 
void ref (T &obj) noexcept
 Clear existing and set (non-const) reference. More...
 
void ref (T *p) noexcept
 Clear existing and set (non-const) reference to pointer content. More...
 
void swap (refPtr< T > &other) noexcept
 Swaps the managed object with other. More...
 
const Toperator* () const
 Return const reference to the object. More...
 
Toperator* ()
 Return reference to the managed object. More...
 
const Toperator-> () const
 Dereferences (const) pointer to the managed object. More...
 
Toperator-> ()
 Dereferences (non-const) pointer to the managed object. More...
 
const Toperator() () const
 Return const reference to the object - same as cref() method. More...
 
 operator bool () const noexcept
 True if pointer/reference is non-null. Same as good() More...
 
 operator const T & () const
 Cast to underlying data type, using the cref() method. More...
 
void operator= (const refPtr< T > &other)
 Transfer ownership of the managed pointer. More...
 
void operator= (refPtr< T > &&other) noexcept
 Clear existing and transfer ownership. More...
 
void operator= (T *p)
 Take ownership of the pointer. More...
 
void operator= (std::nullptr_t) noexcept
 Reset via assignment from literal nullptr. More...
 
 operator tmp< T > ()
 Conversion to tmp, releases pointer or shallow-copies reference. More...
 
bool valid () const noexcept
 Identical to good(), or bool operator. More...
 
bool empty () const noexcept
 Deprecated(2020-07) True if a null managed pointer. More...
 
template<class... Args>
Foam::refPtr< TNew (Args &&... args)
 
template<class U , class... Args>
Foam::refPtr< TNewFrom (Args &&... args)
 

Static Public Member Functions

template<class... Args>
static refPtr< TNew (Args &&... args)
 Construct refPtr of T with forwarding arguments. More...
 
template<class U , class... Args>
static refPtr< TNewFrom (Args &&... args)
 Construct refPtr from derived type with forwarding arguments. More...
 
static word typeName ()
 The type-name, constructed from type-name of T. More...
 

Detailed Description

template<class T>
class Foam::refPtr< T >

A class for managing references or pointers (no reference counting)

Source files
See also
Foam::autoPtr Foam::tmp

Definition at line 60 of file PtrList.H.

Member Typedef Documentation

◆ element_type

typedef T element_type

Type of object being managed or referenced.

Definition at line 81 of file refPtr.H.

◆ pointer

typedef T* pointer

Pointer to type of object being managed or referenced.

Definition at line 84 of file refPtr.H.

◆ refCount

Null reference counter class.

Definition at line 88 of file refPtr.H.

Constructor & Destructor Documentation

◆ refPtr() [1/9]

constexpr refPtr ( )
inlineconstexprnoexcept

Construct with no managed pointer.

Definition at line 60 of file refPtrI.H.

◆ refPtr() [2/9]

constexpr refPtr ( std::nullptr_t  )
inlineconstexprnoexcept

Construct with no managed pointer (literal nullptr).

Definition at line 68 of file refPtrI.H.

◆ refPtr() [3/9]

constexpr refPtr ( T p)
inlineexplicitconstexprnoexcept

Construct, taking ownership of the pointer.

Definition at line 76 of file refPtrI.H.

◆ refPtr() [4/9]

refPtr ( autoPtr< T > &&  ptr)
inlineexplicitnoexcept

Move construct from autoPtr, transferring ownership.

Definition at line 84 of file refPtrI.H.

◆ refPtr() [5/9]

refPtr ( std::unique_ptr< T > &&  ptr)
inlineexplicitnoexcept

Move construct from unique_ptr, transferring ownership.

Definition at line 91 of file refPtrI.H.

◆ refPtr() [6/9]

constexpr refPtr ( const T obj)
inlineconstexprnoexcept

Construct for a const reference to an object.

Definition at line 98 of file refPtrI.H.

◆ refPtr() [7/9]

refPtr ( refPtr< T > &&  rhs)
inlinenoexcept

Move construct, transferring ownership.

Definition at line 106 of file refPtrI.H.

◆ refPtr() [8/9]

refPtr ( const refPtr< T > &  rhs)
inline

Copy construct (shallow copy)

Definition at line 117 of file refPtrI.H.

◆ refPtr() [9/9]

refPtr ( const refPtr< T > &  rhs,
bool  reuse 
)
inline

Copy/move construct. Optionally reusing pointer.

Definition at line 140 of file refPtrI.H.

◆ ~refPtr()

~refPtr ( )
inline

Destructor: deletes managed pointer.

Definition at line 173 of file refPtrI.H.

Member Function Documentation

◆ New() [1/2]

static refPtr<T> New ( Args &&...  args)
inlinestatic

Construct refPtr of T with forwarding arguments.

Parameters
argslist of arguments with which an instance of T will be constructed.
Note
Similar to std::make_shared, but the overload for array types is not disabled.

Referenced by AMIInterpolation::calculate(), RASModelVariables::cloneRefPtr(), fileOperation::lookupAndCacheProcessorsPath(), and blockMesh::topology().

Here is the caller graph for this function:

◆ NewFrom() [1/2]

static refPtr<T> NewFrom ( Args &&...  args)
inlinestatic

Construct refPtr from derived type with forwarding arguments.

Parameters
argslist of arguments with which an instance of U will be constructed.
Note
Similar to New but for derived types

◆ typeName()

Foam::word typeName ( )
inlinestatic

The type-name, constructed from type-name of T.

Definition at line 51 of file refPtrI.H.

◆ good()

bool good ( ) const
inlinenoexcept

True if pointer/reference is non-null.

Definition at line 154 of file refPtr.H.

Referenced by PrecisionAdaptor< Type, InputType, Container >::commit().

Here is the caller graph for this function:

◆ is_const()

bool is_const ( ) const
inlinenoexcept

If the stored/referenced content is const.

Definition at line 157 of file refPtr.H.

◆ is_pointer()

bool is_pointer ( ) const
inlinenoexcept

True if this is a managed pointer (not a reference)

Definition at line 160 of file refPtr.H.

Referenced by regIOobject::store().

Here is the caller graph for this function:

◆ movable()

bool movable ( ) const
inlinenoexcept

True if this is a non-null managed pointer.

Definition at line 182 of file refPtrI.H.

◆ get() [1/2]

T* get ( )
inlinenoexcept

Return pointer without nullptr checking.

Definition at line 169 of file refPtr.H.

Referenced by PrecisionAdaptor< Type, InputType, Container >::set(), and regIOobject::store().

Here is the caller graph for this function:

◆ get() [2/2]

const T* get ( ) const
inlinenoexcept

Return const pointer without nullptr checking.

Definition at line 172 of file refPtr.H.

◆ cref() [1/4]

const T & cref ( ) const
inline

Return const reference to the object or to the contents of a (non-null) managed pointer.

Fatal for a null managed pointer

Definition at line 189 of file refPtrI.H.

Referenced by parseDriver::getField(), fvExprDriver::getTopoSetLabels(), fvExprDriver::getVariable(), parseDriver::getVariableIfAvailable(), PatchFunction1< Foam::Vector >::New(), Function1< Foam::Tensor >::New(), refPtr< T >::operator const T &(), refPtr< Foam::OSstream >::operator()(), and regIOobject::store().

Here is the caller graph for this function:

◆ ref() [1/3]

T & ref ( ) const
inline

Return non-const reference to the contents of a non-null managed pointer.

Fatal for a null managed pointer or if the object is const.

Definition at line 203 of file refPtrI.H.

Referenced by PrecisionAdaptor< Type, InputType, Container >::commit(), mappedPolyPatch::mapCollocatedFaces(), mappedWallPolyPatch::mapCollocatedFaces(), and cyclicPolyPatch::mapCollocatedFaces().

Here is the caller graph for this function:

◆ constCast()

T & constCast ( ) const
inline

Return non-const reference to the object or to the contents of a (non-null) managed pointer, with an additional const_cast.

Fatal for a null managed pointer.

Definition at line 224 of file refPtrI.H.

◆ shallowClone()

Foam::refPtr< T > shallowClone ( ) const
inlinenoexcept

Return a shallow copy as a wrapped reference, preserving the const/non-const status.

Definition at line 231 of file refPtrI.H.

◆ release()

T * release ( )
inlinenoexcept

Release ownership and return the pointer. A no-op for reference objects (returns nullptr).

Remarks
Method naming consistent with std::unique_ptr

Definition at line 246 of file refPtrI.H.

Referenced by regIOobject::store().

Here is the caller graph for this function:

◆ ptr()

T * ptr ( ) const
inline

Return managed pointer for reuse, or clone() the object reference.

Remarks
Method naming consistent with Foam::tmp

Definition at line 260 of file refPtrI.H.

Referenced by PtrList< transferModel >::append(), PtrDynList< Foam::profilingInformation >::append(), PtrList< transferModel >::set(), and PtrDynList< Foam::profilingInformation >::set().

Here is the caller graph for this function:

◆ clear()

void clear ( ) const
inlinenoexcept

If object pointer points to valid object: delete object and set pointer to nullptr

Definition at line 283 of file refPtrI.H.

◆ reset() [1/4]

void reset ( refPtr< T > &&  other)
inlinenoexcept

Clear existing and transfer ownership.

Definition at line 303 of file refPtrI.H.

Referenced by fvExprDriver::getTopoSetLabels().

Here is the caller graph for this function:

◆ reset() [2/4]

void reset ( T p = nullptr)
inlinenoexcept

Delete managed pointer and set to new given pointer.

Definition at line 294 of file refPtrI.H.

◆ reset() [3/4]

void reset ( autoPtr< T > &&  other)
inlinenoexcept

Clear existing and transfer ownership from autoPtr.

Definition at line 217 of file refPtr.H.

Referenced by refPtr< Foam::OSstream >::reset().

Here is the caller graph for this function:

◆ reset() [4/4]

void reset ( std::unique_ptr< T > &&  other)
inline

Clear existing and transfer ownership from unique_ptr.

Definition at line 220 of file refPtr.H.

Referenced by refPtr< Foam::OSstream >::reset().

Here is the caller graph for this function:

◆ cref() [2/4]

void cref ( const refPtr< T > &  other)
inlinenoexcept

Clear existing and set (const) reference from other.

Definition at line 320 of file refPtrI.H.

◆ cref() [3/4]

void cref ( const T obj)
inlinenoexcept

Clear existing and set (const) reference.

Definition at line 334 of file refPtrI.H.

◆ cref() [4/4]

void cref ( const T p)
inlinenoexcept

Clear existing and set (const) reference to pointer content.

The pointer can be null, which is handled like a clear().

Definition at line 343 of file refPtrI.H.

◆ ref() [2/3]

void ref ( T obj)
inlinenoexcept

Clear existing and set (non-const) reference.

Definition at line 352 of file refPtrI.H.

◆ ref() [3/3]

void ref ( T p)
inlinenoexcept

Clear existing and set (non-const) reference to pointer content.

The pointer can be null, which is handled like a clear().

Definition at line 361 of file refPtrI.H.

◆ swap()

void swap ( refPtr< T > &  other)
inlinenoexcept

Swaps the managed object with other.

Definition at line 370 of file refPtrI.H.

◆ operator*() [1/2]

const T & operator* ( ) const
inline

Return const reference to the object.

Fatal if nothing is managed

Definition at line 387 of file refPtrI.H.

◆ operator*() [2/2]

T & operator* ( )
inline

Return reference to the managed object.

Fatal if nothing is managed or if the object is const.

Definition at line 400 of file refPtrI.H.

◆ operator->() [1/2]

const T * operator-> ( ) const
inline

Dereferences (const) pointer to the managed object.

Fatal if nothing is managed.

Definition at line 421 of file refPtrI.H.

◆ operator->() [2/2]

T * operator-> ( )
inline

Dereferences (non-const) pointer to the managed object.

Fatal if nothing is managed or if the object is const.

Definition at line 435 of file refPtrI.H.

◆ operator()()

const T& operator() ( ) const
inline

Return const reference to the object - same as cref() method.

Definition at line 265 of file refPtr.H.

◆ operator bool()

operator bool ( ) const
inlineexplicitnoexcept

True if pointer/reference is non-null. Same as good()

Definition at line 271 of file refPtr.H.

◆ operator const T &()

operator const T & ( ) const
inline

Cast to underlying data type, using the cref() method.

Definition at line 274 of file refPtr.H.

References refPtr< T >::cref().

Here is the call graph for this function:

◆ operator=() [1/4]

void operator= ( const refPtr< T > &  other)
inline

Transfer ownership of the managed pointer.

Fatal for a null managed pointer or if the object is const.

Definition at line 456 of file refPtrI.H.

◆ operator=() [2/4]

void operator= ( refPtr< T > &&  other)
inlinenoexcept

Clear existing and transfer ownership.

Definition at line 490 of file refPtrI.H.

◆ operator=() [3/4]

void operator= ( T p)
inline

Take ownership of the pointer.

Fatal for a null pointer

Definition at line 507 of file refPtrI.H.

◆ operator=() [4/4]

void operator= ( std::nullptr_t  )
inlinenoexcept

Reset via assignment from literal nullptr.

Definition at line 522 of file refPtrI.H.

◆ operator tmp< T >()

operator tmp< T > ( )
inline

Conversion to tmp, releases pointer or shallow-copies reference.

Definition at line 529 of file refPtrI.H.

◆ valid()

bool valid ( ) const
inlinenoexcept

Identical to good(), or bool operator.

Definition at line 300 of file refPtr.H.

Referenced by parseDriver::getField(), fvExprDriver::getTopoSetLabels(), fvExprDriver::getVariable(), and parseDriver::getVariableIfAvailable().

Here is the caller graph for this function:

◆ empty()

bool empty ( ) const
inlinenoexcept

Deprecated(2020-07) True if a null managed pointer.

Deprecated:
(2020-07) - use bool operator

Definition at line 306 of file refPtr.H.

◆ New() [2/2]

Foam::refPtr<T> New ( Args &&...  args)
inline

Definition at line 36 of file refPtrI.H.

◆ NewFrom() [2/2]

Foam::refPtr<T> NewFrom ( Args &&...  args)
inline

Definition at line 44 of file refPtrI.H.


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