Commit 16aaf5b5 authored by Mark Olesen's avatar Mark Olesen
Browse files

autoPtr gets "empty()" method that can be used instead of "! ...valid()"

parent 5ba68da7
......@@ -24,6 +24,16 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
template<class T>
inline const Foam::Xfer<T>& Foam::Xfer<T>::null()
{
Xfer<T>* nullPtr = reinterpret_cast<Xfer<T>*>(0);
return *nullPtr;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
......@@ -79,13 +89,6 @@ inline Foam::Xfer<T>::~Xfer()
// * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * * //
template<class T>
inline const Foam::Xfer<T>& Foam::Xfer<T>::null()
{
Xfer<T>* nullPtr = reinterpret_cast<Xfer<T>*>(0);
return *nullPtr;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
......
......@@ -77,37 +77,41 @@ public:
// Member Functions
// Check
// Check
//- Is the autoPtr valid, i.e. is the pointer set
inline bool valid() const;
//- Return true if the autoPtr is empty (ie, no pointer set).
inline bool empty() const;
//- Return true if the autoPtr valid (ie, the pointer is set).
inline bool valid() const;
// Edit
//- Return object pointer for reuse
inline T* ptr();
// Edit
//- Set pointer to that given.
// If object pointer already set issue a FatalError.
inline void set(T*);
//- Return object pointer for reuse
inline T* ptr();
//- If object pointer already set delete object and
// set pointer to that given
inline void reset(T* = 0);
//- Set pointer to that given.
// If object pointer already set issue a FatalError.
inline void set(T*);
//- If object pointer points to valid object:
// delete object and set pointer to NULL
inline void clear();
//- If object pointer already set, delete object and set to given pointer
inline void reset(T* = 0);
//- Delete object and set pointer to NULL, if the pointer is valid.
inline void clear();
// Member operators
//- Return reference to the object data
inline T& operator()();
//- Return const reference to the object data
inline const T& operator()() const;
//inline Tref operator*();
//inline const Tref operator*() const;
// inline T& operator*();
// inline const T& operator*() const;
inline operator const T&() const;
......@@ -117,6 +121,7 @@ public:
//- Return const object pointer
inline const T* operator->() const;
//- Take over object pointer from parameter
inline void operator=(const autoPtr<T>&);
};
......
......@@ -53,6 +53,13 @@ inline Foam::autoPtr<T>::~autoPtr()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline bool Foam::autoPtr<T>::empty() const
{
return !ptr_;
}
template<class T>
inline bool Foam::autoPtr<T>::valid() const
{
......
......@@ -41,7 +41,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class refCount Declaration
Class refCount Declaration
\*---------------------------------------------------------------------------*/
class refCount
......@@ -63,6 +63,7 @@ public:
// Constructors
//- Construct null with zero count
refCount()
:
count_(0)
......@@ -71,18 +72,21 @@ public:
// Member Functions
//- Return the reference count
int count() const
{
return count_;
}
//- Return true if the reference count is zero
bool okToDelete() const
{
return(count_ == 0);
return (count_ == 0);
}
//- Reset the reference count to zero
void resetRefCount()
{
count_ = 0;
......@@ -91,22 +95,25 @@ public:
// Member Operators
//- Increment the reference count
void operator++()
{
count_++;
}
//- Increment the reference count
void operator++(int)
{
count_++;
}
//- Decrement the reference count
void operator--()
{
count_--;
}
//- Decrement the reference count
void operator--(int)
{
count_--;
......
......@@ -49,7 +49,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class tmp Declaration
Class tmp Declaration
\*---------------------------------------------------------------------------*/
template<class T>
......@@ -91,11 +91,15 @@ public:
// Access
//- Is this really a temporary object
//- Return true if this is really a temporary object
inline bool isTmp() const;
//- Is this temporary object valid, i.e. is it a reference
// or a temporary that has been allocated
//- Return true if this temporary object empty,
// ie, a temporary without allocation
inline bool empty() const;
//- Is this temporary object valid,
// ie, it is a reference or a temporary that has been allocated
inline bool valid() const;
// Edit
......
......@@ -96,6 +96,13 @@ inline bool Foam::tmp<T>::isTmp() const
}
template<class T>
inline bool Foam::tmp<T>::empty() const
{
return (isTmp_ && !ptr_);
}
template<class T>
inline bool Foam::tmp<T>::valid() const
{
......@@ -132,7 +139,7 @@ inline T* Foam::tmp<T>::ptr() const
template<class T>
inline void Foam::tmp<T>::clear() const
{
if (isTmp_ && ptr_) // && ptr_->okToDelete())
if (isTmp_ && ptr_) // skip this bit: && ptr_->okToDelete())
{
delete ptr_;
ptr_ = 0;
......@@ -161,8 +168,11 @@ inline T& Foam::tmp<T>::operator()()
// Note: const is cast away!
// Perhaps there should be two refs, one for const and one for non const
// and if the ref is actually const then you cannot return it here.
//
// Another possibility would be to store a const ref and a flag to say
// wether the tmp was constructed with a const or a non-const argument.
// whether the tmp was constructed with a const or a non-const argument.
//
// eg, enum refType { POINTER = 0, REF = 1, CONSTREF = 2 };
return const_cast<T&>(ref_);
}
}
......
......@@ -152,7 +152,7 @@ Foam::List<Foam::labelPair> Foam::mapDistribute::schedule
const Foam::List<Foam::labelPair>& Foam::mapDistribute::schedule() const
{
if (!schedulePtr_.valid())
if (schedulePtr_.empty())
{
schedulePtr_.reset
(
......
......@@ -62,6 +62,7 @@ void Foam::refinementHistory::writeEntry
<< " no subcells"
<< endl;
}
if (split.parent_ >= 0)
{
Pout<< "parent data:" << endl;
......@@ -234,7 +235,7 @@ Foam::label Foam::refinementHistory::allocateSplitCell
{
splitCell8& parentSplit = splitCells_[parent];
if (!parentSplit.addedCellsPtr_.valid())
if (parentSplit.addedCellsPtr_.empty())
{
// Allocate storage on parent for the 8 subcells.
parentSplit.addedCellsPtr_.reset(new FixedList<label, 8>(-1));
......@@ -406,7 +407,7 @@ Foam::refinementHistory::refinementHistory
)
{
readStream(typeName) >> *this;
close();
close();
}
else
{
......@@ -497,7 +498,7 @@ void Foam::refinementHistory::resize(const label size)
}
}
void Foam::refinementHistory::updateMesh(const mapPolyMesh& map)
{
if (active())
......@@ -514,7 +515,7 @@ void Foam::refinementHistory::updateMesh(const mapPolyMesh& map)
{
label index = visibleCells_[cellI];
// Check
// Check not already set
if (splitCells_[index].addedCellsPtr_.valid())
{
FatalErrorIn
......@@ -974,7 +975,7 @@ void Foam::refinementHistory::compact()
else if
(
splitCells_[index].parent_ == -1
&& !splitCells_[index].addedCellsPtr_.valid()
&& splitCells_[index].addedCellsPtr_.empty()
)
{
// recombined cell. No need to keep since no parent and no subsplits
......@@ -989,7 +990,7 @@ void Foam::refinementHistory::compact()
// Now oldToNew is fully complete and compacted elements are in
// newSplitCells.
// newSplitCells.
// Renumber contents of newSplitCells and visibleCells.
forAll(newSplitCells, index)
{
......
......@@ -40,7 +40,7 @@ Description
Foam::polyTopoChange& Foam::repatchPolyTopoChanger::meshMod()
{
if (!meshModPtr_.valid())
if (meshModPtr_.empty())
{
meshModPtr_.reset(new polyTopoChange(mesh_));
}
......
......@@ -30,12 +30,9 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void edgeMesh::calcPointEdges() const
void Foam::edgeMesh::calcPointEdges() const
{
if (pointEdgesPtr_.valid())
{
......@@ -81,7 +78,7 @@ void edgeMesh::calcPointEdges() const
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// construct from components
edgeMesh::edgeMesh(const pointField& points, const edgeList& edges)
Foam::edgeMesh::edgeMesh(const pointField& points, const edgeList& edges)
:
points_(points),
edges_(edges)
......@@ -89,7 +86,7 @@ edgeMesh::edgeMesh(const pointField& points, const edgeList& edges)
// construct as copy
edgeMesh::edgeMesh(const edgeMesh& em)
Foam::edgeMesh::edgeMesh(const edgeMesh& em)
:
points_(em.points_),
edges_(em.edges_),
......@@ -99,7 +96,7 @@ edgeMesh::edgeMesh(const edgeMesh& em)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
label edgeMesh::regions(labelList& edgeRegion) const
Foam::label Foam::edgeMesh::regions(labelList& edgeRegion) const
{
edgeRegion.setSize(edges_.size());
edgeRegion = -1;
......@@ -165,7 +162,7 @@ label edgeMesh::regions(labelList& edgeRegion) const
}
void edgeMesh::mergePoints(const scalar mergeDist)
void Foam::edgeMesh::mergePoints(const scalar mergeDist)
{
pointField newPoints;
labelList pointMap;
......@@ -245,7 +242,7 @@ void edgeMesh::mergePoints(const scalar mergeDist)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void edgeMesh::operator=(const edgeMesh& rhs)
void Foam::edgeMesh::operator=(const edgeMesh& rhs)
{
points_ = rhs.points_;
edges_ = rhs.edges_;
......@@ -253,8 +250,4 @@ void edgeMesh::operator=(const edgeMesh& rhs)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -24,10 +24,6 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -40,21 +36,21 @@ namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const pointField& edgeMesh::points() const
inline const Foam::pointField& Foam::edgeMesh::points() const
{
return points_;
}
inline const edgeList& edgeMesh::edges() const
inline const Foam::edgeList& Foam::edgeMesh::edges() const
{
return edges_;
}
inline const labelListList& edgeMesh::pointEdges() const
inline const Foam::labelListList& Foam::edgeMesh::pointEdges() const
{
if (!pointEdgesPtr_.valid())
if (pointEdgesPtr_.empty())
{
calcPointEdges();
}
......@@ -73,6 +69,4 @@ inline const labelListList& edgeMesh::pointEdges() const
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -27,15 +27,11 @@ License
#include "edgeMesh.H"
#include "IFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// construct from file
edgeMesh::edgeMesh(const fileName& fname)
Foam::edgeMesh::edgeMesh(const fileName& fname)
:
points_(0),
edges_(0),
......@@ -57,7 +53,7 @@ edgeMesh::edgeMesh(const fileName& fname)
// construct from Istream
edgeMesh::edgeMesh(Istream& is)
Foam::edgeMesh::edgeMesh(Istream& is)
:
points_(is),
edges_(is),
......@@ -70,7 +66,7 @@ edgeMesh::edgeMesh(Istream& is)
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Ostream& operator<<(Ostream& os, const edgeMesh& em)
Foam::Ostream& Foam::operator<<(Ostream& os, const edgeMesh& em)
{
os << em.points_ << nl << em.edges_ << endl;
......@@ -81,7 +77,7 @@ Ostream& operator<<(Ostream& os, const edgeMesh& em)
}
Istream& operator>>(Istream& is, edgeMesh& em)
Foam::Istream& Foam::operator>>(Istream& is, edgeMesh& em)
{
is >> em.points_ >> em.edges_;
......@@ -92,8 +88,4 @@ Istream& operator>>(Istream& is, edgeMesh& em)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -48,7 +48,7 @@ namespace Foam
bool Foam::fvMeshSubset::checkCellSubset() const
{
if (!fvMeshSubsetPtr_.valid())
if (fvMeshSubsetPtr_.empty())
{
FatalErrorIn("bool fvMeshSubset::checkCellSubset() const")
<< "Mesh subset not set. Please set the cell map using "
......@@ -161,11 +161,11 @@ void Foam::fvMeshSubset::doCoupledPatches
nCellsUsingFace[pp.start()+i] = 3;
nUncoupled++;
}
}
}
}
}
}
// Do same for cyclics.
forAll (oldPatches, oldPatchI)
{
......
......@@ -136,10 +136,10 @@ surfaceSlipDisplacementPointPatchVectorField
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const searchableSurfaces& surfaceSlipDisplacementPointPatchVectorField::
surfaces() const
const searchableSurfaces&
surfaceSlipDisplacementPointPatchVectorField::surfaces() const
{
if (!surfacesPtr_.valid())
if (surfacesPtr_.empty())
{
surfacesPtr_.reset
(
......
......@@ -292,7 +292,7 @@ public:
//- Access to communication.
const List<labelPair>& schedule() const
{
if (!schedulePtr_.valid())
if (schedulePtr_.empty())
{
calcMapping();
}
......@@ -307,7 +307,7 @@ public:
Pout<< "Asking for sendLabels." << endl;
}
if (!sendLabelsPtr_.valid())
if (sendLabelsPtr_.empty())
{
if (debug)
{
......@@ -326,7 +326,7 @@ public:
Pout<< "Asking for receiveFaceLabels." << endl;
}
if (!receiveFaceLabelsPtr_.valid())
if (receiveFaceLabelsPtr_.empty())
{
if (debug)
{
......
......@@ -1260,7 +1260,7 @@ void Foam::distributedTriSurfaceMesh::clearOut()
const Foam::globalIndex& Foam::distributedTriSurfaceMesh::globalTris() const
{
if (!globalTris_.valid())
if (globalTris_.empty())
{
globalTris_.reset(new globalIndex(triSurface::size()));
}
......
......@@ -229,7 +229,7 @@ void Foam::triSurfaceMesh::movePoints(const pointField& newPoints)
const Foam::indexedOctree<Foam::treeDataTriSurface>&
Foam::triSurfaceMesh::tree() const
{
if (!tree_.valid())
if (tree_.empty())
{
treeBoundBox bb(points(), meshPoints());
......@@ -256,7 +256,7 @@ const Foam::indexedOctree<Foam::treeDataTriSurface>&
const Foam::indexedOctree<Foam::treeDataEdge>&
Foam::triSurfaceMesh::edgeTree() const
{
if (!edgeTree_.valid())
if (edgeTree_.empty())
{
treeBoundBox bb(localPoints());
......
......@@ -220,7 +220,7 @@ void Foam::forces::read(const dictionary& dict)
void Foam::forces::makeFile()
{
// Create the forces file if not already created
if (!forcesFilePtr_.valid())
if (forcesFilePtr_.empty())
{
if (debug)
{
......
......@@ -93,7 +93,7 @@ void Foam::minMaxFields::read(const dictionary& dict)
void Foam::minMaxFields::makeFile()
{
// Create the minMaxFields file if not already created
if (!minMaxFieldsFilePtr_.valid())
if (minMaxFieldsFilePtr_.empty())
{
if (debug)
{
......
......@@ -227,7 +227,7 @@ void Foam::sampledSets::sampleAndWrite
bool interpolate = interpolationScheme_ != "cell";
// Create or use existing writer
if (!fields.formatter.valid())
if (fields.formatter.empty())
{
fields.formatter = writer<Type>::New(writeFormat_);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment