autoPtr< T > Class Template Reference

Pointer management similar to std::unique_ptr, with some additional methods and type checking. More...

Public Types

typedef T element_type
 Type of object being managed. More...
 
typedef Tpointer
 Pointer to type of object being managed. More...
 

Public Member Functions

constexpr autoPtr () noexcept
 Construct with no managed object. More...
 
constexpr autoPtr (std::nullptr_t) noexcept
 Construct with no managed object (literal nullptr). More...
 
 autoPtr (T *p) noexcept
 Construct, taking ownership of the pointer. More...
 
 autoPtr (autoPtr< T > &&ap) noexcept
 Move construct, transferring ownership. More...
 
template<class U >
 autoPtr (autoPtr< U > &&ap)
 Move construct, transferring ownership from derived type. More...
 
 autoPtr (const autoPtr< T > &ap) noexcept
 A move construct disguised as a copy construct (transfers ownership) More...
 
 ~autoPtr () noexcept
 Deletes the managed object if such is present. More...
 
bool empty () const noexcept
 True if the managed pointer is null. More...
 
bool valid () const noexcept
 True if the managed pointer is non-null. More...
 
Tget () noexcept
 Return pointer to managed object without nullptr checking. More...
 
const Tget () const noexcept
 Return const pointer to managed object without nullptr checking. More...
 
Tref ()
 Return reference to the managed object without nullptr checking. More...
 
Trelease () noexcept
 Return pointer to the managed object and release ownership. More...
 
Tptr () noexcept
 
void clear () noexcept
 Delete managed object and set pointer to nullptr. More...
 
void reset (T *p=nullptr) noexcept
 Delete managed object and set to new given pointer. More...
 
void reset (autoPtr< T > &&ap) noexcept
 Delete managed object and set to new given pointer. More...
 
void swap (autoPtr< T > &other) noexcept
 Swaps the managed object with other autoPtr. More...
 
template<class... Args>
autoPtr< Tclone (Args &&... args) const
 Construct copy by invoking clone on underlying managed object. More...
 
Toperator* ()
 Return reference to the managed object. More...
 
const Toperator* () const
 Return const reference to the object. More...
 
Toperator-> ()
 Dereferences (non-const) pointer to the managed object. More...
 
const Toperator-> () const
 Dereferences (const) pointer to the managed object. More...
 
Toperator() ()
 Return reference to the object data. More...
 
const Toperator() () const
 Return const reference to the object data. More...
 
 operator const T & () const
 Deprecated(2019-01) Automatic cast conversion to underlying type. More...
 
 operator const T * () const noexcept
 Cast to pointer type. More...
 
 operator T* () noexcept
 Cast to pointer type. More...
 
 operator bool () const noexcept
 True if the managed pointer is non-null. More...
 
void operator= (autoPtr< T > &&ap) noexcept
 Transfer object ownership from parameter. More...
 
template<class U >
void operator= (autoPtr< U > &&ap) noexcept
 Transfer object ownership from parameter. More...
 
void operator= (const autoPtr< T > &ap) noexcept
 A move assignment disguised as a copy assignment. More...
 
void operator= (std::nullptr_t) noexcept
 Clear via assignment from literal nullptr. More...
 
void set (T *p) noexcept
 Deprecated(2018-02) Identical to reset(). More...
 
void operator= (T *p)=delete
 Deprecated(2018-02) No copy assignment from plain pointer. More...
 
template<class... Args>
Foam::autoPtr< TNew (Args &&... args)
 
template<class U , class... Args>
Foam::autoPtr< TNewFrom (Args &&... args)
 
template<class... Args>
Foam::autoPtr< Tclone (Args &&... args) const
 

Static Public Member Functions

template<class... Args>
static autoPtr< TNew (Args &&... args)
 Construct autoPtr of T with forwarding arguments. More...
 
template<class U , class... Args>
static autoPtr< TNewFrom (Args &&... args)
 Construct autoPtr from derived type with forwarding arguments. More...
 

