autoPtr< T > Class Template Reference

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

Inherited by LList< Foam::autoPtr< Foam::regExpPosix > >.

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 pointer. More...
 
constexpr autoPtr (std::nullptr_t) noexcept
 Implicit construct from literal nullptr: no managed pointer. More...
 
 autoPtr (T *p) noexcept
 Construct, taking ownership of the pointer. More...
 
 autoPtr (autoPtr< T > &&rhs) noexcept
 Move construct, transferring ownership. More...
 
template<class U >
 autoPtr (autoPtr< U > &&rhs)
 Move construct, transferring ownership from derived type. More...
 
 autoPtr (std::unique_ptr< T > &&rhs) noexcept
 Move construct from unique_ptr, transferring ownership. More...
 
 autoPtr (const autoPtr< T > &rhs) noexcept
 A move construct disguised as a copy construct (transfers ownership) More...
 
 ~autoPtr () noexcept
 Destructor: deletes managed pointer. More...
 
bool good () 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
 Release ownership and return the pointer. More...
 
Tptr () noexcept
 Same as release(). More...
 
void clear () noexcept
 Same as reset(nullptr) More...
 
void reset (T *p=nullptr) noexcept
 Delete managed object and set to new given pointer. More...
 
void reset (autoPtr< T > &&other) noexcept
 Delete managed object and set to new given pointer. More...
 
template<class... Args>
Templace (Args &&... args)
 Reset with emplace construction. Return reference to the new content. More...
 
void swap (autoPtr< T > &other) noexcept
 Swaps the managed object with other autoPtr. More...
 
template<class... Args>
autoPtr< Tclone (Args &&... args) const
 Copy construct 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 bool () const noexcept
 True if pointer/reference is non-null. Same as good() More...
 
 operator const T * () const noexcept
 Implicit cast to const pointer type. More...
 
 operator const T & () const
 Deprecated(2019-01) Automatic cast conversion to underlying type. More...
 
void operator= (T *p)=delete
 No copy assignment from plain pointer (uncontrolled access) More...
 
void operator= (const autoPtr< T > &)=delete
 No move assignment disguised as a copy assignment. More...
 
void operator= (autoPtr< T > &&other) noexcept
 Transfer object ownership from parameter. More...
 
template<class U >
void operator= (autoPtr< U > &&other) noexcept
 Transfer object ownership from parameter. More...
 
void operator= (std::unique_ptr< T > &&other)
 Transfer ownership by move assignment from unique_ptr. More...
 
void operator= (std::nullptr_t) noexcept
 Reset via assignment from literal nullptr. More...
 
bool valid () const noexcept
 Identical to good(), or bool operator. More...
 
bool empty () const noexcept
 Deprecated(2020-07) True if the managed pointer is null. More...
 
void set (T *p) noexcept
 Deprecated(2018-02) Identical to reset(). More...
 
template<class... Args>
Foam::autoPtr< Tclone (Args &&... args) const
 

Static Public Member Functions

template<class... Args>
static autoPtr< TNew (Args &&... args)
 Construct autoPtr 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
See also
Foam::refPtr

Definition at line 48 of file HashPtrTable.H.

Member Typedef Documentation

◆ element_type

typedef T element_type

Type of object being managed.

Definition at line 79 of file autoPtr.H.

◆ pointer

typedef T* pointer

Pointer to type of object being managed.

Definition at line 84 of file autoPtr.H.

Constructor & Destructor Documentation

◆ autoPtr() [1/7]

constexpr autoPtr ( )
inlinenoexcept

Construct with no managed pointer.

Definition at line 92 of file autoPtr.H.

◆ autoPtr() [2/7]

constexpr autoPtr ( std::nullptr_t  )
inlinenoexcept

Implicit construct from literal nullptr: no managed pointer.

Definition at line 100 of file autoPtr.H.

◆ autoPtr() [3/7]

autoPtr ( T p)
inlineexplicitnoexcept

Construct, taking ownership of the pointer.

Definition at line 108 of file autoPtr.H.

◆ autoPtr() [4/7]

