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 pointer. More...
 
constexpr autoPtr (std::nullptr_t) noexcept
 Construct with no managed pointer (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 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 (autoPtr< T > &&other) noexcept
 Delete managed object and set to new given pointer. More...
 
void reset (T *p=nullptr) 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
 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
 Cast to pointer type. More...
 
 operator T* () noexcept
 Cast to 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= (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)=delete
 No move assignment disguised as a copy assignment. 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< 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 65 of file autoPtr.H.

Member Typedef Documentation

◆ element_type

typedef T element_type

Type of object being managed.

Definition at line 76 of file autoPtr.H.

◆ pointer

typedef T* pointer

Pointer to type of object being managed.

Definition at line 79 of file autoPtr.H.

Constructor & Destructor Documentation

◆ autoPtr() [1/6]

constexpr autoPtr
inlineconstexprnoexcept

Construct with no managed pointer.

Definition at line 53 of file autoPtrI.H.

◆ autoPtr() [2/6]

constexpr autoPtr ( std::nullptr_t  )
inlineconstexprnoexcept

Construct with no managed pointer (literal nullptr).

Definition at line 60 of file autoPtrI.H.

References Foam::noexcept.

◆ autoPtr() [3/6]

autoPtr ( T p)
inlineexplicitnoexcept

Construct, taking ownership of the pointer.

Definition at line 67 of file autoPtrI.H.

References Foam::noexcept.

◆ autoPtr() [4/6]

autoPtr ( autoPtr< T > &&  ap)
inlinenoexcept

Move construct, transferring ownership.

Definition at line 74 of file autoPtrI.H.

References Foam::noexcept.

◆ 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 82 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 127 of file autoPtr.H.

◆ ~autoPtr()

~autoPtr
inlinenoexcept

Deletes the managed pointer.

Definition at line 91 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.

◆ 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 ?

◆ good()

bool good ( ) const
inlinenoexcept

True if the managed pointer is non-null.

Definition at line 145 of file autoPtr.H.

References bool.

Referenced by writeFile::createFile(), UniformValueField< Type >::good(), argList::parse(), rawIOField< Type >::rawIOField(), uncollatedFileOperation::readHeader(), uncollatedFileOperation::readStream(), masterUncollatedFileOperation::readStream(), Table< Type >::Table(), FIREMeshWriter::write(), FLMAsurfaceFormat< Face >::write(), and decomposedBlockData::writeBlocks().

Here is the caller graph for this function:

◆ get() [1/2]

T * get ( )
inlinenoexcept

Return pointer to managed object without nullptr checking.

Pointer remains under autoPtr management.

Definition at line 152 of file autoPtr.H.

Referenced by refinementHistory::add(), refinementHistory::apply(), HashPtrTable< T, Key, Hash >::insert(), and fvExpressionField::performAction().

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 156 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 161 of file autoPtr.H.

Referenced by sensitivitySurface::accumulateIntegrand(), sensitivitySurfacePoints::accumulateIntegrand(), energySpectrum::calcAndWriteSpectrum(), sensitivitySurface::smoothSensitivities(), TDACChemistryModel< ReactionThermo, ThermoType >::TDACChemistryModel(), objectiveForce::update_dxdbMultiplier(), objectiveMoment::update_dxdbMultiplier(), and Foam::ensightOutput::writeCloudField().

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 100 of file autoPtrI.H.

References p, and T.

Referenced by PtrDynList< T, SizeMin >::append(), PtrList< T >::append(), HashPtrTable< T, Key, Hash >::insert(), fvExpressionField::performAction(), HashPtrTable< T, Key, Hash >::set(), PtrDynList< T, SizeMin >::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 172 of file autoPtr.H.

Referenced by variablesSet::allocateField(), variablesSet::allocateFluxField(), fvMeshDistribute::distribute(), rigidBodyModel::join(), PtrListDictionary< phaseModel >::set(), and OFstreamCollator::write().

Here is the caller graph for this function:

◆ clear()

void clear ( )
inlinenoexcept

Same as reset(nullptr)

Remarks
Method naming consistent with Foam::tmp

Definition at line 176 of file autoPtr.H.

Referenced by meshRefinement::distribute(), snappySnapDriver::doSnap(), rawIOField< Type >::rawIOField(), reactingMixture< ThermoType >::reactingMixture(), masterUncollatedFileOperation::readStream(), FIREMeshWriter::write(), and FLMAsurfaceFormat< Face >::write().

Here is the caller graph for this function:

◆ reset() [1/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 117 of file autoPtrI.H.

Referenced by polyMeshAdder::add(), refinementHistory::add(), ATCUaGradU::addATC(), AMIInterpolation::agglomerate(), variablesSet::allocateRenamedField(), refinementHistory::apply(), sensitivityBezierFI::assembleSensitivities(), sensitivitySurface::assembleSensitivities(), sensitivityVolBSplinesFI::assembleSensitivities(), PatchInteractionFields< CloudType >::clearOrReset(), writeFile::createFile(), snappySnapDriver::detectNearSurfaces(), faMeshDistributor::distribute(), distributedTriSurfaceMesh::distribute(), snappySnapDriver::doSnap(), sensitivitySurfacePoints::finaliseFaceMultiplier(), distributedTriSurfaceMesh::findNearest(), PatchTools::gatherAndMerge(), distributedTriSurfaceMesh::getVolumeType(), if(), steadyOptimisation::lineSearchUpdate(), polyTopoChange::makeMesh(), rigidBodyModel::merge(), averageNeighbourFvGeometryScheme::movePoints(), MultiComponentPhaseModel< BasePhaseModel, phaseThermo >::MultiComponentPhaseModel(), functionObjectList::New(), lineSearch::New(), isoSurfaceBase::New(), entry::New(), Foam::vtk::newFormatter(), masterUncollatedFileOperation::NewIFstream(), Foam::NewOrNone(), objective::objective(), optMeshMovement::optMeshMovement(), processorCyclicPolyPatch::order(), fvExpressionField::performAction(), projectCurveEdge::position(), projectEdge::position(), projectFace::project(), PurePhaseModel< BasePhaseModel, phaseThermo >::PurePhaseModel(), radiativeIntensityRay::radiativeIntensityRay(), functionObjectList::read(), decomposedBlockData::read(), BilgerMixtureFraction::read(), masterUncollatedFileOperation::read(), decomposedBlockData::readBlock(), decomposedBlockData::readBlocks(), masterUncollatedFileOperation::readStream(), Foam::reconstructLagrangian(), Foam::redistributeLagrangian(), autoPtr< T >::set(), cyclicAMIPolyPatch::setAMIFaces(), variablesSet::setFluxField(), sensitivitySurface::smoothSensitivities(), objective::updateNormalizationFactor(), Foam::ensightOutput::writeCloudPositions(), externalCoupled::writeGeometry(), and decomposedBlockData::writeObject().

◆ reset() [2/2]

void reset ( T p = nullptr)
inlinenoexcept

Delete managed object and set to new given pointer.

Definition at line 109 of file autoPtrI.H.

◆ swap()

void swap ( autoPtr< T > &  other)
inlinenoexcept

Swaps the managed object with other autoPtr.

Definition at line 128 of file autoPtrI.H.

References p, and T.

Referenced by Foam::Swap().

Here is the caller graph for this function:

◆ 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 154 of file autoPtrI.H.

References Foam::abort(), Foam::FatalError, FatalErrorInFunction, Foam::name(), and T.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator*() [2/2]

const T & operator*
inline

Return const reference to the object.

FatalError if no pointer is managed

Definition at line 167 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 174 of file autoPtrI.H.

References Foam::abort(), Foam::FatalError, FatalErrorInFunction, Foam::name(), and T.

Here is the call graph for this function:

◆ operator->() [2/2]

const T * operator->
inline

Dereferences (const) pointer to the managed object.

FatalError if no pointer is managed

Definition at line 187 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 194 of file autoPtrI.H.

References Foam::operator*().

Here is the call graph for this function:

◆ operator()() [2/2]

const T & operator()
inline

Return const reference to the object data.

FatalError if no pointer is managed

Definition at line 201 of file autoPtrI.H.

◆ operator bool()

operator bool ( ) const
inlineexplicitnoexcept

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

Definition at line 229 of file autoPtr.H.

References bool.

◆ operator const T *()

operator const T * ( ) const
inlinenoexcept

Cast to pointer type.

Definition at line 232 of file autoPtr.H.

◆ operator T*()

operator T* ( )
inlinenoexcept

Cast to pointer type.

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

◆ operator=() [1/5]

void operator= ( T p)
delete

No copy assignment from plain pointer (uncontrolled access)

◆ operator=() [2/5]

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

Transfer object ownership from parameter.

Definition at line 208 of file autoPtrI.H.

◆ operator=() [3/5]

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

Transfer object ownership from parameter.

Definition at line 220 of file autoPtrI.H.

◆ operator=() [4/5]

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

No move assignment disguised as a copy assignment.

Deprecated:
(2018-02) can have unintended behaviour

◆ operator=() [5/5]

void operator= ( std::nullptr_t  )
inlinenoexcept

Reset via assignment from literal nullptr.

Definition at line 231 of file autoPtrI.H.

◆ valid()

bool valid ( ) const
inlinenoexcept

Identical to good(), or bool operator.

Definition at line 272 of file autoPtr.H.

References bool.

Referenced by meshRefinement::blockLeakFaces(), objective::JCycle(), 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 278 of file autoPtr.H.

Referenced by MultiComponentPhaseModel< BasePhaseModel, phaseThermo >::MultiComponentPhaseModel().

Here is the caller graph for this function:

◆ 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 288 of file autoPtr.H.

References p, and autoPtr< T >::reset().

Referenced by BlendedInterfacialModel< ModelType >::BlendedInterfacialModel(), and multiphaseSystem::dragCoeffs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ New() [2/2]

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

Definition at line 36 of file autoPtrI.H.

References args, and T.

◆ NewFrom() [2/2]

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

Definition at line 44 of file autoPtrI.H.

References args, and U.

◆ clone() [2/2]

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

Definition at line 140 of file autoPtrI.H.

References args.


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