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
 Default construct, no managed pointer. More...
 
constexpr refPtr (std::nullptr_t) noexcept
 Construct with no managed pointer. 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. More...
 
 refPtr (const refPtr< T > &rhs, bool reuse)
 Copy/move construct. Optionally reusing pointer. More...
 
 ~refPtr ()
 Destructor: deletes managed pointer. More...
 
bool empty () const noexcept
 Deprecated(2020-07) True if a null managed pointer. More...
 
bool valid () const noexcept
 True for non-null pointer/reference. More...
 
bool is_pointer () const noexcept
 True if this is a managed pointer (not a reference) More...
 
bool isTmp () const noexcept
 Identical to is_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
 
Tref () const
 
TconstCast () const
 
Tptr () const
 Return managed pointer for reuse, or clone() the object reference. More...
 
void clear () const noexcept
 
void reset (T *p=nullptr) noexcept
 Delete managed temporary object 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 reset (refPtr< T > &&other) noexcept
 Clear existing and transfer ownership. More...
 
void cref (const T &obj) noexcept
 Delete managed temporary object and set to (const) reference. More...
 
void ref (T &obj) noexcept
 Delete managed temporary object and set to (non-const) reference. More...
 
void swap (refPtr< T > &other) noexcept
 Swaps the managed object with other. 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 const T & () const
 Cast to underlying data type, using the cref() method. More...
 
 operator bool () const noexcept
 Non-null pointer/reference : valid() 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...
 
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

Default construct, 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.

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.

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 171 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(), and fileOperation::lookupAndCacheProcessorsPath().

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.

◆ empty()

bool empty ( ) const
inlinenoexcept

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

Deprecated:
(2020-07) - use bool operator

Definition at line 157 of file refPtr.H.

◆ valid()

bool valid ( ) const
inlinenoexcept

True for non-null pointer/reference.

Definition at line 160 of file refPtr.H.

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

Here is the caller graph for this function:

◆ is_pointer()

bool is_pointer ( ) const
inlinenoexcept

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

Definition at line 163 of file refPtr.H.

Referenced by regIOobject::store().

Here is the caller graph for this function:

◆ isTmp()

bool isTmp ( ) const
inlinenoexcept

Identical to is_pointer()

Definition at line 166 of file refPtr.H.

◆ movable()

bool movable ( ) const
inlinenoexcept

True if this is a non-null managed pointer.

Definition at line 180 of file refPtrI.H.

◆ get() [1/2]

T* get ( )
inlinenoexcept

Return pointer without nullptr checking.

Definition at line 175 of file refPtr.H.

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

◆ cref() [1/2]

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

Referenced by parseDriver::getField(), fvExprDriver::getVariable(), parseDriver::getVariableIfAvailable(), refPtr< T >::operator const T &(), refPtr< Foam::PrimitivePatch >::operator()(), and regIOobject::store().

Here is the caller graph for this function:

◆ ref() [1/2]

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

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

◆ ptr()

T * ptr ( ) const
inline

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

Definition at line 235 of file refPtrI.H.

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

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

◆ reset() [1/4]

void reset ( T p = nullptr)
inlinenoexcept

Delete managed temporary object and set to new given pointer.

Definition at line 269 of file refPtrI.H.

◆ reset() [2/4]

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

Clear existing and transfer ownership from autoPtr.

Definition at line 209 of file refPtr.H.

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

Here is the caller graph for this function:

◆ reset() [3/4]

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

Clear existing and transfer ownership from unique_ptr.

Definition at line 212 of file refPtr.H.

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

Here is the caller graph for this function:

◆ reset() [4/4]

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

Clear existing and transfer ownership.

Definition at line 278 of file refPtrI.H.

◆ cref() [2/2]

void cref ( const T obj)
inlinenoexcept

Delete managed temporary object and set to (const) reference.

Definition at line 295 of file refPtrI.H.

◆ ref() [2/2]

void ref ( T obj)
inlinenoexcept

Delete managed temporary object and set to (non-const) reference.

Definition at line 304 of file refPtrI.H.

◆ swap()

void swap ( refPtr< T > &  other)
inlinenoexcept

Swaps the managed object with other.

Definition at line 313 of file refPtrI.H.

◆ operator->() [1/2]

const T * operator-> ( ) const
inline

Dereferences (const) pointer to the managed object.

Fatal for a null managed pointer.

Definition at line 330 of file refPtrI.H.

◆ operator->() [2/2]

T * operator-> ( )
inline

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

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

Definition at line 347 of file refPtrI.H.

◆ operator()()

const T& operator() ( ) const
inline

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

Definition at line 238 of file refPtr.H.

◆ operator const T &()

operator const T & ( ) const
inline

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

Definition at line 241 of file refPtr.H.

References refPtr< T >::cref().

Here is the call graph for this function:

◆ operator bool()

operator bool ( ) const
inlineexplicitnoexcept

Non-null pointer/reference : valid()

Definition at line 244 of file refPtr.H.

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

◆ operator=() [2/4]

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

Clear existing and transfer ownership.

Definition at line 405 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 422 of file refPtrI.H.

◆ operator=() [4/4]

void operator= ( std::nullptr_t  )
inlinenoexcept

Reset via assignment from literal nullptr.

Definition at line 437 of file refPtrI.H.

◆ operator tmp< T >()

operator tmp< T > ( )
inline

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

Definition at line 444 of file refPtrI.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: