Simplify checking of container (List/HashTable, strings) sizes

- can use 'XX.empty()' instead of 'XX.size() == 0', 'XX.size() < 1' or
  'XX.size() <= 0' or for simpler coding.
  It also has the same number of characters as '!XX.size()' and /might/ be
  more readable

- many size checking had 'XX.size() > 0', 'XX.size() != 0', or 'XX.size() >= 1'
  when a simple 'XX.size()' suffices
This commit is contained in:
Mark Olesen
2009-01-10 20:28:06 +01:00
parent 16aaf5b54e
commit 95dcb6ded7
211 changed files with 713 additions and 832 deletions

View File

@ -558,7 +558,7 @@ void ensightFieldAscii
GeometricField<Type, fvPatchField, volMesh> vf(fieldObject, mesh);
if (!patchNames.size())
if (patchNames.empty())
{
if (Pstream::master())
{
@ -633,7 +633,7 @@ void ensightFieldAscii
const word& patchName = iter.key();
const labelList& patchProcessors = iter();
if (!patchNames.size() || patchNames.found(patchName))
if (patchNames.empty() || patchNames.found(patchName))
{
if (patchIndices.found(patchName))
{
@ -734,7 +734,7 @@ void ensightFieldBinary
GeometricField<Type, fvPatchField, volMesh> vf(fieldObject, mesh);
if (!patchNames.size())
if (patchNames.empty())
{
if (Pstream::master())
{
@ -805,7 +805,7 @@ void ensightFieldBinary
const word& patchName = iter.key();
const labelList& patchProcessors = iter();
if (!patchNames.size() || patchNames.found(patchName))
if (patchNames.empty() || patchNames.found(patchName))
{
if (patchIndices.found(patchName))
{

View File

@ -129,7 +129,7 @@ Foam::ensightMesh::ensightMesh
{
wordList patchNameList(IStringStream(args.options()["patches"])());
if (!patchNameList.size())
if (patchNameList.empty())
{
patchNameList = allPatchNames_.toc();
}
@ -163,7 +163,7 @@ Foam::ensightMesh::ensightMesh
label nHexes = 0;
label nPolys = 0;
if (!patchNames_.size())
if (patchNames_.empty())
{
forAll(cellShapes, celli)
{
@ -267,7 +267,7 @@ Foam::ensightMesh::ensightMesh
const word& patchName = iter.key();
nFacePrimitives nfp;
if (!patchNames_.size() || patchNames_.found(patchName))
if (patchNames_.empty() || patchNames_.found(patchName))
{
if (patchIndices_.found(patchName))
{
@ -403,7 +403,7 @@ void Foam::ensightMesh::writePrimsBinary
numElem = cellShapes.size();
if (cellShapes.size() > 0)
if (cellShapes.size())
{
// All the cellShapes have the same number of elements!
int numIntElem = cellShapes.size()*cellShapes[0].size();
@ -917,7 +917,7 @@ void Foam::ensightMesh::writeAscii
labelList pointOffsets(Pstream::nProcs(), 0);
if (!patchNames_.size())
if (patchNames_.empty())
{
label nPoints = points.size();
Pstream::gather(nPoints, sumOp<label>());
@ -1044,7 +1044,7 @@ void Foam::ensightMesh::writeAscii
{
const labelList& patchProcessors = iter();
if (!patchNames_.size() || patchNames_.found(iter.key()))
if (patchNames_.empty() || patchNames_.found(iter.key()))
{
const word& patchName = iter.key();
const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
@ -1244,7 +1244,7 @@ void Foam::ensightMesh::writeBinary
labelList pointOffsets(Pstream::nProcs(), 0);
if (!patchNames_.size())
if (patchNames_.empty())
{
label nPoints = points.size();
Pstream::gather(nPoints, sumOp<label>());
@ -1373,7 +1373,7 @@ void Foam::ensightMesh::writeBinary
iCount ++;
const labelList& patchProcessors = iter();
if (!patchNames_.size() || patchNames_.found(iter.key()))
if (patchNames_.empty() || patchNames_.found(iter.key()))
{
const word& patchName = iter.key();
const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();

View File

@ -57,7 +57,7 @@ void writeEnsDataBinary
std::ofstream& ensightFile
)
{
if (sf.size() > 0)
if (sf.size())
{
List<float> temp(sf.size());

View File

@ -77,9 +77,9 @@ forAllIter(HashTable<HashTable<word> >, cloudFields, cloudIter)
}
}
if (!cloudIter().size())
if (cloudIter().empty())
{
Info<< "removing cloud " << cloudName<< endl;
Info<< "removing cloud " << cloudName << endl;
cloudFields.erase(cloudIter);
}
}

View File

@ -227,7 +227,7 @@ int main(int argc, char *argv[])
# include "getFieldNames.H"
bool hasLagrangian = false;
if ((sprayScalarNames.size() > 0) || (sprayVectorNames.size() > 0))
if (sprayScalarNames.size() || sprayVectorNames.size())
{
hasLagrangian = true;
}

View File

@ -80,7 +80,7 @@ for(label i=0; i < nTypes; i++)
wordList lagrangianScalarNames = objects.names("scalarField");
wordList lagrangianVectorNames = objects.names("vectorField");
if (particles.size() > 0)
if (particles.size())
{
# include "gmvOutputLagrangian.H"
}

View File

@ -49,16 +49,11 @@ forAll(lagrangianScalarNames, i)
)
);
if (s.size() != 0)
if (s.size())
{
gmvFile << name << nl;
for
(
label n = 0;
n < s.size();
n++
)
for (label n = 0; n < s.size(); n++)
{
gmvFile << s[n] << token::SPACE;
}
@ -85,16 +80,11 @@ forAll(lagrangianVectorNames, i)
)
);
if (v.size() != 0)
if (v.size())
{
gmvFile << name + "x" << nl;
for
(
label n = 0;
n < v.size();
n++
)
for (label n = 0; n < v.size(); n++)
{
gmvFile << v[n].x() << token::SPACE;
}
@ -102,12 +92,7 @@ forAll(lagrangianVectorNames, i)
gmvFile << name + "y" << nl;
for
(
label n = 0;
n < v.size();
n++
)
for (label n = 0; n < v.size(); n++)
{
gmvFile << v[n].y() << token::SPACE;
}
@ -115,19 +100,13 @@ forAll(lagrangianVectorNames, i)
gmvFile << name + "z" << nl;
for
(
label n = 0;
n < v.size();
n++
)
for (label n = 0; n < v.size(); n++)
{
gmvFile << v[n].z() << token::SPACE;
}
gmvFile << nl;
}
}

View File

@ -47,16 +47,11 @@ forAll(lagrangianScalarNames, i)
)
);
if (s.size() != 0)
if (s.size())
{
gmvFile << name << nl;
for
(
label n = 0;
n < s.size();
n++
)
for (label n = 0; n < s.size(); n++)
{
gmvFile << s[n] << token::SPACE;
}

View File

@ -339,7 +339,7 @@ int main(int argc, char *argv[])
(
args.options().found("time")
|| args.options().found("latestTime")
|| cellSetName.size() > 0
|| cellSetName.size()
|| regionName != polyMesh::defaultRegion
)
{

View File

@ -58,7 +58,7 @@ void readFields
++iter
)
{
if (!selectedFields.size() || selectedFields.found(iter()->name()))
if (selectedFields.empty() || selectedFields.found(iter()->name()))
{
fields.set
(

View File

@ -47,7 +47,7 @@ Foam::vtkMesh::vtkMesh
subsetter_(baseMesh),
setName_(setName)
{
if (setName.size() > 0)
if (setName.size())
{
// Read cellSet using whole mesh
cellSet currentSet(baseMesh_, setName_);
@ -71,7 +71,7 @@ Foam::polyMesh::readUpdateState Foam::vtkMesh::readUpdate()
topoPtr_.clear();
if (setName_.size() > 0)
if (setName_.size())
{
Info<< "Subsetting mesh based on cellSet " << setName_ << endl;

View File

@ -105,13 +105,13 @@ public:
//- Check if running subMesh
bool useSubMesh() const
{
return setName_.size() > 0;
return setName_.size();
}
//- topology
const vtkTopo& topo() const
{
if (!topoPtr_.valid())
if (topoPtr_.empty())
{
topoPtr_.reset(new vtkTopo(mesh()));
}