refPtr< T > Class Template Reference

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

Inheritance diagram for refPtr< T >:

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
 Implicit construct from literal nullptr: no managed pointer. More...
 
constexpr refPtr (T *p) noexcept
 Construct, taking ownership of the pointer. More...
 
constexpr refPtr (const T &obj) noexcept
 Implicit 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 (std::unique_ptr< T > &&rhs) noexcept
 Move construct from unique_ptr, transferring ownership. More...
 
 refPtr (const autoPtr< T > &)=delete
 No copy construct from autoPtr, also avoids implicit cast to object or pointer. More...
 
 refPtr (autoPtr< T > &&rhs) noexcept
 Move construct from autoPtr, transferring ownership. More...
 
 refPtr (const tmp< T > &rhs, bool reuse)
 Reference tmp contents or transfer ownership if requested/possible. More...
 
 refPtr (const tmp< T > &rhs)
 Reference the tmp contents. More...
 
 refPtr (tmp< T > &&rhs)
 Move construct from tmp, transfer ownership if possible. More...
 
 ~refPtr () noexcept
 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 is_reference () const noexcept
 True if this is a reference (not a pointer) 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
 Return const reference to the object or to the contents of a (non-null) managed pointer. More...
 
Tref () const
 Return non-const reference to the contents of a non-null managed pointer. More...
 
TconstCast () const
 Return non-const reference to the object or to the contents of a (non-null) managed pointer, with an additional const_cast. More...
 
refPtr< TshallowClone () const noexcept
 Return a shallow copy as a wrapped reference, preserving the const/non-const status. More...
 
Trelease () noexcept
 Release ownership and return the pointer. A no-op for reference objects (returns nullptr). More...
 
Tptr () const
 Return managed pointer for reuse, or clone() the object reference. More...
 
void clear () const noexcept
 If object pointer points to valid object: delete object and set pointer to nullptr. More...
 
void reset (T *p=nullptr) noexcept
 Delete managed pointer and set to new given pointer. More...
 
void reset (refPtr< T > &&other) noexcept
 Clear existing and transfer ownership. More...
 
void reset (const autoPtr< T > &)=delete
 No reset from autoPtr reference (potentially confusing) 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 reset (tmp< T > &rhs, bool reuse)
 Reference tmp contents or transfer pointer ownership if possible. More...
 
template<class... Args>
Templace (Args &&... args)
 Reset with emplace construction. Return reference to the new content. 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 cref (const autoPtr< T > &)=delete
 Avoid inadvertent casting (to object or pointer) More...
 
void cref (const tmp< T > &)=delete
 Avoid inadvertent casting (to object) 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 ref (const autoPtr< T > &)=delete
 Avoid inadvertent casting (to object or pointer) More...
 
void ref (const tmp< T > &)=delete
 Avoid inadvertent casting (object) 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 managed pointer. More...
 
void operator= (refPtr< T > &&other) noexcept
 Clear existing and transfer ownership. More...
 
void operator= (T *p)=delete
 No copy assignment from plain pointer (uncontrolled access) More...
 
void operator= (std::nullptr_t) noexcept
 Reset via assignment from literal nullptr. More...
 
void operator= (const autoPtr< T > &)=delete
 No copy assignment from autoPtr (can have unintended behaviour) More...
 
void operator= (autoPtr< T > &&other) noexcept
 Transfer ownership by move assignment from autoPtr. More...
 
void operator= (std::unique_ptr< T > &&other)
 Transfer ownership by move assignment from unique_ptr. More...
 
void operator= (const tmp< T > &)=delete
 No copy assignment from tmp. More...
 
void operator= (tmp< T > &&other)
 Move construct, transferring pointer ownership if possible. 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...
 

Static Public Member Functions

template<class... Args>
static refPtr< TNew (Args &&... args)
 Construct refPtr 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 49 of file HashPtrTable.H.

Member Typedef Documentation

◆ element_type

typedef T element_type

Type of object being managed or referenced.

Definition at line 86 of file refPtr.H.

◆ pointer

typedef T* pointer

Pointer to type of object being managed or referenced.

Definition at line 91 of file refPtr.H.

◆ refCount

Null reference counter class.

Definition at line 97 of file refPtr.H.

Constructor & Destructor Documentation

◆ refPtr() [1/13]

constexpr refPtr ( )
inlinenoexcept

Construct with no managed pointer.

Definition at line 37 of file refPtrI.H.

◆ refPtr() [2/13]

constexpr refPtr ( std::nullptr_t  )
inlinenoexcept

Implicit construct from literal nullptr: no managed pointer.

Definition at line 45 of file refPtrI.H.

