Commit 07dafe7b authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: use range-for when looping dictionary entries.

- as part of the cleanup of dictionary access methods (c6520033)
  made the dictionary class single inheritance from IDLList<entry>.

  This eliminates any ambiguities for iterators and allows
  for simple use of range-for looping.

  Eg,
      for (const entry& e : topDict))
      {
          Info<< "entry:" << e.keyword() << " is dict:" << e.isDict() << nl;
      }

   vs

      forAllConstIter(dictionary, topDict, iter))
      {
          Info<< "entry:" << iter().keyword()
              << " is dict:" << iter().isDict() << nl;
      }
parent 4e04c196
......@@ -25,12 +25,7 @@
PtrList<fvScalarMatrix> p_rghEqnComps(mixture.phases().size());
label phasei = 0;
forAllConstIter
(
PtrDictionary<phaseModel>,
mixture.phases(),
phase
)
forAllConstIters(mixture.phases(), phase)
{
const rhoThermo& thermo = phase().thermo();
const volScalarField& rho = thermo.rho()();
......@@ -61,12 +56,7 @@
tmp<fvScalarMatrix> p_rghEqnComp;
phasei = 0;
forAllConstIter
(
PtrDictionary<phaseModel>,
mixture.phases(),
phase
)
forAllConstIters(mixture.phases(), phase)
{
tmp<fvScalarMatrix> hmm
(
......
......@@ -35,12 +35,7 @@
- fvm::laplacian(rAUf, p_rgh)
);
forAllConstIter
(
phaseSystem::phasePairTable,
fluid.totalPhasePairs(),
iter
)
forAllConstIters(fluid.totalPhasePairs(), iter)
{
const phasePair& pair = iter()();
......
......@@ -202,7 +202,7 @@ void Foam::MultiComponentPhaseModel<BasePhaseModel, phaseThermo>::solveYi
surfaceScalarField phir(0.0*phi);
forAllConstIter(phaseSystem::phaseModelTable,this->fluid().phases(),iter2)
forAllConstIters(this->fluid().phases(),iter2)
{
const volScalarField& alpha2 = iter2();
if (&alpha2 == &alpha1)
......@@ -251,10 +251,7 @@ void Foam::MultiComponentPhaseModel<BasePhaseModel, phaseThermo>::solveYi
surfaceScalarField& phiYiCorr = phiYiCorrs[i];
forAllConstIter
(
phaseSystem::phaseModelTable, this->fluid().phases(), iter2
)
forAllConstIters(this->fluid().phases(), iter2)
{
//const volScalarField& alpha2 = iter2()().oldTime();
const volScalarField& alpha2 = iter2();
......
......@@ -125,15 +125,8 @@ massTransfer() const
this->massTransferModels_[key][phase.name()]->K()
);
forAllConstIter
(
hashedWordList,
compositionModel.species(),
memberIter
)
for (const word& member : compositionModel.species())
{
const word& member = *memberIter;
const word name
(
IOobject::groupName(member, phase.name())
......
......@@ -157,14 +157,14 @@ Foam::phaseSystem::phaseSystem
phi_.writeOpt() = IOobject::AUTO_WRITE;
// Blending methods
forAllConstIter(dictionary, subDict("blending"), iter)
for (const entry& dEntry : subDict("blending"))
{
blendingMethods_.insert
(
iter().dict().dictName(),
dEntry.dict().dictName(),
blendingMethod::New
(
iter().dict(),
dEntry.dict(),
phaseModels_.toc()
)
);
......
......@@ -113,14 +113,14 @@ Foam::twoPhaseSystem::twoPhaseSystem
// Blending
forAllConstIter(dictionary, subDict("blending"), iter)
for (const entry& dEntry : subDict("blending"))
{
blendingMethods_.insert
(
iter().dict().dictName(),
dEntry.dict().dictName(),
blendingMethod::New
(
iter().dict(),
dEntry.dict(),
wordList(lookup("phases"))
)
);
......
......@@ -182,11 +182,11 @@ int main(int argc, char *argv[])
dictionary inputDict(is);
forAllConstIters(inputDict, iter)
for (const entry& dEntry : inputDict)
{
if (iter().isDict())
if (dEntry.isDict())
{
doTest(runTime, iter().dict());
doTest(runTime, dEntry.dict());
}
}
}
......@@ -204,11 +204,11 @@ int main(int argc, char *argv[])
dictionary inputDict(is);
forAllConstIters(inputDict, iter)
for (const entry& dEntry : inputDict)
{
if (iter().isDict())
if (dEntry.isDict())
{
doTest(iter().dict());
doTest(dEntry.dict());
}
}
}
......
......@@ -650,17 +650,19 @@ int main(int argc, char *argv[])
// Per faceSet the patch to put the coupled baffles into
DynamicList<FixedList<word, 3>> coupledAndPatches(10);
const dictionary& functionDicts = dict.subDict("coupledFaces");
forAllConstIter(dictionary, functionDicts, iter)
for (const entry& dEntry : functionDicts)
{
// safety:
if (!iter().isDict())
if (!dEntry.isDict()) // Safety
{
continue;
}
const word& key = iter().keyword();
const dictionary& dict = iter().dict();
const word& key = dEntry.keyword();
const dictionary& dict = dEntry.dict();
const word cyclicName = dict.get<word>("cyclicMasterPatch");
const word wallName = dict.get<word>("wallPatch");
FixedList<word, 3> nameAndType;
......
......@@ -93,14 +93,10 @@ Foam::cellSizeAndAlignmentControls::cellSizeAndAlignmentControls
{
label functionI = 0;
forAllConstIter(dictionary, shapeControlDict_, iter)
for (const entry& dEntry : shapeControlDict_)
{
word shapeControlEntryName = iter().keyword();
const dictionary& controlFunctionDict
(
shapeControlDict_.subDict(shapeControlEntryName)
);
const word& shapeControlEntryName = dEntry.keyword();
const dictionary& controlFunctionDict = dEntry.dict();
Info<< nl << "Shape Control : " << shapeControlEntryName << endl;
Info<< incrIndent;
......
......@@ -535,16 +535,12 @@ Foam::conformationSurfaces::conformationSurfaces
Info<< nl << "Reading additionalFeatures" << endl;
}
forAllConstIter(dictionary, additionalFeaturesDict, iter)
for (const entry& dEntry : additionalFeaturesDict)
{
word featureName = iter().keyword();
const word& featureName = dEntry.keyword();
const dictionary& featureSubDict = dEntry.dict();
Info<< nl << " " << iter().keyword() << endl;
const dictionary& featureSubDict
(
additionalFeaturesDict.subDict(featureName)
);
Info<< nl << " " << featureName << endl;
readFeatures(featureSubDict, featureName, featureI);
}
......
......@@ -474,27 +474,24 @@ int main(int argc, char *argv[])
const dictionary& selectionsDict = dict.subDict("baffles");
label n = 0;
forAllConstIter(dictionary, selectionsDict, iter)
{
if (iter().isDict())
{
n++;
}
}
selectors.setSize(n);
n = 0;
forAllConstIter(dictionary, selectionsDict, iter)
selectors.resize(selectionsDict.size());
label nselect = 0;
for (const entry& dEntry : selectionsDict)
{
if (iter().isDict())
if (dEntry.isDict())
{
selectors.set
(
n++,
faceSelection::New(iter().keyword(), mesh, iter().dict())
nselect,
faceSelection::New(dEntry.keyword(), mesh, dEntry.dict())
);
++nselect;
}
}
selectors.resize(nselect);
}
......@@ -641,10 +638,9 @@ int main(int argc, char *argv[])
if (dict.found("patches"))
{
const dictionary& patchSources = dict.subDict("patches");
forAllConstIter(dictionary, patchSources, iter)
for (const entry& dEntry : dict.subDict("patches"))
{
const word patchName(iter().dict().get<word>("name"));
const word patchName(dEntry.dict().get<word>("name"));
bafflePatches.insert(patchName);
}
......@@ -687,14 +683,15 @@ int main(int argc, char *argv[])
if (dict.found("patches"))
{
const dictionary& patchSources = dict.subDict("patches");
forAllConstIter(dictionary, patchSources, iter)
for (const entry& dEntry : dict.subDict("patches"))
{
const word patchName(iter().dict().get<word>("name"));
const dictionary& dict = dEntry.dict();
const word patchName(dict.get<word>("name"));
if (pbm.findPatchID(patchName) == -1)
{
dictionary patchDict = iter().dict();
dictionary patchDict = dict;
patchDict.set("nFaces", 0);
patchDict.set("startFace", 0);
......@@ -789,13 +786,14 @@ int main(int argc, char *argv[])
if (dict.found("patches"))
{
const dictionary& patchSources = dict.subDict("patches");
bool master = true;
forAllConstIter(dictionary, patchSources, iter)
for (const entry& dEntry : dict.subDict("patches"))
{
const word patchName(iter().dict().get<word>("name"));
label patchi = pbm.findPatchID(patchName);
const word patchName(dEntry.dict().get<word>("name"));
const label patchi = pbm.findPatchID(patchName);
if (master)
{
newMasterPatches.append(patchi);
......@@ -885,17 +883,18 @@ int main(int argc, char *argv[])
const dictionary& dict = selectors[selectorI].dict();
if (dict.found("patches"))
{
const dictionary& patchSources = dict.subDict("patches");
forAllConstIter(dictionary, patchSources, iter)
for (const entry& dEntry : dict.subDict("patches"))
{
const word patchName(iter().dict().get<word>("name"));
const dictionary& dict = dEntry.dict();
const word patchName(dict.get<word>("name"));
label patchi = pbm.findPatchID(patchName);
if (iter().dict().found("patchFields"))
if (dEntry.dict().found("patchFields"))
{
const dictionary& patchFieldsDict =
iter().dict().subDict
dEntry.dict().subDict
(
"patchFields"
);
......@@ -928,11 +927,11 @@ int main(int argc, char *argv[])
if (sameGroup)
{
// Add coupleGroup to all entries
forAllIter(dictionary, patchFieldsDict, iter)
for (entry& dEntry : patchFieldsDict)
{
if (iter().isDict())
if (dEntry.isDict())
{
dictionary& dict = iter().dict();
dictionary& dict = dEntry.dict();
dict.set("coupleGroup", groupName);
}
}
......
......@@ -292,16 +292,17 @@ int main(int argc, char *argv[])
// Suppress duplicate names
wordHashSet requestedPatches;
forAllConstIters(stitchDict, iter)
for (const entry& dEntry : stitchDict)
{
if (!iter().isDict())
if (!dEntry.isDict())
{
Info<< "Ignoring non-dictionary entry: "
<< iter().keyword() << nl;
<< dEntry.keyword() << nl;
continue;
}
const dictionary& dict = iter().dict();
const keyType& key = dEntry.keyword();
const dictionary& dict = dEntry.dict();
// Match type
word matchName;
......@@ -358,7 +359,7 @@ int main(int argc, char *argv[])
// Input was validated
validatedDict.add(iter().keyword(), iter().dict());
validatedDict.add(key, dict);
}
}
......@@ -433,9 +434,9 @@ int main(int argc, char *argv[])
// Step through the topology changes
label actioni = 0;
forAllConstIters(validatedDict, iter)
for (const entry& dEntry : validatedDict)
{
const dictionary& dict = iter().dict();
const dictionary& dict = dEntry.dict();
// Match type
bool perfect = false;
......
......@@ -97,10 +97,10 @@ HashTable<wordList> extractPatchGroups(const dictionary& boundaryDict)
{
HashTable<wordList> groupToPatch;
forAllConstIter(dictionary, boundaryDict, iter)
for (const entry& dEntry : boundaryDict)
{
const word& patchName = iter().keyword();
const dictionary& patchDict = iter().dict();
const word& patchName = dEntry.keyword();
const dictionary& patchDict = dEntry.dict();
wordList groups;
if (patchDict.readIfPresent("inGroups", groups))
......@@ -243,9 +243,9 @@ bool merge
// Pass 1. All literal matches
forAllConstIter(IDLList<entry>, mergeDict, mergeIter)
for (const entry& mergeEntry : mergeDict)
{
const keyType& key = mergeIter().keyword();
const keyType& key = mergeEntry.keyword();
if (key[0] == '~')
{
......@@ -274,7 +274,7 @@ bool merge
(
thisDict,
*eptr,
mergeIter(),
mergeEntry,
literalRE,
shortcuts
)
......@@ -287,8 +287,8 @@ bool merge
{
if (addNonExisting)
{
// not found - just add
thisDict.add(mergeIter().clone(thisDict).ptr());
// Not found - just add
thisDict.add(mergeEntry.clone(thisDict).ptr());
changed = true;
}
else
......@@ -309,9 +309,9 @@ bool merge
// Pick up remaining dictionary entries
wordList thisKeys(thisKeysSet.toc());
forAllConstIter(IDLList<entry>, mergeDict, mergeIter)
for (const entry& mergeEntry : mergeDict)
{
const keyType& key = mergeIter().keyword();
const keyType& key = mergeEntry.keyword();
if (key[0] == '~')
{
......@@ -364,7 +364,7 @@ bool merge
(
thisDict,
*eptr,
mergeIter(),
mergeEntry,
literalRE,
HashTable<wordList>(0) // no shortcuts
// at deeper levels
......@@ -462,7 +462,7 @@ int main(int argc, char *argv[])
const bool enableEntries = args.found("enableFunctionEntries");
if (enableEntries)
{
Info<< "Allowing dictionary preprocessing ('#include', '#codeStream')."
Info<< "Allowing dictionary preprocessing (#include, #codeStream)."
<< endl;
}
......@@ -550,9 +550,9 @@ int main(int argc, char *argv[])
// Temporary convert to dictionary
dictionary fieldDict;
forAll(dictList, i)
for (const entry& e : dictList)
{
fieldDict.add(dictList[i].keyword(), dictList[i].dict());
fieldDict.add(e.keyword(), e.dict());
}
if (dictList.size())
......@@ -582,9 +582,11 @@ int main(int argc, char *argv[])
// Every replacement is a dictionary name and a keyword in this
forAllConstIter(dictionary, replaceDicts, fieldIter)
for (const entry& replaceEntry : replaceDicts)
{
const word& fieldName = fieldIter().keyword();
const word& fieldName = replaceEntry.keyword();
const dictionary& replaceDict = replaceEntry.dict();
Info<< "Replacing entries in dictionary " << fieldName << endl;
// Handle 'boundary' specially:
......@@ -595,11 +597,8 @@ int main(int argc, char *argv[])
Info<< "Special handling of " << fieldName
<< " as polyMesh/boundary file." << endl;
// Get the replacement dictionary for the field
const dictionary& replaceDict = fieldIter().dict();
Info<< "Merging entries from " << replaceDict.toc() << endl;
// Merge the replacements in. Do not add non-existing entries.
Info<< "Merging entries from " << replaceDict.toc() << endl;
merge(false, fieldDict, replaceDict, literalRE, patchGroups);
Info<< "fieldDict:" << fieldDict << endl;
......@@ -627,9 +626,9 @@ int main(int argc, char *argv[])
// Add remaining entries
label sz = dictList.size();
dictList.setSize(nEntries);
forAllConstIter(dictionary, fieldDict, iter)
for (const entry& e : fieldDict)
{
dictList.set(sz++, iter().clone());
dictList.set(sz++, e.clone());
}
Info<< "Writing modified " << fieldName << endl;
......@@ -672,11 +671,8 @@ int main(int argc, char *argv[])
Info<< "Loaded dictionary " << fieldName
<< " with entries " << fieldDict.toc() << endl;
// Get the replacement dictionary for the field
const dictionary& replaceDict = fieldIter().dict();
Info<< "Merging entries from " << replaceDict.toc() << endl;
// Merge the replacements in (allow adding)
Info<< "Merging entries from " << replaceDict.toc() << endl;
merge(true, fieldDict, replaceDict, literalRE, patchGroups);
Info<< "Writing modified fieldDict " << fieldName << endl;
......
......@@ -54,9 +54,9 @@ Foam::boundaryTemplates::boundaryTemplates
)
);
forAllConstIter(dictionary, regionBCs, iter)
for (const entry& dEntry : regionBCs)
{
const word& regionType = iter().keyword();
const word& regionType = dEntry.keyword();
wordList patchTypes(regionBCs.lookup(regionType));
dictionary regionTemplate = dictionary::null;
......@@ -175,7 +175,7 @@ Foam::dictionary Foam::boundaryTemplates::generatePatchDict
// look for inlet, outlet, wall etc
if (regionTemplates.found(category))
{
const dictionary& categoryDict(regionTemplates.subDict(category));
const dictionary& categoryDict = regionTemplates.subDict(category);
// look for subSonic, slip etc
if (categoryDict.found(patchType))
......@@ -199,10 +199,8 @@ Foam::dictionary Foam::boundaryTemplates::generatePatchDict
const wordList requiredOptions(patchDict.lookup("OPTIONS"));
forAll(requiredOptions, i)
for (const word& option : requiredOptions)
{
const word& option = requiredOptions[i];
word selected;
if (!conditionOptions.readIfPresent(option, selected))
{
......@@ -252,18 +250,19 @@ Foam::dictionary Foam::boundaryTemplates::generatePatchDict
dictionary dict(dictionary::null);
const dictionary& fieldDict(patchDict.subDict(fieldName));
forAllConstIter(IDLList<entry>, fieldDict, iter)
for (const entry& dEntry : fieldDict)
{
OStringStream oss;
oss << iter();
oss << dEntry;
string s(oss.str());
s.replace(iter().keyword(), "");
s.replace(dEntry.keyword(),