mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: cleanup autoPtr class (issue #639)
Improve alignment of its behaviour with std::unique_ptr
- element_type typedef
- release() method - identical to ptr() method
- get() method to get the pointer without checking and without releasing it.
- operator*() for dereferencing
Method name changes
- renamed rawPtr() to get()
- renamed rawRef() to ref(), removed unused const version.
Removed methods/operators
- assignment from a raw pointer was deleted (was rarely used).
Can be convenient, but uncontrolled and potentially unsafe.
Do allow assignment from a literal nullptr though, since this
can never leak (and also corresponds to the unique_ptr API).
Additional methods
- clone() method: forwards to the clone() method of the underlying
data object with argument forwarding.
- reset(autoPtr&&) as an alternative to operator=(autoPtr&&)
STYLE: avoid implicit conversion from autoPtr to object type in many places
- existing implementation has the following:
operator const T&() const { return operator*(); }
which means that the following code works:
autoPtr<mapPolyMesh> map = ...;
updateMesh(*map); // OK: explicit dereferencing
updateMesh(map()); // OK: explicit dereferencing
updateMesh(map); // OK: implicit dereferencing
for clarity it may preferable to avoid the implicit dereferencing
- prefer operator* to operator() when deferenced a return value
so it is clearer that a pointer is involve and not a function call
etc Eg, return *meshPtr_; vs. return meshPtr_();
This commit is contained in:
@ -116,7 +116,7 @@ template<class SourcePatch, class TargetPatch>
|
||||
inline const Foam::mapDistribute&
|
||||
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcMap() const
|
||||
{
|
||||
return srcMapPtr_();
|
||||
return *srcMapPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -188,7 +188,7 @@ template<class SourcePatch, class TargetPatch>
|
||||
inline const Foam::mapDistribute&
|
||||
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtMap() const
|
||||
{
|
||||
return tgtMapPtr_();
|
||||
return *tgtMapPtr_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -132,7 +132,7 @@ public:
|
||||
|
||||
virtual const AMIPatchToPatchInterpolation& AMI() const
|
||||
{
|
||||
return amiPtr_();
|
||||
return *amiPtr_;
|
||||
}
|
||||
|
||||
//- Return face transformation tensor
|
||||
|
||||
@ -132,7 +132,7 @@ public:
|
||||
|
||||
virtual const AMIPatchToPatchInterpolation& AMI() const
|
||||
{
|
||||
return amiPtr_();
|
||||
return *amiPtr_;
|
||||
}
|
||||
|
||||
//- Return face transformation tensor
|
||||
|
||||
@ -82,7 +82,7 @@ class cyclicACMIPointPatchField
|
||||
);
|
||||
}
|
||||
|
||||
return ppiPtr_();
|
||||
return *ppiPtr_;
|
||||
}
|
||||
|
||||
//- Neighbour side patch interpolation
|
||||
@ -99,7 +99,7 @@ class cyclicACMIPointPatchField
|
||||
);
|
||||
}
|
||||
|
||||
return nbrPpiPtr_();
|
||||
return *nbrPpiPtr_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -82,7 +82,7 @@ class cyclicAMIPointPatchField
|
||||
);
|
||||
}
|
||||
|
||||
return ppiPtr_();
|
||||
return *ppiPtr_;
|
||||
}
|
||||
|
||||
//- Neighbour side patch interpolation
|
||||
@ -99,7 +99,7 @@ class cyclicAMIPointPatchField
|
||||
);
|
||||
}
|
||||
|
||||
return nbrPpiPtr_();
|
||||
return *nbrPpiPtr_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -810,7 +810,7 @@ const Foam::AMIPatchToPatchInterpolation& Foam::cyclicAMIPolyPatch::AMI() const
|
||||
resetAMI(AMIMethod_);
|
||||
}
|
||||
|
||||
return AMIPtr_();
|
||||
return *AMIPtr_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ void Foam::cylindrical::init
|
||||
|
||||
Foam::cylindrical::cylindrical(const cylindrical& r)
|
||||
:
|
||||
Rptr_(r.Rptr_, false), // clone
|
||||
Rptr_(r.Rptr_.clone()),
|
||||
origin_(r.origin_),
|
||||
e3_(r.e3_)
|
||||
{}
|
||||
@ -177,15 +177,11 @@ Foam::cylindrical::cylindrical
|
||||
}
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::cylindrical::clear()
|
||||
{
|
||||
if (!Rptr_.empty())
|
||||
{
|
||||
Rptr_.clear();
|
||||
}
|
||||
Rptr_.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -181,7 +181,7 @@ public:
|
||||
|
||||
virtual const tensorField& Tr() const
|
||||
{
|
||||
return Rptr_();
|
||||
return *Rptr_;
|
||||
}
|
||||
|
||||
//- Transform vectorField using transformation tensor field
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -48,6 +48,24 @@ Foam::coordinateSystem::coordinateSystem()
|
||||
{}
|
||||
|
||||
|
||||
Foam::coordinateSystem::coordinateSystem(const coordinateSystem& cs)
|
||||
:
|
||||
name_(cs.name_),
|
||||
note_(cs.note_),
|
||||
origin_(cs.origin_),
|
||||
R_(cs.R_.clone())
|
||||
{}
|
||||
|
||||
|
||||
Foam::coordinateSystem::coordinateSystem(coordinateSystem&& cs)
|
||||
:
|
||||
name_(std::move(cs.name_)),
|
||||
note_(std::move(cs.note_)),
|
||||
origin_(std::move(cs.origin_)),
|
||||
R_(std::move(cs.R_))
|
||||
{}
|
||||
|
||||
|
||||
Foam::coordinateSystem::coordinateSystem
|
||||
(
|
||||
const word& name,
|
||||
@ -55,9 +73,9 @@ Foam::coordinateSystem::coordinateSystem
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
note_(),
|
||||
note_(cs.note_),
|
||||
origin_(cs.origin_),
|
||||
R_(cs.R().clone())
|
||||
R_(cs.R_.clone())
|
||||
{}
|
||||
|
||||
|
||||
@ -176,12 +194,6 @@ Foam::coordinateSystem::coordinateSystem(Istream& is)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::coordinateSystem::~coordinateSystem()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::dictionary Foam::coordinateSystem::dict(bool ignoreType) const
|
||||
@ -220,10 +232,8 @@ Foam::vector Foam::coordinateSystem::localToGlobal
|
||||
{
|
||||
return (R_->transform(local)) + origin_;
|
||||
}
|
||||
else
|
||||
{
|
||||
return R_->transform(local);
|
||||
}
|
||||
|
||||
return R_->transform(local);
|
||||
}
|
||||
|
||||
|
||||
@ -237,10 +247,8 @@ Foam::tmp<Foam::vectorField> Foam::coordinateSystem::localToGlobal
|
||||
{
|
||||
return (R_->transform(local)) + origin_;
|
||||
}
|
||||
else
|
||||
{
|
||||
return R_->transform(local);
|
||||
}
|
||||
|
||||
return R_->transform(local);
|
||||
}
|
||||
|
||||
|
||||
@ -254,10 +262,8 @@ Foam::vector Foam::coordinateSystem::globalToLocal
|
||||
{
|
||||
return R_->invTransform(global - origin_);
|
||||
}
|
||||
else
|
||||
{
|
||||
return R_->invTransform(global);
|
||||
}
|
||||
|
||||
return R_->invTransform(global);
|
||||
}
|
||||
|
||||
|
||||
@ -271,10 +277,8 @@ Foam::tmp<Foam::vectorField> Foam::coordinateSystem::globalToLocal
|
||||
{
|
||||
return R_->invTransform(global - origin_);
|
||||
}
|
||||
else
|
||||
{
|
||||
return R_->invTransform(global);
|
||||
}
|
||||
|
||||
return R_->invTransform(global);
|
||||
}
|
||||
|
||||
|
||||
@ -286,6 +290,17 @@ void Foam::coordinateSystem::clear()
|
||||
}
|
||||
|
||||
|
||||
void Foam::coordinateSystem::transfer(coordinateSystem& cs)
|
||||
{
|
||||
name_ = std::move(cs.name_);
|
||||
note_ = std::move(cs.note_);
|
||||
origin_ = std::move(cs.origin_);
|
||||
R_ = std::move(cs.R_);
|
||||
|
||||
cs.clear();
|
||||
}
|
||||
|
||||
|
||||
void Foam::coordinateSystem::write(Ostream& os) const
|
||||
{
|
||||
os << type() << " origin: " << origin() << nl;
|
||||
@ -304,7 +319,7 @@ void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
|
||||
|
||||
if (note_.size())
|
||||
{
|
||||
// note is optional
|
||||
// The 'note' is optional
|
||||
os.writeEntry("note", note_);
|
||||
}
|
||||
|
||||
@ -320,12 +335,26 @@ void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::coordinateSystem::operator=(const coordinateSystem& cs)
|
||||
{
|
||||
name_ = cs.name_;
|
||||
note_ = cs.note_;
|
||||
origin_ = cs.origin_;
|
||||
R_ = cs.R_.clone();
|
||||
}
|
||||
|
||||
void Foam::coordinateSystem::operator=(coordinateSystem&& cs)
|
||||
{
|
||||
transfer(cs);
|
||||
}
|
||||
|
||||
|
||||
void Foam::coordinateSystem::init(const dictionary& rhs)
|
||||
{
|
||||
rhs.lookup("origin") >> origin_;
|
||||
note_.clear();
|
||||
rhs.readIfPresent("note", note_);
|
||||
R_.reset(coordinateRotation::New(rhs.subDict("coordinateRotation")).ptr());
|
||||
R_ = coordinateRotation::New(rhs.subDict("coordinateRotation"));
|
||||
}
|
||||
|
||||
|
||||
@ -347,14 +376,11 @@ void Foam::coordinateSystem::init
|
||||
|
||||
rhs.lookup("origin") >> origin_;
|
||||
|
||||
// The note entry is optional
|
||||
// The 'note' entry is optional
|
||||
note_.clear();
|
||||
rhs.readIfPresent("note", note_);
|
||||
|
||||
R_.reset
|
||||
(
|
||||
coordinateRotation::New(rhs.subDict("coordinateRotation"), obr).ptr()
|
||||
);
|
||||
R_ = coordinateRotation::New(rhs.subDict("coordinateRotation"), obr);
|
||||
}
|
||||
|
||||
|
||||
@ -365,8 +391,8 @@ bool Foam::operator!=(const coordinateSystem& a, const coordinateSystem& b)
|
||||
return
|
||||
(
|
||||
a.origin() != b.origin()
|
||||
|| a.R().R() != b.R().R()
|
||||
|| a.type() != b.type()
|
||||
|| a.R().R() != b.R().R()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -151,11 +151,17 @@ public:
|
||||
//- Construct null. This is equivalent to an identity coordinateSystem
|
||||
coordinateSystem();
|
||||
|
||||
//- Construct copy with a different name
|
||||
//- Copy construct
|
||||
coordinateSystem(const coordinateSystem& cs);
|
||||
|
||||
//- Move construct
|
||||
coordinateSystem(coordinateSystem&& cs);
|
||||
|
||||
//- Copy construct with a different name
|
||||
coordinateSystem
|
||||
(
|
||||
const word& name,
|
||||
const coordinateSystem&
|
||||
const coordinateSystem& cs
|
||||
);
|
||||
|
||||
//- Construct from origin and rotation
|
||||
@ -231,7 +237,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~coordinateSystem();
|
||||
virtual ~coordinateSystem() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -265,13 +271,13 @@ public:
|
||||
//- Return const reference to co-ordinate rotation
|
||||
const coordinateRotation& R() const
|
||||
{
|
||||
return R_();
|
||||
return *R_;
|
||||
}
|
||||
|
||||
//- Return non const reference to co-ordinate rotation
|
||||
coordinateRotation& R()
|
||||
{
|
||||
return R_();
|
||||
return *R_;
|
||||
}
|
||||
|
||||
//- Update and return the co-ordinate rotation for a list of cells
|
||||
@ -282,7 +288,7 @@ public:
|
||||
)
|
||||
{
|
||||
R_->updateCells(mesh, cells);
|
||||
return R_();
|
||||
return *R_;
|
||||
}
|
||||
|
||||
//- Return as dictionary of entries
|
||||
@ -309,6 +315,9 @@ public:
|
||||
// Also resets the note
|
||||
virtual void clear();
|
||||
|
||||
//- Transfer contents from parameter
|
||||
void transfer(coordinateSystem& cs);
|
||||
|
||||
|
||||
// Write
|
||||
|
||||
@ -380,12 +389,19 @@ public:
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Copy assignment
|
||||
void operator=(const coordinateSystem& cs);
|
||||
|
||||
//- Move assignment
|
||||
void operator=(coordinateSystem&& cs);
|
||||
|
||||
|
||||
// friend Operators
|
||||
|
||||
friend bool operator!=
|
||||
(
|
||||
const coordinateSystem&,
|
||||
const coordinateSystem&
|
||||
const coordinateSystem& a,
|
||||
const coordinateSystem& b
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -202,7 +202,7 @@ void Foam::edgeMesh::transfer(edgeMesh& mesh)
|
||||
{
|
||||
points_.transfer(mesh.points_);
|
||||
edges_.transfer(mesh.edges_);
|
||||
pointEdgesPtr_ = mesh.pointEdgesPtr_;
|
||||
pointEdgesPtr_ = std::move(mesh.pointEdgesPtr_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -965,7 +965,7 @@ Foam::extendedEdgeMesh::pointTree() const
|
||||
);
|
||||
}
|
||||
|
||||
return pointTree_();
|
||||
return *pointTree_;
|
||||
}
|
||||
|
||||
|
||||
@ -1007,7 +1007,7 @@ Foam::extendedEdgeMesh::edgeTree() const
|
||||
);
|
||||
}
|
||||
|
||||
return edgeTree_();
|
||||
return *edgeTree_;
|
||||
}
|
||||
|
||||
|
||||
@ -1095,8 +1095,8 @@ void Foam::extendedEdgeMesh::transfer(extendedEdgeMesh& mesh)
|
||||
featurePointNormals_.transfer(mesh.featurePointNormals_);
|
||||
featurePointEdges_.transfer(mesh.featurePointEdges_);
|
||||
regionEdges_.transfer(mesh.regionEdges_);
|
||||
pointTree_ = mesh.pointTree_;
|
||||
edgeTree_ = mesh.edgeTree_;
|
||||
pointTree_ = std::move(mesh.pointTree_);
|
||||
edgeTree_ = std::move(mesh.edgeTree_);
|
||||
edgeTreesByType_.transfer(mesh.edgeTreesByType_);
|
||||
}
|
||||
|
||||
|
||||
@ -148,7 +148,7 @@ inline const Foam::mapDistribute& Foam::mappedPatchBase::map() const
|
||||
calcMapping();
|
||||
}
|
||||
|
||||
return mapPtr_();
|
||||
return *mapPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -162,7 +162,7 @@ inline const Foam::AMIPatchToPatchInterpolation& Foam::mappedPatchBase::AMI
|
||||
calcAMI();
|
||||
}
|
||||
|
||||
return AMIPtr_();
|
||||
return *AMIPtr_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -591,7 +591,7 @@ Foam::meshSearch::boundaryTree() const
|
||||
);
|
||||
}
|
||||
|
||||
return boundaryTreePtr_();
|
||||
return *boundaryTreePtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -637,7 +637,7 @@ Foam::meshSearch::cellTree() const
|
||||
);
|
||||
}
|
||||
|
||||
return cellTreePtr_();
|
||||
return *cellTreePtr_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -130,7 +130,7 @@ public:
|
||||
|
||||
//virtual const AMIPatchToPatchInterpolation& AMI() const
|
||||
//{
|
||||
// return amiPtr_();
|
||||
// return *amiPtr_;
|
||||
//}
|
||||
|
||||
virtual const polyMesh& nbrMesh() const
|
||||
|
||||
@ -293,7 +293,7 @@ const Foam::AMIPatchToPatchInterpolation& Foam::regionCoupledBase::AMI() const
|
||||
resetAMI();
|
||||
}
|
||||
|
||||
return AMIPtr_();
|
||||
return *AMIPtr_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@ public:
|
||||
//- Return global region numbering
|
||||
const globalIndex& globalNumbering() const
|
||||
{
|
||||
return globalNumberingPtr_();
|
||||
return *globalNumberingPtr_;
|
||||
}
|
||||
|
||||
//- Return local number of regions
|
||||
|
||||
@ -139,7 +139,7 @@ public:
|
||||
virtual autoPtr<searchableSurface> clone() const
|
||||
{
|
||||
NotImplemented;
|
||||
return autoPtr<searchableSurface>(nullptr);
|
||||
return autoPtr<searchableSurface>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -613,7 +613,8 @@ Foam::triSurfaceMesh::edgeTree() const
|
||||
|
||||
indexedOctree<treeDataEdge>::perturbTol() = oldTol;
|
||||
}
|
||||
return edgeTree_();
|
||||
|
||||
return *edgeTree_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -243,7 +243,7 @@ public:
|
||||
autoPtr<topoSetSource> clone() const
|
||||
{
|
||||
NotImplemented;
|
||||
return autoPtr<topoSetSource>(nullptr);
|
||||
return autoPtr<topoSetSource>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -254,7 +254,7 @@ public:
|
||||
autoPtr<topoSet> clone() const
|
||||
{
|
||||
NotImplemented;
|
||||
return autoPtr<topoSet>(nullptr);
|
||||
return autoPtr<topoSet>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -250,7 +250,7 @@ Foam::triSurfaceSearch::tree() const
|
||||
indexedOctree<treeDataTriSurface>::perturbTol() = oldTol;
|
||||
}
|
||||
|
||||
return treePtr_();
|
||||
return *treePtr_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user