◆ refPtr() [3/13]

constexpr refPtr ( T p)
inlineexplicitnoexcept

Construct, taking ownership of the pointer.

Definition at line 53 of file refPtrI.H.

◆ refPtr() [4/13]

constexpr refPtr ( const T obj)
inlinenoexcept

Implicit construct for a const reference to an object.

Definition at line 61 of file refPtrI.H.

◆ refPtr() [5/13]

refPtr ( refPtr< T > &&  rhs)
inlinenoexcept

Move construct, transferring ownership.

Definition at line 69 of file refPtrI.H.

◆ refPtr() [6/13]

refPtr ( const refPtr< T > &  rhs)
inline

Copy construct (shallow copy)

Definition at line 80 of file refPtrI.H.

◆ refPtr() [7/13]

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

Copy/move construct. Optionally reusing pointer.

Definition at line 103 of file refPtrI.H.

◆ refPtr() [8/13]

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

Move construct from unique_ptr, transferring ownership.

Definition at line 134 of file refPtrI.H.

◆ refPtr() [9/13]

refPtr ( const autoPtr< T > &  )
delete

No copy construct from autoPtr, also avoids implicit cast to object or pointer.

◆ refPtr() [10/13]

refPtr ( autoPtr< T > &&  rhs)
inlineexplicitnoexcept

Move construct from autoPtr, transferring ownership.

Definition at line 141 of file refPtrI.H.

◆ refPtr() [11/13]

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

Reference tmp contents or transfer ownership if requested/possible.

Definition at line 148 of file refPtrI.H.

◆ refPtr() [12/13]

refPtr ( const tmp< T > &  rhs)
inlineexplicit

Reference the tmp contents.

Definition at line 157 of file refPtrI.H.

◆ refPtr() [13/13]

refPtr ( tmp< T > &&  rhs)
inlineexplicit

Move construct from tmp, transfer ownership if possible.

Definition at line 166 of file refPtrI.H.

◆ ~refPtr()

~refPtr ( )
inlinenoexcept

Destructor: deletes managed pointer.

Definition at line 177 of file refPtrI.H.

Member Function Documentation

◆ New()

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

Construct refPtr 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.

Definition at line 187 of file refPtr.H.

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

Here is the caller graph for this function:

◆ NewFrom()

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. Future check std::enable_if + std::is_convertible ?

Definition at line 202 of file refPtr.H.

◆ typeName()

Foam::word typeName ( )
inlinestatic

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

Definition at line 28 of file refPtrI.H.

◆ good()

bool good ( ) const
inlinenoexcept

True if pointer/reference is non-null.

Definition at line 221 of file refPtr.H.

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

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 186 of file refPtrI.H.

◆ is_pointer()

bool is_pointer ( ) const
inlinenoexcept

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

Definition at line 193 of file refPtrI.H.

Referenced by refPtr< Foam::mapDistributePolyMesh >::operator=(), and regIOobject::store().

Here is the caller graph for this function:

◆ is_reference()

bool is_reference ( ) const
inlinenoexcept

True if this is a reference (not a pointer)

Definition at line 201 of file refPtrI.H.

◆ movable()

bool movable ( ) const
inlinenoexcept

True if this is a non-null managed pointer.

Definition at line 209 of file refPtrI.H.

◆ get() [1/2]

T* get ( )
inlinenoexcept

Return pointer without nullptr checking.

Definition at line 249 of file refPtr.H.

Referenced by fileOperation::fileHandler(), 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 254 of file refPtr.H.

◆ cref() [1/6]

◆ ref() [1/5]

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 230 of file refPtrI.H.

Referenced by PrecisionAdaptor< Type, InputType, Container >::commit(), mappedWallPolyPatch::mapCollocatedFaces(), mappedPolyPatch::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 278 of file refPtr.H.

Referenced by meshRefinement::findRegions().

Here is the caller graph for this function:

◆ shallowClone()

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

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

Definition at line 251 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 266 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 280 of file refPtrI.H.

Referenced by PtrList< transferModel >::push_back(), PtrDynList< Foam::profilingInformation >::push_back(), PtrList< transferModel >::set(), PtrDynList< Foam::profilingInformation >::set(), and HashPtrTable< exprResult >::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 303 of file refPtrI.H.

◆ reset() [1/6]

void reset ( T p = nullptr)
inlinenoexcept

Delete managed pointer and set to new given pointer.

Definition at line 314 of file refPtrI.H.

Referenced by meshedSurfRef::clear(), fileOperation::fileHandler(), fvExprDriver::getTopoSetLabels(), streamLineBase::initInterpolations(), refPtr< Foam::mapDistributePolyMesh >::operator=(), and meshedSurfRef::reset().

