Commit 12c91b94 authored by Mark Olesen's avatar Mark Olesen

STYLE: check autoPtr as plain bool instead of valid()

- cleaner code, more similarity with unique_ptr

  Now
      if (ptr)
      if (!ptr)

  instead
      if (ptr.valid())
      if (!ptr.valid())
parent 9af3f85c
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014-2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -85,7 +86,7 @@ Foam::word Foam::orderedPhasePair::name() const
Foam::tmp<Foam::volScalarField> Foam::orderedPhasePair::E() const
{
if (!aspectRatio_.valid())
if (!aspectRatio_)
{
FatalErrorInFunction
<< "Aspect ratio model not specified for " << *this << "."
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -44,7 +44,7 @@ void testTransfer1(autoPtr<labelList> ap)
// Passed in copy, so automatically removes content
// Transfer would be nice, but not actually needed
Info<< "recv " << Switch::name(ap.valid()) << nl;
Info<< "recv " << Switch::name(bool(ap)) << nl;
}
......@@ -53,7 +53,7 @@ void testTransfer1(autoPtr<labelList> ap)
void testTransfer2(autoPtr<labelList>&& ap)
{
// As rvalue, so this time we actually get to manage content
Info<< "recv " << Switch::name(ap.valid()) << nl;
Info<< "recv " << Switch::name(bool(ap)) << nl;
}
......@@ -161,7 +161,7 @@ int main(int argc, char *argv[])
testTransfer2(std::move(list));
Info<<"now have valid=" << Switch::name(list.valid());
Info<<"now have valid=" << Switch::name(bool(list));
if (list)
{
......@@ -209,9 +209,9 @@ int main(int argc, char *argv[])
testTransfer2(std::move(list));
Info<<"now have valid=" << Switch::name(list.valid());
Info<<"now have valid=" << Switch::name(bool(list));
if (list.valid())
if (list)
{
Info<< nl
<< flatOutput(*list) << " @ " << name(list->cdata())
......@@ -229,7 +229,7 @@ int main(int argc, char *argv[])
auto ptr1 = autoPtr<labelList>::New();
auto ptr2 = autoPtr<labelList>::New();
Info<<"ptr valid: " << ptr1.valid() << nl;
Info<<"ptr valid: " << bool(ptr1) << nl;
// Refuses to compile (good!): ptr1 = new labelList(10);
......
......@@ -137,9 +137,9 @@ label mergePatchFaces
// Faces in error.
labelHashSet errorFaces;
if (qualDictPtr.valid())
if (qualDictPtr)
{
motionSmoother::checkMesh(false, mesh, qualDictPtr(), errorFaces);
motionSmoother::checkMesh(false, mesh, *qualDictPtr, errorFaces);
}
else
{
......@@ -440,7 +440,7 @@ int main(int argc, char *argv[])
);
// Merge points on straight edges and remove unused points
if (qualDict.valid())
if (qualDict)
{
Info<< "Merging all 'loose' points on surface edges, "
<< "regardless of the angle they make." << endl;
......
......@@ -731,9 +731,9 @@ int main(int argc, char *argv[])
);
// Update
if (refDataPtr.valid())
if (refDataPtr)
{
refDataPtr().updateMesh(map());
refDataPtr->updateMesh(map());
}
// Store added cells
......@@ -896,9 +896,9 @@ int main(int argc, char *argv[])
updateFaceLabels(map(), backPatchFaces);
updateCellSet(map(), addedCellsSet);
if (refDataPtr.valid())
if (refDataPtr)
{
refDataPtr().updateMesh(map());
refDataPtr->updateMesh(map());
}
// Move mesh (if inflation used)
......@@ -1029,9 +1029,9 @@ int main(int argc, char *argv[])
// Update local data
updateCellSet(map(), addedCellsSet);
if (refDataPtr.valid())
if (refDataPtr)
{
refDataPtr().updateMesh(map());
refDataPtr->updateMesh(map());
}
// Move mesh (if inflation used)
......@@ -1067,9 +1067,9 @@ int main(int argc, char *argv[])
}
}
if (refDataPtr.valid())
if (refDataPtr)
{
refDataPtr().write();
refDataPtr->write();
}
......
......@@ -539,7 +539,7 @@ Foam::label Foam::checkGeometry
<< nonAlignedPoints.name() << endl;
nonAlignedPoints.instance() = mesh.pointsInstance();
nonAlignedPoints.write();
if (setWriter.valid())
if (setWriter)
{
mergeAndWrite(*setWriter, nonAlignedPoints);
}
......@@ -573,7 +573,7 @@ Foam::label Foam::checkGeometry
<< " non closed cells to set " << cells.name() << endl;
cells.instance() = mesh.pointsInstance();
cells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, cells);
}
......@@ -589,7 +589,7 @@ Foam::label Foam::checkGeometry
<< aspectCells.name() << endl;
aspectCells.instance() = mesh.pointsInstance();
aspectCells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, aspectCells);
}
......@@ -610,7 +610,7 @@ Foam::label Foam::checkGeometry
<< " zero area faces to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -632,7 +632,7 @@ Foam::label Foam::checkGeometry
<< " zero volume cells to set " << cells.name() << endl;
cells.instance() = mesh.pointsInstance();
cells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, cells);
}
......@@ -655,7 +655,7 @@ Foam::label Foam::checkGeometry
<< " non-orthogonal faces to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -677,7 +677,7 @@ Foam::label Foam::checkGeometry
<< faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -699,7 +699,7 @@ Foam::label Foam::checkGeometry
<< " skew faces to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -723,7 +723,7 @@ Foam::label Foam::checkGeometry
<< faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -756,7 +756,7 @@ Foam::label Foam::checkGeometry
<< "decomposition tets to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -781,7 +781,7 @@ Foam::label Foam::checkGeometry
<< endl;
points.instance() = mesh.pointsInstance();
points.write();
if (setWriter.valid())
if (setWriter)
{
mergeAndWrite(*setWriter, points);
}
......@@ -804,7 +804,7 @@ Foam::label Foam::checkGeometry
<< " apart) points to set " << nearPoints.name() << endl;
nearPoints.instance() = mesh.pointsInstance();
nearPoints.write();
if (setWriter.valid())
if (setWriter)
{
mergeAndWrite(*setWriter, nearPoints);
}
......@@ -828,7 +828,7 @@ Foam::label Foam::checkGeometry
<< endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -851,7 +851,7 @@ Foam::label Foam::checkGeometry
<< " warped faces to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -872,7 +872,7 @@ Foam::label Foam::checkGeometry
<< " under-determined cells to set " << cells.name() << endl;
cells.instance() = mesh.pointsInstance();
cells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, cells);
}
......@@ -892,7 +892,7 @@ Foam::label Foam::checkGeometry
<< " concave cells to set " << cells.name() << endl;
cells.instance() = mesh.pointsInstance();
cells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, cells);
}
......@@ -913,7 +913,7 @@ Foam::label Foam::checkGeometry
<< faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -934,7 +934,7 @@ Foam::label Foam::checkGeometry
<< faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -949,7 +949,7 @@ Foam::label Foam::checkGeometry
const word procAndTime(Foam::name(Pstream::myProcNo()) + "_" + tmName);
autoPtr<surfaceWriter> patchWriter;
if (!surfWriter.valid())
if (!surfWriter)
{
patchWriter.reset(new surfaceWriters::vtkWriter());
}
......
......@@ -30,7 +30,7 @@ Foam::label Foam::checkMeshQuality
faces.instance() = mesh.pointsInstance();
faces.write();
if (writer.valid())
if (writer)
{
mergeAndWrite(*writer, faces);
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -202,7 +202,7 @@ Foam::label Foam::checkTopology
<< " illegal cells to set " << cells.name() << endl;
cells.instance() = mesh.pointsInstance();
cells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, cells);
}
......@@ -226,7 +226,7 @@ Foam::label Foam::checkTopology
<< " unused points to set " << points.name() << endl;
points.instance() = mesh.pointsInstance();
points.write();
if (setWriter.valid())
if (setWriter)
{
mergeAndWrite(*setWriter, points);
}
......@@ -248,7 +248,7 @@ Foam::label Foam::checkTopology
<< " unordered faces to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -268,7 +268,7 @@ Foam::label Foam::checkTopology
<< faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -289,7 +289,7 @@ Foam::label Foam::checkTopology
<< endl;
cells.instance() = mesh.pointsInstance();
cells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, cells);
}
......@@ -313,7 +313,7 @@ Foam::label Foam::checkTopology
<< faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, faces);
}
......@@ -368,7 +368,7 @@ Foam::label Foam::checkTopology
<< endl;
oneCells.instance() = mesh.pointsInstance();
oneCells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, oneCells);
}
......@@ -384,7 +384,7 @@ Foam::label Foam::checkTopology
<< endl;
twoCells.instance() = mesh.pointsInstance();
twoCells.write();
if (surfWriter.valid())
if (surfWriter)
{
mergeAndWrite(*surfWriter, twoCells);
}
......@@ -529,7 +529,7 @@ Foam::label Foam::checkTopology
<< " points that are in multiple regions to set "
<< points.name() << endl;
points.write();
if (setWriter.valid())
if (setWriter)
{
mergeAndWrite(*setWriter, points);
}
......@@ -640,7 +640,7 @@ Foam::label Foam::checkTopology
<< " conflicting points to set " << points.name() << endl;
points.instance() = mesh.pointsInstance();
points.write();
if (setWriter.valid())
if (setWriter)
{
mergeAndWrite(*setWriter, points);
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -1035,9 +1036,9 @@ void Foam::meshDualiser::setRefinement
-1, //masterCellID,
-1 //zoneID
);
if (dualCcStr.valid())
if (dualCcStr)
{
meshTools::writeOBJ(dualCcStr(), mesh_.points()[pointi]);
meshTools::writeOBJ(*dualCcStr, mesh_.points()[pointi]);
}
}
......@@ -1079,11 +1080,11 @@ void Foam::meshDualiser::setRefinement
-1, //masterCellID
mesh_.cellZones().whichZone(pCells[pCelli]) //zoneID
);
if (dualCcStr.valid())
if (dualCcStr)
{
meshTools::writeOBJ
(
dualCcStr(),
*dualCcStr,
0.5*(mesh_.points()[pointi]+cellCentres[pCells[pCelli]])
);
}
......@@ -1104,9 +1105,9 @@ void Foam::meshDualiser::setRefinement
-1 //zoneID
);
if (dualCcStr.valid())
if (dualCcStr)
{
meshTools::writeOBJ(dualCcStr(), mesh_.points()[pointi]);
meshTools::writeOBJ(*dualCcStr, mesh_.points()[pointi]);
}
}
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2018 OpenFOAM Foundation
Copyright (C) 2017-2018 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -393,9 +393,9 @@ bool doCommand
currentSet.resize(max(currentSet.size(), typSize));
}
if (currentSetPtr.valid())
if (currentSetPtr)
{
topoSet& currentSet = currentSetPtr();
topoSet& currentSet = *currentSetPtr;
Info<< " Set:" << currentSet.name()
<< " Size:" << returnReduce(currentSet.size(), sumOp<label>())
......@@ -829,9 +829,9 @@ int main(int argc, char *argv[])
commandStatus stat = INVALID;
if (fileStreamPtr.valid())
if (fileStreamPtr)
{
if (!fileStreamPtr().good())
if (!fileStreamPtr->good())
{
Info<< "End of batch file" << endl;
// No error.
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -394,7 +394,7 @@ int main(int argc, char *argv[])
break;
}
if (currentSet.valid())
if (currentSet)
{
Info<< " "
<< currentSet().type() << ' '
......
......@@ -426,9 +426,9 @@ int main(int argc, char *argv[])
if (!lagrangianDirs.empty())
{
if (meshPtr.valid())
if (meshPtr)
{
meshPtr().readUpdate();
meshPtr->readUpdate();
}
else
{
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -334,7 +334,7 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
autoPtr<polyMesh> procMeshPtr;
if (facesInstancePointsPtr_.valid())
if (facesInstancePointsPtr_)
{
// Construct mesh from facesInstance.
pointField facesInstancePoints
......@@ -738,7 +738,7 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
procMesh.write();
// Write points if pointsInstance differing from facesInstance
if (facesInstancePointsPtr_.valid())
if (facesInstancePointsPtr_)
{
pointIOField pointsInstancePoints
(
......
......@@ -672,9 +672,9 @@ void readFields
// Load field (but not oldTime)
readField(io, mesh, i, fields);
// Create zero sized field and send
if (subsetterPtr.valid())
if (subsetterPtr)
{
tmp<GeoField> tsubfld = subsetterPtr().interpolate(fields[i]);
tmp<GeoField> tsubfld = subsetterPtr->interpolate(fields[i]);
// Send to all processors that don't have a mesh
for (label procI = 1; procI < Pstream::nProcs(); ++procI)
......@@ -1803,7 +1803,7 @@ void reconstructLagrangian
if (cloudNames.size())
{
if (!lagrangianReconstructorPtr.valid())
if (!lagrangianReconstructorPtr)
{