Detailed Description

template<class T>
class Foam::autoPtr< T >

Pointer management similar to std::unique_ptr, with some additional methods and type checking.

Note
Parts of the interface now mirror std::unique_ptr, but since it pre-dates both C++11 and std::unique_ptr, it has some additional idiosyncrasies. The const-reference constructors and assignment operators actually use move semantics to allow their participation in default constructible, default assignable classes.
Source files

Definition at line 52 of file HashPtrTable.H.

Member Typedef Documentation

◆ element_type

typedef T element_type

Type of object being managed.

Definition at line 75 of file autoPtr.H.

◆ pointer

typedef T* pointer

Pointer to type of object being managed.

Definition at line 78 of file autoPtr.H.

Constructor & Destructor Documentation

◆ autoPtr() [1/6]

constexpr autoPtr ( )
inlineconstexprnoexcept

Construct with no managed object.

Definition at line 52 of file autoPtrI.H.

◆ autoPtr() [2/6]

constexpr autoPtr ( std::nullptr_t  )
inlineconstexprnoexcept

Construct with no managed object (literal nullptr).

Definition at line 59 of file autoPtrI.H.

◆ autoPtr() [3/6]

autoPtr ( T p)
inlineexplicitnoexcept

Construct, taking ownership of the pointer.

Definition at line 66 of file autoPtrI.H.

◆ autoPtr() [4/6]

autoPtr ( autoPtr< T > &&  ap)
inlinenoexcept

Move construct, transferring ownership.

Definition at line 73 of file autoPtrI.H.

◆ autoPtr() [5/6]

autoPtr ( autoPtr< U > &&  ap)
inlineexplicit

Move construct, transferring ownership from derived type.

U must be derivable from T

Note
Future check for std::is_base_of ?

Definition at line 81 of file autoPtrI.H.

◆ autoPtr() [6/6]

autoPtr ( const autoPtr< T > &  ap)
inlinenoexcept

A move construct disguised as a copy construct (transfers ownership)

Remarks
This should ideally be deleted - pending cleanup of code currently relying on this behaviour.

Definition at line 126 of file autoPtr.H.

◆ ~autoPtr()

~autoPtr ( )
inlinenoexcept

Deletes the managed object if such is present.

Definition at line 90 of file autoPtrI.H.

Member Function Documentation

◆ New() [1/2]

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

Construct autoPtr of T with forwarding arguments.

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

Referenced by polyMeshAdder::add(), cellToCellStencil::allCoupledFacesPatch(), cellToFaceStencil::allCoupledFacesPatch(), polyTopoChange::changeMesh(), subBody::clone(), solidMixtureProperties::clone(), liquidMixtureProperties::clone(), boundaryPatch::clone(), regionModelFunctionObject::clone(), cellShape::clone(), solidProperties::clone(), rigidBody::clone(), ignitionSite::clone(), pointToPointPlanarInterpolation::clone(), surfaceZonesInfo::clone(), curve::clone(), cellZone::clone(), cellModel::clone(), pointZone::clone(), faPatch::clone(), dimensionSet::clone(), bitSet::clone(), faceZone::clone(), polyPatch::clone(), IOobject::clone(), coordinateSystem::clone(), dictionary::clone(), particle< Type >::clone(), mapDistribute::clone(), fvMeshDistribute::distribute(), sampledSet::gather(), IOobjectList::IOobjectList(), Foam::loadPointField(), voxelMeshSearch::makeMesh(), polyTopoChange::makeMesh(), meshRefinement::makePatch(), FIREMeshReader::mesh(), meshReader::mesh(), PDRblock::mesh(), reader::mesh(), lumpedPointIOMovement::New(), motionInterpolation::New(), procLduInterface::New(), solidMixtureProperties::New(), surfZone::New(), rigidBody::New(), cellModel::New(), block::New(), colourTable::New(), dictionary::New(), momentum::newField(), ensightCase::newGeometry(), fvMeshTools::newMesh(), phaseModel::iNew::operator()(), ignitionSite::iNew::operator()(), trackedParticle::iNew::operator()(), molecule::iNew::operator()(), particle< Type >::iNew::operator()(), probes::prepare(), regionSplit::reduceRegions(), UnsortedMeshedSurface< Face >::releaseZoneIds(), fvMeshSubset::setCellSubset(), streamLineBase::wallPatch(), and vtkWrite::write().

◆ NewFrom() [1/2]

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

Construct autoPtr 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 for std::is_base_of ?

◆ empty()

bool empty ( ) const
inlinenoexcept

True if the managed pointer is null.

Definition at line 99 of file autoPtrI.H.

Referenced by adjointBoundaryCondition::addATCUaGradUTerm().

Here is the caller graph for this function:

◆ valid()

◆ get() [1/2]

T * get ( )
inlinenoexcept

Return pointer to managed object without nullptr checking.

Pointer remains under autoPtr management.

Definition at line 113 of file autoPtrI.H.

Referenced by refinementHistory::add(), refinementHistory::apply(), HashPtrTable< ThermoType >::insert(), autoPtr< wallLubricationModel >::operator const wallLubricationModel *(), and autoPtr< wallLubricationModel >::operator wallLubricationModel *().

Here is the caller graph for this function:

◆ get() [2/2]

const T * get ( ) const
inlinenoexcept

Return const pointer to managed object without nullptr checking.

Pointer remains under autoPtr management.

Definition at line 120 of file autoPtrI.H.

◆ ref()

T & ref ( )
inline

Return reference to the managed object without nullptr checking.

When get() == nullptr, additional guards may be required to avoid inadvertent access to a nullptr.

Definition at line 127 of file autoPtrI.H.

Referenced by energySpectrum::calcAndWriteSpectrum(), ensightMesh::write(), Foam::ensightOutput::writeCloudField(), Foam::writeVolField(), and ensightWrite::writeVolFields().

Here is the caller graph for this function:

◆ release()

T * release ( )
inlinenoexcept

Return pointer to the managed object and release ownership.

Definition at line 134 of file autoPtrI.H.

Referenced by PtrList< injectionModel >::append(), HashPtrTable< ThermoType >::insert(), functionObjectList::read(), sampledSurfaces::read(), PtrList< injectionModel >::set(), and HashPtrTable< ThermoType >::set().

Here is the caller graph for this function:

◆ ptr()

T * ptr ( )
inlinenoexcept

Return pointer to the managed object and release ownership. Identical behaviour to release().

Note
Provided for method naming consistent with Foam::tmp

Definition at line 143 of file autoPtrI.H.

Referenced by variablesSet::allocateField(), variablesSet::allocateFluxField(), rigidBodyModel::join(), masterUncollatedFileOperation::read(), PtrListDictionary< phaseModel >::set(), regIOobject::store(), and OFstreamCollator::write().

Here is the caller graph for this function:

◆ clear()

void clear ( )
inlinenoexcept

Delete managed object and set pointer to nullptr.

Definition at line 150 of file autoPtrI.H.

Referenced by polyMeshAdder::add(), meshRefinement::distribute(), snappySnapDriver::doSnap(), functionObjectList::read(), STLCore::readBinaryHeader(), masterUncollatedFileOperation::readStream(), FLMAsurfaceFormat< Face >::write(), and FIREMeshWriter::write().

Here is the caller graph for this function:

◆ reset() [1/2]

◆ reset() [2/2]

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

Delete managed object and set to new given pointer.

Remarks
Same as move assign, but better for code documentation

Definition at line 165 of file autoPtrI.H.

◆ swap()

void swap ( autoPtr< T > &  other)
inlinenoexcept

Swaps the managed object with other autoPtr.

Definition at line 172 of file autoPtrI.H.

◆ clone() [1/2]

autoPtr<T> clone ( Args &&...  args) const
inline