autoPtr ( autoPtr< T > &&  rhs)
inlinenoexcept

Move construct, transferring ownership.

Definition at line 116 of file autoPtr.H.

◆ autoPtr() [5/7]

autoPtr ( autoPtr< U > &&  rhs)
inlineexplicit

Move construct, transferring ownership from derived type.

U must be derivable from T

Note
Future check std::enable_if + std::is_convertible ?

Definition at line 128 of file autoPtr.H.

◆ autoPtr() [6/7]

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

Move construct from unique_ptr, transferring ownership.

Definition at line 136 of file autoPtr.H.

◆ autoPtr() [7/7]

autoPtr ( const autoPtr< T > &  rhs)
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 148 of file autoPtr.H.

◆ ~autoPtr()

~autoPtr ( )
inlinenoexcept

Destructor: deletes managed pointer.

Definition at line 160 of file autoPtr.H.

Member Function Documentation

◆ New()

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

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

Definition at line 178 of file autoPtr.H.

Referenced by polyMeshAdder::add(), zoneCellStencils::allCoupledFacesPatch(), cellToFaceStencil::allCoupledFacesPatch(), cellToCellStencil::allCoupledFacesPatch(), holeToFace::calcClosure(), polyTopoChange::changeMesh(), solidMixtureProperties::clone(), subBody::clone(), liquidMixtureProperties::clone(), boundaryPatch::clone(), regionModelFunctionObject::clone(), rigidBody::clone(), ignitionSite::clone(), solidProperties::clone(), curve::clone(), RASModelVariables::clone(), cellShape::clone(), pointToPointPlanarInterpolation::clone(), surfaceZonesInfo::clone(), cellModel::clone(), cellZone::clone(), pointZone::clone(), faPatch::clone(), bitSet::clone(), polyPatch::clone(), dimensionSet::clone(), faceZone::clone(), AMIInterpolation::clone(), exprResult::clone(), mapDistribute::clone(), coordinateSystem::clone(), particle< Type >::clone(), dictionary::clone(), IOobject::clone(), Foam::createReconstructMap(), cyclicAMIPolyPatch::cylindricalCS(), fvMeshDistribute::distribute(), coordSet::gatherSort(), PDRblock::innerMesh(), IOobjectList::IOobjectList(), Foam::loadPointField(), distributedTriSurfaceMesh::localQueries(), polyTopoChange::makeMesh(), voxelMeshSearch::makeMesh(), meshRefinement::makePatch(), FIREMeshReader::mesh(), meshReader::mesh(), blockMesh::mesh(), reader::mesh(), lumpedPointIOMovement::New(), procLduInterface::New(), motionInterpolation::New(), lumpedPointController::New(), solidMixtureProperties::New(), surfZone::New(), rigidBody::New(), block::New(), topODesignVariables::New(), cellModel::New(), colourTable::New(), Time::New(), dictionary::New(), momentum::newField(), age::newField(), ensightCase::newGeometry(), Time::NewGlobalTime(), faMeshTools::newMesh(), fvMeshTools::newMesh(), zoneCellStencils::nonEmptyFacesPatch(), phaseModel::iNew::operator()(), ignitionSite::iNew::operator()(), passiveParticle::iNew::operator()(), passivePositionParticle::iNew::operator()(), trackedParticle::iNew::operator()(), solidParticle::iNew::operator()(), molecule::iNew::operator()(), particle< Type >::iNew::operator()(), UnsortedMeshedSurface< Face >::releaseZoneIds(), fvMeshSubset::reset(), basicSpecieMixture::specieComposition(), polyTopoChanger::topoChangeRequest(), faMesh::TryNew(), streamLineBase::wallPatch(), and vtkWrite::write().

◆ NewFrom()

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

Definition at line 193 of file autoPtr.H.

◆ good()

◆ get() [1/2]

T* get ( )
inlinenoexcept

Return pointer to managed object without nullptr checking.

Pointer remains under autoPtr management.

Definition at line 216 of file autoPtr.H.

Referenced by refinementHistory::add(), refinementHistory::apply(), fvExpressionField::performAction(), and fieldsDistributor::readFields().

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 223 of file autoPtr.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 of a nullptr.

Definition at line 231 of file autoPtr.H.

Referenced by energySpectrum::calcAndWriteSpectrum(), pointPatchField< vector >::New(), sensitivitySurface::smoothSensitivities(), TDACChemistryModel< CompType, ThermoType >::TDACChemistryModel(), objectiveForce::update_dxdbMultiplier(), objectiveMoment::update_dxdbMultiplier(), ParticlePostProcessing< CloudType >::write(), and ParticleHistogram< CloudType >::write().

Here is the caller graph for this function:

◆ release()

T * release ( )
inlinenoexcept

Release ownership and return the pointer.

Remarks
Method naming consistent with std::unique_ptr

Definition at line 28 of file autoPtrI.H.

Referenced by PtrList< transferModel >::append(), fvExpressionField::performAction(), autoPtr< Foam::distributionModel >::ptr(), PtrListDictionary< phaseModel >::set(), PtrList< transferModel >::set(), PtrDynList< Foam::profilingInformation >::set(), and regIOobject::store().

Here is the caller graph for this function:

◆ ptr()

T* ptr ( )
inlinenoexcept

Same as release().

Remarks
Method naming consistent with Foam::tmp

Definition at line 248 of file autoPtr.H.

Referenced by variablesSet::allocateField(), variablesSet::allocateFluxField(), rigidBodyModel::join(), and OFstreamCollator::write().

Here is the caller graph for this function:

◆ clear()

void clear ( )
inlinenoexcept

◆ reset() [1/2]

void reset ( T p = nullptr)
inlinenoexcept

Delete managed object and set to new given pointer.

Definition at line 37 of file autoPtrI.H.

Referenced by refinementHistory::add(), polyMeshAdder::add(), ATCUaGradU::addATC(), AMIInterpolation::agglomerate(), variablesSet::allocateRenamedField(), refinementHistory::apply(), shapeDesignVariables::assembleSensitivities(), autoPtr< Foam::distributionModel >::clear(), PatchInteractionFields< CloudType >::clearOrReset(), cyclicACMIGAMGInterface::cyclicACMIGAMGInterface(), cyclicAMIGAMGInterface::cyclicAMIGAMGInterface(), snappySnapDriver::detectNearSurfaces(), faMeshDistributor::distribute(), distributedTriSurfaceMesh::distribute(), snappySnapDriver::doSnap(), searchablePlateFeatures::features(), distributedTriSurfaceMesh::findNearest(), PatchTools::gatherAndMerge(), distributedTriSurfaceMesh::getVolumeType(), if(), cyclicAMIPolyPatch::initInterpolate(), cyclicAMIPolyPatch::interpolate(), optimisationManager::lineSearchUpdate(), polyTopoChange::makeMesh(), rigidBodyModel::merge(), averageNeighbourFvGeometryScheme::movePoints(), isoSurfaceBase::New(), lineSearch::New(), entry::New(), functionObjectList::New(), writeFile::newFile(), writeFile::newFileAtTime(), Foam::vtk::newFormatter(), masterUncollatedFileOperation::NewIFstream(), Foam::NewOrNone(), autoPtr< Foam::distributionModel >::operator=(), processorCyclicPolyPatch::order(), fvExpressionField::performAction(), projectCurveEdge::position(), projectEdge::position(), ISQP::preconVectorProduct(), projectFace::project(), radiativeIntensityRay::radiativeIntensityRay(), decomposedBlockData::read(), BilgerMixtureFraction::read(), functionObjectList::read(), masterUncollatedFileOperation::read(), decomposedBlockData::readBlock(), decomposedBlockData::readBlocks(), volumetricBSplinesDesignVariables::readBounds(), designVariables::readDict(), masterUncollatedFileOperation::readStream(), Foam::reconstructLagrangian(), Foam::redistributeLagrangian(), autoPtr< Foam::distributionModel >::set(), cyclicAMIPolyPatch::setAMIFaces(), BezierDesignVariables::setBounds(), variablesSet::setFluxField(), sensitivitySurface::smoothSensitivities(), objective::updateNormalizationFactor(), Foam::ensightOutput::writeCloudPositions(), externalCoupled::writeGeometry(), decomposedBlockData::writeObject(), and topOVariablesBase::writeSurfaceFiles().