Here is the caller graph for this function:

◆ reset() [2/6]

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

Clear existing and transfer ownership.

Definition at line 323 of file refPtrI.H.

◆ reset() [3/6]

void reset ( const autoPtr< T > &  )
delete

No reset from autoPtr reference (potentially confusing)

◆ reset() [4/6]

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

Clear existing and transfer ownership from autoPtr.

Definition at line 328 of file refPtr.H.

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

Here is the caller graph for this function:

◆ reset() [5/6]

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

Clear existing and transfer ownership from unique_ptr.

Definition at line 333 of file refPtr.H.

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

Here is the caller graph for this function:

◆ reset() [6/6]

void reset ( tmp< T > &  rhs,
bool  reuse 
)
inline

Reference tmp contents or transfer pointer ownership if possible.

Definition at line 341 of file refPtrI.H.

◆ emplace()

T & emplace ( Args &&...  args)
inline

Reset with emplace construction. Return reference to the new content.

Definition at line 369 of file refPtrI.H.

◆ cref() [2/6]

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

Clear existing and set (const) reference from other.

Definition at line 379 of file refPtrI.H.

◆ cref() [3/6]

void cref ( const T obj)
inlinenoexcept

Clear existing and set (const) reference.

Definition at line 394 of file refPtrI.H.

◆ cref() [4/6]

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 403 of file refPtrI.H.

◆ cref() [5/6]

void cref ( const autoPtr< T > &  )
delete

Avoid inadvertent casting (to object or pointer)

◆ cref() [6/6]

void cref ( const tmp< T > &  )
delete

Avoid inadvertent casting (to object)

◆ ref() [2/5]

void ref ( T obj)
inlinenoexcept

Clear existing and set (non-const) reference.

Definition at line 412 of file refPtrI.H.

◆ ref() [3/5]

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 421 of file refPtrI.H.

◆ ref() [4/5]

void ref ( const autoPtr< T > &  )
delete

Avoid inadvertent casting (to object or pointer)

◆ ref() [5/5]

void ref ( const tmp< T > &  )
delete

Avoid inadvertent casting (object)

◆ swap()

void swap ( refPtr< T > &  other)
inlinenoexcept

Swaps the managed object with other.

Definition at line 430 of file refPtrI.H.

Referenced by fileOperation::fileHandler().

Here is the caller graph for this function:

◆ operator*() [1/2]

const T & operator* ( ) const
inline

Return const reference to the object.

Fatal if nothing is managed

Definition at line 447 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 460 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 481 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 495 of file refPtrI.H.

◆ operator()()

const T& operator() ( ) const
inline

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

Definition at line 435 of file refPtr.H.

◆ operator bool()

operator bool ( ) const
inlineexplicitnoexcept

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

Definition at line 443 of file refPtr.H.

◆ operator const T &()

operator const T & ( ) const
inline

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

Definition at line 448 of file refPtr.H.

References refPtr< T >::cref().

Here is the call graph for this function:

◆ operator=() [1/9]

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

Transfer ownership of managed pointer.

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

Definition at line 516 of file refPtrI.H.

◆ operator=() [2/9]

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

Clear existing and transfer ownership.

Definition at line 463 of file refPtr.H.

◆ operator=() [3/9]

void operator= ( T p)
delete

No copy assignment from plain pointer (uncontrolled access)

◆ operator=() [4/9]

void operator= ( std::nullptr_t  )
inlinenoexcept

Reset via assignment from literal nullptr.

Definition at line 473 of file refPtr.H.

◆ operator=() [5/9]

void operator= ( const autoPtr< T > &  )
delete

No copy assignment from autoPtr (can have unintended behaviour)

◆ operator=() [6/9]

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

Transfer ownership by move assignment from autoPtr.

Definition at line 483 of file refPtr.H.

◆ operator=() [7/9]

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

Transfer ownership by move assignment from unique_ptr.

Definition at line 488 of file refPtr.H.

◆ operator=() [8/9]

void operator= ( const tmp< T > &  )
delete

No copy assignment from tmp.

◆ operator=() [9/9]

void operator= ( tmp< T > &&  other)
inline

Move construct, transferring pointer ownership if possible.

Definition at line 553 of file refPtrI.H.

◆ operator tmp< T >()

operator tmp< T > ( )
inline

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

Definition at line 560 of file refPtrI.H.

◆ valid()

bool valid ( ) const
inlinenoexcept

Identical to good(), or bool operator.

Definition at line 512 of file refPtr.H.

Referenced by 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 521 of file refPtr.H.


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