Construct copy by invoking clone on underlying managed object.

Parameters
argslist of arguments for clone

Referenced by mapPolyMesh::mapPolyMesh().

Here is the caller graph for this function:

◆ operator*() [1/2]

T & operator* ( )
inline

Return reference to the managed object.

Fatal error if no pointer is managed

Definition at line 196 of file autoPtrI.H.

Referenced by autoPtr< wallLubricationModel >::operator const wallLubricationModel &().

Here is the caller graph for this function:

◆ operator*() [2/2]

const T & operator* ( ) const
inline

Return const reference to the object.

Fatal error if no pointer is managed

Definition at line 209 of file autoPtrI.H.

◆ operator->() [1/2]

T * operator-> ( )
inline

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

Fatal error if no pointer is managed

Definition at line 216 of file autoPtrI.H.

◆ operator->() [2/2]

const T * operator-> ( ) const
inline

Dereferences (const) pointer to the managed object.

Fatal error if no pointer is managed

Definition at line 229 of file autoPtrI.H.

◆ operator()() [1/2]

T & operator() ( )
inline

Return reference to the object data.

Fatal error if no pointer is managed

Definition at line 236 of file autoPtrI.H.

◆ operator()() [2/2]

const T & operator() ( ) const
inline

Return const reference to the object data.

Fatal error if no pointer is managed

Definition at line 243 of file autoPtrI.H.

◆ operator const T &()

operator const T & ( ) const
inline

Deprecated(2019-01) Automatic cast conversion to underlying type.

Fatal error if no pointer is managed

Deprecated:
(2019-01) Can result in inadvertent conversions where the user should really know or check if the pointer is valid prior to using.

Definition at line 230 of file autoPtr.H.

◆ operator const T *()

operator const T * ( ) const
inlinenoexcept

Cast to pointer type.

Definition at line 236 of file autoPtr.H.

◆ operator T*()

operator T* ( )
inlinenoexcept

Cast to pointer type.

Definition at line 239 of file autoPtr.H.

◆ operator bool()

operator bool ( ) const
inlineexplicitnoexcept

True if the managed pointer is non-null.

Definition at line 250 of file autoPtrI.H.

◆ operator=() [1/5]

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

Transfer object ownership from parameter.

Definition at line 257 of file autoPtrI.H.

◆ operator=() [2/5]

void operator= ( autoPtr< U > &&  ap)
inlinenoexcept

Transfer object ownership from parameter.

Definition at line 268 of file autoPtrI.H.

◆ operator=() [3/5]

void operator= ( const autoPtr< T > &  ap)
inlinenoexcept

A move assignment disguised as a copy assignment.

Remarks
Non-standard definition - should just be movable

Definition at line 254 of file autoPtr.H.

◆ operator=() [4/5]

void operator= ( std::nullptr_t  )
inlinenoexcept

Clear via assignment from literal nullptr.

Definition at line 278 of file autoPtrI.H.

◆ set()

void set ( T p)
inlinenoexcept

Deprecated(2018-02) Identical to reset().

Note
Provided for backward compatibility - the older version enforced a run-time check (Fatal if pointer was already set) but this was rarely used.
Deprecated:
(2018-02) Identical to reset().

Definition at line 273 of file autoPtr.H.

Referenced by distributedTriSurfaceMesh::findNearest(), and distributedTriSurfaceMesh::getVolumeType().

Here is the caller graph for this function:

◆ operator=() [5/5]

void operator= ( T p)
delete

Deprecated(2018-02) No copy assignment from plain pointer.

Deprecated:
(2018-02) Convenient, but uncontrolled access

◆ New() [2/2]

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

Definition at line 35 of file autoPtrI.H.

◆ NewFrom() [2/2]

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

Definition at line 43 of file autoPtrI.H.

◆ clone() [2/2]

Foam::autoPtr<T> clone ( Args &&...  args) const
inline

Definition at line 182 of file autoPtrI.H.


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