◆ reset() [2/2]

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

Delete managed object and set to new given pointer.

Remarks
Same as move assign, but better for code documentation

Definition at line 45 of file autoPtrI.H.

◆ emplace()

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

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

Definition at line 59 of file autoPtrI.H.

◆ swap()

void swap ( autoPtr< T > &  other)
inlinenoexcept

Swaps the managed object with other autoPtr.

Definition at line 68 of file autoPtrI.H.

◆ clone() [1/2]

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

Copy construct by invoking clone on underlying managed object.

A no-op if no pointer is managed

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.

FatalError if no pointer is managed

Definition at line 94 of file autoPtrI.H.

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

Here is the caller graph for this function:

◆ operator*() [2/2]

const T & operator* ( ) const
inline

Return const reference to the object.

FatalError if no pointer is managed

Definition at line 107 of file autoPtrI.H.

◆ operator->() [1/2]

T * operator-> ( )
inline

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

FatalError if no pointer is managed

Definition at line 114 of file autoPtrI.H.

◆ operator->() [2/2]

const T * operator-> ( ) const
inline

Dereferences (const) pointer to the managed object.

FatalError if no pointer is managed

Definition at line 127 of file autoPtrI.H.

◆ operator()() [1/2]

T & operator() ( )
inline

Return reference to the object data.

FatalError if no pointer is managed

Definition at line 134 of file autoPtrI.H.

◆ operator()() [2/2]

const T & operator() ( ) const
inline

Return const reference to the object data.

FatalError if no pointer is managed

Definition at line 141 of file autoPtrI.H.

◆ operator bool()

operator bool ( ) const
inlineexplicitnoexcept

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

Definition at line 344 of file autoPtr.H.

◆ operator const T *()

operator const T * ( ) const
inlinenoexcept

Implicit cast to const pointer type.

Note
no cast to non-const pointer, since this would add uncertainty of ownership.

Definition at line 352 of file autoPtr.H.

◆ operator const T &()

operator const T & ( ) const
inline

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

FatalError 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 363 of file autoPtr.H.

◆ operator=() [1/6]

void operator= ( T p)
delete

No copy assignment from plain pointer (uncontrolled access)

◆ operator=() [2/6]

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

No move assignment disguised as a copy assignment.

Deprecated:
(2018-02) can have unintended behaviour

◆ operator=() [3/6]

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

Transfer object ownership from parameter.

Definition at line 386 of file autoPtr.H.

◆ operator=() [4/6]

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

Transfer object ownership from parameter.

Note
Future check std::enable_if + std::is_convertible ?

Definition at line 394 of file autoPtr.H.

◆ operator=() [5/6]

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

Transfer ownership by move assignment from unique_ptr.

Definition at line 402 of file autoPtr.H.

◆ operator=() [6/6]

void operator= ( std::nullptr_t  )
inlinenoexcept

Reset via assignment from literal nullptr.

Definition at line 407 of file autoPtr.H.

◆ valid()

bool valid ( ) const
inlinenoexcept

Identical to good(), or bool operator.

Definition at line 415 of file autoPtr.H.

Referenced by objective::JCycle(), designVariables::readBounds(), and objective::write().

Here is the caller graph for this function:

◆ empty()

bool empty ( ) const
inlinenoexcept

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

Deprecated:
(2020-07) - use bool operator

Definition at line 424 of file autoPtr.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 437 of file autoPtr.H.

Referenced by multiphaseSystem::dragCoeffs(), lduPrimitiveMesh::lduPrimitiveMesh(), and fvMeshSubset::reset().

Here is the caller graph for this function:

◆ clone() [2/2]

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

Definition at line 80 of file autoPtrI.H.


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