mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: for-range, forAllIters() ... in conversion/
- reduced clutter when iterating over containers
This commit is contained in:
committed by
Andrew Heather
parent
e3e0d7c8b9
commit
8d5894174f
@ -52,7 +52,7 @@ void Foam::meshReader::addFaceZones(polyMesh& mesh) const
|
||||
}
|
||||
|
||||
nZone = 0;
|
||||
forAllConstIter(HashTable<labelList>, monitoringSets_, iter)
|
||||
forAllConstIters(monitoringSets_, iter)
|
||||
{
|
||||
Info<< "faceZone " << nZone
|
||||
<< " (size: " << iter().size() << ") name: "
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
@ -41,26 +41,26 @@ void Foam::meshReader::warnDuplicates
|
||||
HashTable<label> hashed(list.size());
|
||||
bool duplicates = false;
|
||||
|
||||
forAll(list, listI)
|
||||
for (const word& w : list)
|
||||
{
|
||||
// check duplicate name
|
||||
HashTable<label>::iterator iter = hashed.find(list[listI]);
|
||||
if (iter != hashed.end())
|
||||
// Check duplicate name
|
||||
auto iter = hashed.find(w);
|
||||
if (iter.found())
|
||||
{
|
||||
(*iter)++;
|
||||
++(*iter);
|
||||
duplicates = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
hashed.insert(list[listI], 1);
|
||||
hashed.insert(w, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// warn about duplicate names
|
||||
// Warn about duplicate names
|
||||
if (duplicates)
|
||||
{
|
||||
Info<< nl << "WARNING: " << context << " with identical names:";
|
||||
forAllConstIter(HashTable<label>, hashed, iter)
|
||||
forAllConstIters(hashed, iter)
|
||||
{
|
||||
if (*iter > 1)
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011 OpenFOAM Foundation
|
||||
@ -55,7 +55,7 @@ Foam::boundaryRegion::boundaryRegion
|
||||
Foam::label Foam::boundaryRegion::append(const dictionary& dict)
|
||||
{
|
||||
label maxId = -1;
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
if (maxId < iter.key())
|
||||
{
|
||||
@ -72,7 +72,7 @@ Foam::Map<Foam::word> Foam::boundaryRegion::names() const
|
||||
{
|
||||
Map<word> lookup;
|
||||
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
lookup.insert
|
||||
(
|
||||
@ -96,7 +96,7 @@ Foam::Map<Foam::word> Foam::boundaryRegion::names
|
||||
{
|
||||
Map<word> lookup;
|
||||
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
const word lookupName = iter().lookupOrDefault<word>
|
||||
(
|
||||
@ -118,7 +118,7 @@ Foam::Map<Foam::word> Foam::boundaryRegion::boundaryTypes() const
|
||||
{
|
||||
Map<word> lookup;
|
||||
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
lookup.insert
|
||||
(
|
||||
@ -138,7 +138,7 @@ Foam::label Foam::boundaryRegion::findIndex(const word& name) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
if (iter().lookupOrDefault<word>("Label", word::null) == name)
|
||||
{
|
||||
@ -258,18 +258,18 @@ void Foam::boundaryRegion::rename(const dictionary& mapDict)
|
||||
// This avoid re-matching any renamed regions
|
||||
|
||||
Map<word> mapping;
|
||||
forAllConstIter(dictionary, mapDict, iter)
|
||||
for (const entry& dEntry : mapDict)
|
||||
{
|
||||
word oldName(iter().stream());
|
||||
const word oldName(dEntry.stream());
|
||||
|
||||
label id = this->findIndex(oldName);
|
||||
const label id = this->findIndex(oldName);
|
||||
if (id >= 0)
|
||||
{
|
||||
mapping.insert(id, iter().keyword());
|
||||
mapping.insert(id, dEntry.keyword());
|
||||
}
|
||||
}
|
||||
|
||||
forAllConstIter(Map<word>, mapping, iter)
|
||||
forAllConstIters(mapping, iter)
|
||||
{
|
||||
dictionary& dict = operator[](iter.key());
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -40,10 +40,10 @@ Foam::Map<Foam::label> Foam::cellTable::zoneMap() const
|
||||
{
|
||||
Map<label> lookup;
|
||||
|
||||
label zoneI = 0;
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
label zonei = 0;
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
lookup.insert(iter.key(), zoneI++);
|
||||
lookup.insert(iter.key(), zonei++);
|
||||
}
|
||||
|
||||
return lookup;
|
||||
@ -53,21 +53,21 @@ Foam::Map<Foam::label> Foam::cellTable::zoneMap() const
|
||||
Foam::wordList Foam::cellTable::namesList() const
|
||||
{
|
||||
Map<word> lookup = names();
|
||||
wordList lst(lookup.size());
|
||||
wordList list(lookup.size());
|
||||
|
||||
label zoneI = 0;
|
||||
forAllConstIter(Map<word>, lookup, iter)
|
||||
label zonei = 0;
|
||||
forAllConstIters(lookup, iter)
|
||||
{
|
||||
lst[zoneI++] = iter();
|
||||
list[zonei++] = *iter;
|
||||
}
|
||||
|
||||
return lst;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
void Foam::cellTable::addDefaults()
|
||||
{
|
||||
forAllIter(Map<dictionary>, *this, iter)
|
||||
forAllIters(*this, iter)
|
||||
{
|
||||
if (!iter().found("MaterialType"))
|
||||
{
|
||||
@ -88,7 +88,7 @@ void Foam::cellTable::setEntry
|
||||
dict.add(keyWord, value);
|
||||
|
||||
iterator iter = find(id);
|
||||
if (iter != end())
|
||||
if (iter.found())
|
||||
{
|
||||
iter().merge(dict);
|
||||
}
|
||||
@ -125,7 +125,7 @@ Foam::cellTable::cellTable
|
||||
Foam::label Foam::cellTable::append(const dictionary& dict)
|
||||
{
|
||||
label maxId = -1;
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
if (maxId < iter.key())
|
||||
{
|
||||
@ -142,7 +142,7 @@ Foam::Map<Foam::word> Foam::cellTable::names() const
|
||||
{
|
||||
Map<word> lookup;
|
||||
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
lookup.insert
|
||||
(
|
||||
@ -166,7 +166,7 @@ Foam::Map<Foam::word> Foam::cellTable::names
|
||||
{
|
||||
Map<word> lookup;
|
||||
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
const word lookupName = iter().lookupOrDefault<word>
|
||||
(
|
||||
@ -188,8 +188,8 @@ Foam::word Foam::cellTable::name(const label id) const
|
||||
{
|
||||
word theName("cellTable_" + Foam::name(id));
|
||||
|
||||
const_iterator iter = find(id);
|
||||
if (iter != end())
|
||||
const_iterator iter = cfind(id);
|
||||
if (iter.found())
|
||||
{
|
||||
iter().readIfPresent("Label", theName);
|
||||
}
|
||||
@ -205,7 +205,7 @@ Foam::label Foam::cellTable::findIndex(const word& name) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
if (iter().lookupOrDefault<word>("Label", word::null) == name)
|
||||
{
|
||||
@ -221,7 +221,7 @@ Foam::Map<Foam::word> Foam::cellTable::materialTypes() const
|
||||
{
|
||||
Map<word> lookup;
|
||||
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
lookup.insert
|
||||
(
|
||||
@ -238,7 +238,7 @@ Foam::Map<Foam::word> Foam::cellTable::selectType(const word& matl) const
|
||||
{
|
||||
Map<word> lookup;
|
||||
|
||||
forAllConstIter(Map<dictionary>, *this, iter)
|
||||
forAllConstIters(*this, iter)
|
||||
{
|
||||
const label index = iter.key();
|
||||
const dictionary& dict = iter.val();
|
||||
@ -300,7 +300,7 @@ void Foam::cellTable::setName(const label id)
|
||||
{
|
||||
iterator iter = find(id);
|
||||
|
||||
if (iter == end() || !iter().found("Label"))
|
||||
if (!iter.found() || !iter().found("Label"))
|
||||
{
|
||||
setName(id, "cellTable_" + Foam::name(id));
|
||||
}
|
||||
@ -446,10 +446,10 @@ void Foam::cellTable::addCellZones
|
||||
|
||||
forAll(tableIds, celli)
|
||||
{
|
||||
Map<label>::const_iterator iter = typeToZone.find(tableIds[celli]);
|
||||
if (iter != typeToZone.end())
|
||||
const auto iter = typeToZone.cfind(tableIds[celli]);
|
||||
if (iter.found())
|
||||
{
|
||||
zoneCells[iter()].append(celli);
|
||||
zoneCells[*iter].append(celli);
|
||||
}
|
||||
}
|
||||
|
||||
@ -513,13 +513,13 @@ void Foam::cellTable::combine(const dictionary& mapDict, labelList& tableIds)
|
||||
labelList mapping(identity(max(origNames.toc()) + 1));
|
||||
|
||||
bool remap = false;
|
||||
forAllConstIter(dictionary, mapDict, iter)
|
||||
forAllConstIters(mapDict, iter)
|
||||
{
|
||||
wordRes patterns(iter().stream());
|
||||
|
||||
// find all matches
|
||||
Map<word> matches;
|
||||
forAllConstIter(Map<word>, origNames, namesIter)
|
||||
forAllConstIters(origNames, namesIter)
|
||||
{
|
||||
if (patterns.match(namesIter()))
|
||||
{
|
||||
@ -554,7 +554,7 @@ void Foam::cellTable::combine(const dictionary& mapDict, labelList& tableIds)
|
||||
this->erase(matches);
|
||||
origNames.erase(matches);
|
||||
|
||||
forAllConstIter(Map<word>, matches, matchIter)
|
||||
forAllConstIters(matches, matchIter)
|
||||
{
|
||||
mapping[matchIter.key()] = targetId;
|
||||
Info<< " " << matchIter();
|
||||
|
||||
@ -140,7 +140,7 @@ namespace Foam
|
||||
|
||||
forAll(valueSetNames, i)
|
||||
{
|
||||
if (i > 0)
|
||||
if (i)
|
||||
{
|
||||
writeSeparator(os);
|
||||
}
|
||||
@ -166,7 +166,7 @@ void Foam::csvSetWriter<Type>::writeHeader
|
||||
{
|
||||
for (label j=0; j<Type::nComponents; j++)
|
||||
{
|
||||
if (i>0 || j>0)
|
||||
if (i || j)
|
||||
{
|
||||
writeSeparator(os);
|
||||
}
|
||||
@ -189,12 +189,7 @@ void Foam::csvSetWriter<Type>::writeCoordHeader
|
||||
|
||||
if (points.hasVectorAxis())
|
||||
{
|
||||
for
|
||||
(
|
||||
word::const_iterator iter = axisName.begin();
|
||||
iter != axisName.end();
|
||||
++iter
|
||||
)
|
||||
for (auto iter = axisName.cbegin(); iter != axisName.cend(); ++iter)
|
||||
{
|
||||
os << *iter;
|
||||
writeSeparator(os);
|
||||
|
||||
@ -85,7 +85,7 @@ void Foam::gnuplotSetWriter<Type>::write
|
||||
|
||||
forAll(valueSets, i)
|
||||
{
|
||||
if (i != 0)
|
||||
if (i)
|
||||
{
|
||||
os << ',';
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -159,15 +159,12 @@ void Foam::nastranSetWriter<Type>::write
|
||||
// }
|
||||
|
||||
label globalPti = 0;
|
||||
forAll(tracks, tracki)
|
||||
for (const coordSet& points : tracks)
|
||||
{
|
||||
const coordSet& points = tracks[tracki];
|
||||
forAll(points, pointi)
|
||||
for (const point& pt : points)
|
||||
{
|
||||
fileFormats::NASCore::writeKeyword(os, "GRID", fieldFormat::FREE);
|
||||
|
||||
const point& pt = points[pointi];
|
||||
|
||||
//os.setf(std::ios_base::right);
|
||||
//os << setw(8) << globalPti++
|
||||
// << setw(8) << ' '
|
||||
@ -190,10 +187,8 @@ void Foam::nastranSetWriter<Type>::write
|
||||
// Write ids of track points to file
|
||||
label globalEdgei = 0;
|
||||
label globalPointi = 0;
|
||||
forAll(tracks, tracki)
|
||||
for (const coordSet& points : tracks)
|
||||
{
|
||||
const coordSet& points = tracks[tracki];
|
||||
|
||||
const label nEdges = points.size()-1;
|
||||
for (label edgei = 0; edgei < nEdges; ++edgei)
|
||||
{
|
||||
|
||||
@ -95,7 +95,7 @@ void Foam::vtkSetWriter<Type>::write
|
||||
|
||||
forAll(fld, pointi)
|
||||
{
|
||||
if (pointi != 0)
|
||||
if (pointi)
|
||||
{
|
||||
os << ' ';
|
||||
}
|
||||
@ -137,9 +137,8 @@ void Foam::vtkSetWriter<Type>::write
|
||||
<< "DATASET POLYDATA" << nl
|
||||
<< "POINTS " << nPoints << " double" << nl;
|
||||
|
||||
forAll(tracks, trackI)
|
||||
for (const coordSet& points : tracks)
|
||||
{
|
||||
const coordSet& points = tracks[trackI];
|
||||
for (const point& pt : points)
|
||||
{
|
||||
os << float(pt.x()) << ' '
|
||||
@ -158,11 +157,13 @@ void Foam::vtkSetWriter<Type>::write
|
||||
{
|
||||
const coordSet& points = tracks[trackI];
|
||||
|
||||
os << points.size();
|
||||
forAll(points, i)
|
||||
const label len = points.size();
|
||||
|
||||
os << len;
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
os << ' ' << globalPtI;
|
||||
globalPtI++;
|
||||
++globalPtI;
|
||||
}
|
||||
os << nl;
|
||||
}
|
||||
@ -179,13 +180,11 @@ void Foam::vtkSetWriter<Type>::write
|
||||
|
||||
const List<Field<Type>>& fieldVals = valueSets[setI];
|
||||
|
||||
forAll(fieldVals, i)
|
||||
for (const Field<Type>& vals : fieldVals)
|
||||
{
|
||||
const Field<Type>& vals = fieldVals[i];
|
||||
|
||||
forAll(vals, j)
|
||||
{
|
||||
if (j != 0)
|
||||
if (j)
|
||||
{
|
||||
os << ' ';
|
||||
}
|
||||
|
||||
@ -622,14 +622,14 @@ void Foam::vtk::vtuSizing::populateArrays
|
||||
if (sizing.nFaceLabels())
|
||||
{
|
||||
// End face offsets, leaving -1 untouched
|
||||
label prev = 0;
|
||||
forAll(faceOffset, i)
|
||||
LabelType prev = 0;
|
||||
for (LabelType& off : faceOffset)
|
||||
{
|
||||
const label sz = faceOffset[i];
|
||||
const auto sz = off;
|
||||
if (sz > 0)
|
||||
{
|
||||
prev += sz;
|
||||
faceOffset[i] = prev;
|
||||
off = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -639,10 +639,10 @@ void Foam::vtk::vtuSizing::populateArrays
|
||||
{
|
||||
// Has prefix, determine begin offsets
|
||||
label beg = 0;
|
||||
forAll(vertOffset, i)
|
||||
for (LabelType& off : vertOffset)
|
||||
{
|
||||
const label sz = vertOffset[i];
|
||||
vertOffset[i] = beg;
|
||||
const auto sz = off;
|
||||
off = beg;
|
||||
beg += 1 + sz;
|
||||
}
|
||||
|
||||
@ -650,12 +650,12 @@ void Foam::vtk::vtuSizing::populateArrays
|
||||
if (sizing.nFaceLabels())
|
||||
{
|
||||
beg = 0;
|
||||
forAll(faceOffset, i)
|
||||
for (LabelType& off : faceOffset)
|
||||
{
|
||||
const label sz = faceOffset[i];
|
||||
const auto sz = off;
|
||||
if (sz > 0)
|
||||
{
|
||||
faceOffset[i] = beg;
|
||||
off = beg;
|
||||
beg += sz;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||
@ -186,9 +186,9 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
lineMap_[lineI] = i;
|
||||
labelList& segment = lines_[lineI++];
|
||||
segment.setSize(nRead);
|
||||
forAll(segment, i)
|
||||
for (label& pointi : segment)
|
||||
{
|
||||
segment[i] = cellVertData[dataIndex++];
|
||||
pointi = cellVertData[dataIndex++];
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -236,9 +236,9 @@ void Foam::vtkUnstructuredReader::extractCells
|
||||
face& f = faces_[facei++];
|
||||
label nRead = cellVertData[dataIndex++];
|
||||
f.setSize(nRead);
|
||||
forAll(f, fp)
|
||||
for (label& pointi : f)
|
||||
{
|
||||
f[fp] = cellVertData[dataIndex++];
|
||||
pointi = cellVertData[dataIndex++];
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -398,9 +398,9 @@ void Foam::vtkUnstructuredReader::readField
|
||||
inFile.getLine(fieldVals()[0]);
|
||||
|
||||
// Read without parsing
|
||||
forAll(fieldVals(), i)
|
||||
for (string& s : fieldVals())
|
||||
{
|
||||
inFile.getLine(fieldVals()[i]);
|
||||
inFile.getLine(s);
|
||||
}
|
||||
regIOobject::store(fieldVals);
|
||||
}
|
||||
@ -627,9 +627,9 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
|
||||
lineMap_[lineI] = lineI;
|
||||
labelList& f = lines_[lineI];
|
||||
f.setSize(lineVerts[elemI++]);
|
||||
forAll(f, fp)
|
||||
for (label& pointi : f)
|
||||
{
|
||||
f[fp] = lineVerts[elemI++];
|
||||
pointi = lineVerts[elemI++];
|
||||
}
|
||||
lineI++;
|
||||
}
|
||||
@ -656,9 +656,9 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
|
||||
faceMap_[facei] = facei;
|
||||
face& f = faces_[facei];
|
||||
f.setSize(faceVerts[elemI++]);
|
||||
forAll(f, fp)
|
||||
for (label& pointi : f)
|
||||
{
|
||||
f[fp] = faceVerts[elemI++];
|
||||
pointi = faceVerts[elemI++];
|
||||
}
|
||||
facei++;
|
||||
}
|
||||
@ -769,11 +769,11 @@ void Foam::vtkUnstructuredReader::read(ISstream& inFile)
|
||||
);
|
||||
|
||||
label elemI = 0;
|
||||
forAll(fieldVals(), i)
|
||||
for (vector& val : fieldVals())
|
||||
{
|
||||
fieldVals()[i].x() = s[elemI++];
|
||||
fieldVals()[i].y() = s[elemI++];
|
||||
fieldVals()[i].z() = s[elemI++];
|
||||
val.x() = s[elemI++];
|
||||
val.y() = s[elemI++];
|
||||
val.z() = s[elemI++];
|
||||
}
|
||||
regIOobject::store(fieldVals);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user