ENH: use dictionary::readEntry for detection of input errors (#762, #1033)

- instead of   dict.lookup(name) >> val;
  can use      dict.readEntry(name, val);

  for checking of input token sizes.
  This helps catch certain types of input errors:

  {

      key1 ;                // <- Missing value
      key2 1234             // <- Missing ';' terminator
      key3 val;
  }

STYLE: readIfPresent() instead of 'if found ...' in a few more places.
This commit is contained in:
Mark Olesen
2018-10-05 10:15:13 +02:00
parent 7d88075842
commit 13778f7647
178 changed files with 420 additions and 479 deletions

View File

@ -362,7 +362,7 @@ int main(int argc, char *argv[])
/"processor" + Foam::name(Pstream::myProcNo());
}
wordList sourcePatches;
dict.lookup("sourcePatches") >> sourcePatches;
dict.readEntry("sourcePatches", sourcePatches);
if (sourcePatches.size() == 1)
{
@ -581,7 +581,7 @@ int main(int argc, char *argv[])
labelList exposedPatchID;
if (mode == PATCH)
{
dict.lookup("exposedPatchName") >> backPatchName;
dict.readEntry("exposedPatchName", backPatchName);
exposedPatchID.setSize
(
extrudePatch.size(),

View File

@ -1514,7 +1514,7 @@ int main(int argc, char *argv[])
const bool hasZones = dict.found("faceZones");
if (hasZones)
{
dict.lookup("faceZones") >> zoneNames;
dict.readEntry("faceZones", zoneNames);
dict.readIfPresent("faceZonesShadow", zoneShadowNames);
// Check
@ -1528,7 +1528,7 @@ int main(int argc, char *argv[])
}
else
{
dict.lookup("faceSets") >> zoneNames;
dict.readEntry("faceSets", zoneNames);
dict.readIfPresent("faceSetsShadow", zoneShadowNames);
}

View File

@ -71,10 +71,9 @@ Foam::surfaceOffsetLinearDistance::surfaceOffsetLinearDistance
totalDistance_(),
totalDistanceSqr_()
{
if (coeffsDict().found("totalDistanceCoeff"))
if (coeffsDict().readIfPresent("totalDistanceCoeff", totalDistance_))
{
totalDistance_ =
coeffsDict().get<scalar>("totalDistanceCoeff") * defaultCellSize;
totalDistance_ *= defaultCellSize;
if (coeffsDict().found("linearDistanceCoeff"))
{
@ -84,11 +83,10 @@ Foam::surfaceOffsetLinearDistance::surfaceOffsetLinearDistance
<< nl << exit(FatalError) << endl;
}
}
else if (coeffsDict().found("linearDistanceCoeff"))
else if (coeffsDict().readIfPresent("linearDistanceCoeff", totalDistance_))
{
totalDistance_ =
coeffsDict().get<scalar>("linearDistanceCoeff") * defaultCellSize
+ surfaceOffset_;
totalDistance_ *= defaultCellSize;
totalDistance_ += surfaceOffset_;
}
else
{

View File

@ -749,7 +749,7 @@ int main(int argc, char *argv[])
<< endl;
}
renumberDict.lookup("writeMaps") >> writeMaps;
renumberDict.readEntry("writeMaps", writeMaps);
if (writeMaps)
{
Info<< "Writing renumber maps (new to old) to polyMesh." << nl