ENH: support predicate checks for argList (similar to dictionary methods)

- Favour use of argList methods that are more similar to dictionary
  method names with the aim of reducing the cognitive load.

  * Silently deprecate two-parameter get() method in favour of the
    more familiar getOrDefault.
  * Silently deprecate opt() method in favour of get()

  These may be verbosely deprecated in future versions.
This commit is contained in:
Mark Olesen 2020-06-02 12:22:54 +02:00
parent 695766af16
commit 31b172217c
76 changed files with 398 additions and 170 deletions

View File

@ -40,7 +40,7 @@ if (args.found("initialiseUBCs"))
// converting fixed-value BCs to zero-gradient and vice versa.
// Allow override from command-line -pName option
const word pName = args.get<word>("pName", "p");
const word pName = args.getOrDefault<word>("pName", "p");
// Infer the pressure BCs from the velocity
wordList pBCTypes

View File

@ -40,7 +40,7 @@ if (args.found("initialiseUBCs"))
// converting fixed-value BCs to zero-gradient and vice versa.
// Allow override from command-line -pName option
const word pName = args.get<word>("pName", "p");
const word pName = args.getOrDefault<word>("pName", "p");
// Infer the pressure BCs from the velocity
wordList pBCTypes

View File

@ -121,7 +121,7 @@ volScalarField alphac
const word kinematicCloudName
(
args.get<word>("cloud", "kinematicCloud")
args.getOrDefault<word>("cloud", "kinematicCloud")
);
Info<< "Constructing kinematicCloud " << kinematicCloudName << endl;

View File

@ -59,7 +59,7 @@ volScalarField mu
const word kinematicCloudName
(
args.get<word>("cloud", "kinematicCloud")
args.getOrDefault<word>("cloud", "kinematicCloud")
);
Info<< "Constructing kinematicCloud " << kinematicCloudName << endl;

View File

@ -51,7 +51,7 @@ autoPtr<compressible::turbulenceModel> turbulence
const word kinematicCloudName
(
args.get<word>("cloud", "kinematicCloud")
args.getOrDefault<word>("cloud", "kinematicCloud")
);
Info<< "Constructing kinematicCloud " << kinematicCloudName << endl;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,11 +29,53 @@ Description
#include "argList.H"
#include "IOstreams.H"
#include "MinMax.H"
#include "Switch.H"
#include "StringStream.H"
using namespace Foam;
void predicateTests_label(const word& optName, const argList& args)
{
Info<< "predicate tests for " << optName << nl;
const bool throwingError = FatalError.throwExceptions();
try
{
label val;
val = args.getCheck<label>(optName, labelMinMax::ge(0));
}
catch (const Foam::error& err)
{
Info<< "Caught FatalError "
<< err << nl << endl;
}
FatalError.throwExceptions(throwingError);
}
void predicateTests_scalar(const word& optName, const argList& args)
{
Info<< "predicate tests for " << optName << nl;
const bool throwingError = FatalError.throwExceptions();
try
{
scalar val;
val = args.getCheck<scalar>(optName, scalarMinMax::ge(0));
}
catch (const Foam::error& err)
{
Info<< "Caught FatalError "
<< err << nl << endl;
}
FatalError.throwExceptions(throwingError);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
@ -47,6 +89,11 @@ int main(int argc, char *argv[])
argList::addOption("scalar", "value", "Test parsing of scalar");
argList::addOption("string", "value", "Test string lookup");
argList::addOption("relative", "PATH", "Test relativePath");
argList::addBoolOption
(
"predicates",
"Apply some predicate tests (for label and scalar)"
);
// These are actually lies (never had -parseLabel, -parseScalar etc),
// but good for testing...
@ -105,6 +152,11 @@ int main(int argc, char *argv[])
if (args.readIfPresent("label", ival))
{
Info<< ival << nl;
if (args.found("predicates"))
{
predicateTests_label("label", args);
}
}
else
{
@ -115,6 +167,11 @@ int main(int argc, char *argv[])
if (args.readIfPresent("scalar", sval))
{
Info<< sval << nl;
if (args.found("predicates"))
{
predicateTests_scalar("scalar", args);
}
}
else
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -86,7 +86,8 @@ int main(int argc, char *argv[])
instantList times = timeSelector::selectIfPresent(runTime, args);
// Allow override of decomposeParDict location
const fileName decompDictFile = args.get<fileName>("decomposeParDict", "");
const fileName decompDictFile =
args.getOrDefault<fileName>("decomposeParDict", "");
wordList regionNames;
wordList regionDirs;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -100,8 +100,8 @@ int main(int argc, char *argv[])
const bool allRegions = args.found("allRegions");
const bool verbose = args.found("verbose");
const label numSubdomains = args.get<label>("domains", 0);
const word methodName = args.get<word>("method", word::null);
const label numSubdomains = args.getOrDefault<label>("domains", 0);
const word methodName = args.getOrDefault<word>("method", word::null);
// Set time from database
#include "createTime.H"
@ -109,7 +109,8 @@ int main(int argc, char *argv[])
instantList times = timeSelector::selectIfPresent(runTime, args);
// Allow override of decomposeParDict location
const fileName decompDictFile = args.get<fileName>("decomposeParDict", "");
const fileName decompDictFile =
args.getOrDefault<fileName>("decomposeParDict", "");
// Get all region names
wordList regionNames;
@ -123,7 +124,8 @@ int main(int argc, char *argv[])
else
{
regionNames.resize(1);
regionNames.first() = args.get<word>("region", fvMesh::defaultRegion);
regionNames.first() =
args.getOrDefault<word>("region", fvMesh::defaultRegion);
}
forAll(regionNames, regioni)

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -47,7 +47,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const label maxCount = args.get<label>("max", 1000);
const label maxCount = args.getOrDefault<label>("max", 1000);
externalFileCoupler coupler;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -198,7 +199,7 @@ int main(int argc, char *argv[])
}
{
const label celli = args.get<label>("cell", 0);
const label celli = args.getOrDefault<label>("cell", 0);
tensorField mI(momentOfInertia::meshInertia(mesh));

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -67,7 +68,7 @@ int main(int argc, char *argv[])
bool useBSpline = args.found("B");
bool useCatmullRom = args.found("CMR");
const label nSeg = args.get<label>("n", 20);
const label nSeg = args.getOrDefault<label>("n", 20);
if (!useCatmullRom && !useBSpline)
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -130,7 +130,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
const scalar scaleFactor = args.get<scalar>("scale", -1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", -1);
const word outputFile(args.executable() + ".obj");

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -141,7 +141,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const bool optStdout = args.found("stdout");
const scalar scaleFactor = args.get<scalar>("scale", 0);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 0);
const fileName importName = args[1];
const fileName exportName = optStdout ? "-stdout" : args[2];

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -84,8 +84,7 @@ int main(int argc, char *argv[])
return 1;
}
const word writerType =
args.lookupOrDefault<word>("type", exportName.ext());
const word writerType = args.getOrDefault<word>("type", exportName.ext());
auto surfWriter = surfaceWriter::New(writerType);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -53,7 +54,7 @@ int main(int argc, char *argv[])
argList args(argc, argv, false, true);
const label repeat = args.get<label>("repeat", 1);
const label repeat = args.getOrDefault<label>("repeat", 1);
const bool optVerbose = args.found("verbose");

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -47,7 +47,7 @@ int main(int argc, char *argv[])
argList args(argc, argv, false, true);
const scalar currTime = args.get<scalar>("time", GREAT);
const scalar currTime = args.getOrDefault<scalar>("time", GREAT);
Info<< "Using currTime = " << currTime << nl
<< "when loading " << (args.size()-1) << " files" << nl << nl;

View File

@ -125,7 +125,7 @@ int main(int argc, char *argv[])
}
{
const int prec = args.lookupOrDefault<int>("precision", 0u);
const int prec = args.getOrDefault<int>("precision", 0u);
if (prec > 0)
{
IOstream::defaultPrecision(prec);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -383,7 +383,7 @@ int main(int argc, char *argv[])
// Sin of angle between two consecutive edges on a face.
// If sin(angle) larger than this the face will be considered concave.
const scalar concaveAngle = args.get<scalar>("concaveAngle", 30);
const scalar concaveAngle = args.getOrDefault<scalar>("concaveAngle", 30);
const scalar concaveSin = Foam::sin(degToRad(concaveAngle));

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -561,7 +562,7 @@ int main(int argc, char *argv[])
const bool geometry = args.found("geometry");
const bool overwrite = args.found("overwrite");
const scalar edgeTol = args.get<scalar>("tol", 0.2);
const scalar edgeTol = args.getOrDefault<scalar>("tol", 0.2);
Info<< "Trying to split cells with internal angles > feature angle\n" << nl
<< "featureAngle : " << featureAngle << nl

View File

@ -323,7 +323,7 @@ int main(int argc, char *argv[])
FatalError.exit();
}
const scalar scaleFactor = args.get<scalar>("scale", 1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 1);
#include "createTime.H"

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -188,7 +188,7 @@ int main(int argc, char *argv[])
}
// By default, no scaling
const scalar scaleFactor = args.get<scalar>("scale", 1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 1);
// Default to binary output, unless otherwise specified
const IOstream::streamFormat format =

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -71,7 +72,7 @@ int main(int argc, char *argv[])
FatalError.exit();
}
const scalar scaleFactor = args.get<scalar>("scale", 1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 1);
#include "createTime.H"

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -105,7 +105,7 @@ int main(int argc, char *argv[])
(
args[1],
// Default no scaling
args.get<scalar>("scale", 1)
args.getOrDefault<scalar>("scale", 1)
);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -904,7 +905,7 @@ int main(int argc, char *argv[])
FatalError.exit();
}
const scalar scaleFactor = args.get<scalar>("scale", 1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 1);
const bool writeSets = args.found("writeSets");
const bool writeZones = args.found("writeZones");

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -99,7 +99,7 @@ int main(int argc, char *argv[])
}
// Default rescale from [m] to [mm]
const scalar scaleFactor = args.get<scalar>("scale", 1000);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 1000);
const bool writeBndFile = !args.found("noBnd");
#include "createPolyMesh.H"

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -83,7 +84,7 @@ int main(int argc, char *argv[])
fileName exportName = args[1];
const scalar scaleFactor = args.get<scalar>("scale", 0);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 0);
const bool doTriangulate = args.found("tri");
fileName exportBase = exportName.lessExt();

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -648,7 +649,7 @@ int main(int argc, char *argv[])
FatalError.exit();
}
const scalar scaleFactor = args.get<scalar>("scale", 1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 1);
#include "createTime.H"

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -87,7 +88,8 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
const fileName kivaFileName = args.get<fileName>("file", "otape17");
const fileName kivaFileName =
args.getOrDefault<fileName>("file", "otape17");
kivaVersions kivaVersion = kiva3v;
if (args.found("version"))
@ -113,7 +115,7 @@ int main(int argc, char *argv[])
}
}
const scalar zHeadMin = args.get<scalar>("zHeadMin", -GREAT);
const scalar zHeadMin = args.getOrDefault<scalar>("zHeadMin", -GREAT);
#include "readKivaGrid.H"

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -96,7 +97,7 @@ int main(int argc, char *argv[])
FatalError.exit();
}
const scalar scaleFactor = args.get<scalar>("scale", 1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", 1);
const bool readBlank = !args.found("noBlank");
const bool singleBlock = args.found("singleBlock");

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -116,7 +116,7 @@ int main(int argc, char *argv[])
prefix,
runTime,
// Default rescale from [mm] to [m]
args.get<scalar>("scale", 0.001),
args.getOrDefault<scalar>("scale", 0.001),
args.found("solids")
);

View File

@ -250,7 +250,7 @@ int main(int argc, char *argv[])
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
),
args.get<fileName>("dict", "")
args.getOrDefault<fileName>("dict", "")
)
);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -74,7 +74,7 @@ int main(int argc, char *argv[])
// Allow override of decomposeParDict location
const fileName decompDictFile =
args.get<fileName>("decomposeParDict", "");
args.getOrDefault<fileName>("decomposeParDict", "");
IOdictionary foamyHexMeshDict
(

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -64,7 +64,8 @@ scalar getMergeDistance
const boundBox& bb
)
{
const scalar mergeTol = args.get<scalar>("mergeTol", defaultMergeTol);
const scalar mergeTol =
args.getOrDefault<scalar>("mergeTol", defaultMergeTol);
scalar writeTol =
Foam::pow(scalar(10), -scalar(IOstream::defaultPrecision()));
@ -522,7 +523,7 @@ int main(int argc, char *argv[])
// Allow override of decomposeParDict location
const fileName decompDictFile =
args.get<fileName>("decomposeParDict", "");
args.getOrDefault<fileName>("decomposeParDict", "");
labelList decomp = decompositionModel::New
(

View File

@ -894,7 +894,7 @@ int main(int argc, char *argv[])
IOobject::MUST_READ,
IOobject::NO_WRITE
),
args.get<fileName>("decomposeParDict", "")
args.getOrDefault<fileName>("decomposeParDict", "")
)
);
@ -1979,7 +1979,7 @@ int main(int argc, char *argv[])
fileName outFileName
(
args.get<fileName>
args.getOrDefault<fileName>
(
"outFile",
"constant/triSurface/simplifiedSurface.stl"

View File

@ -139,7 +139,7 @@ int main(int argc, char *argv[])
const bool allTopology = args.found("allTopology");
const bool meshQuality = args.found("meshQuality");
const word surfaceFormat = args.get<word>("writeSets", "");
const word surfaceFormat = args.getOrDefault<word>("writeSets", "");
const bool writeSets = surfaceFormat.size();
wordHashSet selectedFields;

View File

@ -534,7 +534,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
const word meshRegionName =
args.get<word>("region", polyMesh::defaultRegion);
args.getOrDefault<word>("region", polyMesh::defaultRegion);
const bool overwrite = args.found("overwrite");

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2017 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -106,10 +106,10 @@ int main(int argc, char *argv[])
fileName addCase = args[2];
const word masterRegion =
args.get<word>("masterRegion", polyMesh::defaultRegion);
args.getOrDefault<word>("masterRegion", polyMesh::defaultRegion);
const word addRegion =
args.get<word>("addRegion", polyMesh::defaultRegion);
args.getOrDefault<word>("addRegion", polyMesh::defaultRegion);
// Since we don't use argList processor directory detection, add it to
// the casename ourselves so it triggers the logic inside TimePath.

View File

@ -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.
@ -203,7 +203,7 @@ int main(int argc, char *argv[])
const word dictName("refineMeshDict");
// Obtain dictPath here for messages
fileName dictPath = args.get<fileName>("dict", "");
fileName dictPath = args.getOrDefault<fileName>("dict", "");
IOobject dictIO = IOobject::selectIO
(

View File

@ -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.
@ -261,13 +261,13 @@ int main(int argc, char *argv[])
if (args.found("time"))
{
if (args.opt("time") == "constant")
if (args["time"] == "constant")
{
runTime.setTime(instant(0, "constant"), 0);
}
else
{
scalar timeValue = args.get<scalar>("time");
const scalar timeValue = args.get<scalar>("time");
runTime.setTime(instant(timeValue), 0);
}
}

View File

@ -360,7 +360,7 @@ int main(int argc, char *argv[])
// Set the default output precision
{
const unsigned prec = args.lookupOrDefault<unsigned>("precision", 0u);
const unsigned prec = args.getOrDefault<unsigned>("precision", 0u);
if (prec)
{
// if (Pstream::master())

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -330,7 +330,8 @@ int main(int argc, char *argv[])
// Allow override of decomposeParDict location
const fileName decompDictFile = args.get<fileName>("decomposeParDict", "");
const fileName decompDictFile =
args.getOrDefault<fileName>("decomposeParDict", "");
// Get all region names
wordList regionNames;
@ -344,7 +345,8 @@ int main(int argc, char *argv[])
else
{
regionNames.resize(1);
regionNames.first() = args.get<word>("region", fvMesh::defaultRegion);
regionNames.first() =
args.getOrDefault<word>("region", fvMesh::defaultRegion);
}
forAll(regionNames, regioni)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2017 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -509,7 +509,8 @@ int main(int argc, char *argv[])
Info<< "Operating on region " << regionName << nl << endl;
}
const scalar mergeTol = args.get<scalar>("mergeTol", defaultMergeTol);
const scalar mergeTol =
args.getOrDefault<scalar>("mergeTol", defaultMergeTol);
scalar writeTol = Foam::pow(10.0, -scalar(IOstream::defaultPrecision()));

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2018 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -119,7 +119,8 @@ scalar getMergeDistance
const boundBox& bb
)
{
const scalar mergeTol = args.get<scalar>("mergeTol", defaultMergeTol);
const scalar mergeTol =
args.getOrDefault<scalar>("mergeTol", defaultMergeTol);
const scalar writeTol =
Foam::pow(scalar(10), -scalar(IOstream::defaultPrecision()));
@ -2500,7 +2501,8 @@ int main(int argc, char *argv[])
// Allow override of decomposeParDict location
const fileName decompDictFile = args.get<fileName>("decomposeParDict", "");
const fileName decompDictFile =
args.getOrDefault<fileName>("decomposeParDict", "");
// Get all region names
wordList regionNames;
@ -2514,7 +2516,8 @@ int main(int argc, char *argv[])
else
{
regionNames.resize(1);
regionNames.first() = args.get<word>("region", fvMesh::defaultRegion);
regionNames.first() =
args.getOrDefault<word>("region", fvMesh::defaultRegion);
}

View File

@ -357,7 +357,7 @@ int main(int argc, char *argv[])
// Forced point interpolation?
caseOpts.nodeValues(doPointValues && args.found("nodeValues"));
caseOpts.width(args.get<label>("width", 8));
caseOpts.width(args.getOrDefault<label>("width", 8));
caseOpts.overwrite(!args.found("no-overwrite")); // Remove existing?
// Can also have separate directory for lagrangian
@ -366,7 +366,7 @@ int main(int argc, char *argv[])
// Define sub-directory name to use for EnSight data.
// The path to the ensight directory is at case level only
// - For parallel cases, data only written from master
fileName outputDir = args.get<word>("name", "EnSight");
fileName outputDir = args.getOrDefault<word>("name", "EnSight");
if (!outputDir.isAbsolute())
{
outputDir = args.globalPath()/outputDir;

View File

@ -633,7 +633,8 @@ int main(int argc, char *argv[])
else
{
regionNames.resize(1);
regionNames.first() = args.get<word>("region", fvMesh::defaultRegion);
regionNames.first() =
args.getOrDefault<word>("region", fvMesh::defaultRegion);
}
@ -695,7 +696,7 @@ int main(int argc, char *argv[])
// Directory management
// Sub-directory for output
const word vtkDirName = args.get<word>("name", "VTK");
const word vtkDirName = args.getOrDefault<word>("name", "VTK");
const fileName outputDir(args.globalPath()/vtkDirName);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -93,10 +93,10 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const label maxOut = Foam::max(0, args.get<label>("max", 0));
const label span = Foam::max(1, args.get<label>("span", 1));
const label maxOut = Foam::max(0, args.getOrDefault<label>("max", 0));
const label span = Foam::max(1, args.getOrDefault<label>("span", 1));
const scalar relax = args.get<scalar>("scale", 1);
const scalar relax = args.getOrDefault<scalar>("scale", 1);
const bool slave = args.found("slave");
const bool removeLock = args.found("removeLock");

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -237,12 +237,12 @@ int main(int argc, char *argv[])
}
const int divisions = args.get<int>("divisions", 1);
const int divisions = args.getOrDefault<int>("divisions", 1);
Info<< "Using " << divisions << " per time interval" << nl << endl;
const word interpolationType =
args.get<word>("interpolationType", "linear");
args.getOrDefault<word>("interpolationType", "linear");
Info<< "Using interpolation " << interpolationType << nl << endl;

View File

@ -250,7 +250,7 @@ int main(int argc, char *argv[])
fileName baseDir
(
args.get<fileName>
args.getOrDefault<fileName>
(
"templateDir",
"${WM_PROJECT_DIR}/etc/caseDicts/createZeroDirectoryTemplates"

View File

@ -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.
@ -434,7 +434,8 @@ int main(int argc, char *argv[])
}
const bool enableEntries = args.found("enableFunctionEntries");
const word regionName = args.get<word>("region", polyMesh::defaultRegion);
const word regionName =
args.getOrDefault<word>("region", polyMesh::defaultRegion);
fileName regionPrefix;
if (regionName != polyMesh::defaultRegion)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -69,7 +69,7 @@ int readNumProcs
IOobject::NO_WRITE,
false // do not register
),
args.get<fileName>(optionName, "")
args.getOrDefault<fileName>(optionName, "")
)
)
);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -771,7 +771,7 @@ int main(int argc, char *argv[])
expressions::exprString
expression
(
args.opt("expression"),
args[expression],
dictionary::null
);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -90,7 +90,7 @@ int main(int argc, char *argv[])
const bool addPoint = args.found("points");
const bool mergeRegions = args.found("mergeRegions");
const scalar scaleFactor = args.get<scalar>("scale", -1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", -1);
if (addPoint)
{

View File

@ -1606,7 +1606,7 @@ int main(int argc, char *argv[])
// Scale factor for both surfaces:
const scalar scaleFactor = args.get<scalar>("scale", -1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", -1);
const word surf1Name(args[2]);
Info<< "Reading surface " << surf1Name << endl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -338,8 +338,9 @@ int main(int argc, char *argv[])
const fileName surfFileName = args[1];
const bool checkSelfIntersect = args.found("checkSelfIntersection");
const bool splitNonManifold = args.found("splitNonManifold");
const label outputThreshold = args.get<label>("outputThreshold", 10);
const word surfaceFormat = args.get<word>("writeSets", "");
const label outputThreshold =
args.getOrDefault<label>("outputThreshold", 10);
const word surfaceFormat = args.getOrDefault<word>("writeSets", "");
const bool writeSets = !surfaceFormat.empty();
autoPtr<surfaceWriter> surfWriter;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -96,7 +97,7 @@ int main(int argc, char *argv[])
triSurface surf
(
inFileName,
args.get<scalar>("scale", -1)
args.getOrDefault<scalar>("scale", -1)
);
surf.writeStats(Info);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -104,7 +105,7 @@ int main(int argc, char *argv[])
<< exit(FatalError);
}
const scalar scaleFactor = args.get<scalar>("scale", -1);
const scalar scaleFactor = args.getOrDefault<scalar>("scale", -1);
Info<< "Input surface :" << inFileName << nl
<< "Scaling factor :" << scaleFactor << nl

View File

@ -149,7 +149,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
{
const unsigned prec = args.lookupOrDefault<unsigned>("precision", 0u);
const unsigned prec = args.getOrDefault<unsigned>("precision", 0u);
if (prec)
{
Info<< "Output write precision set to " << prec << endl;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -63,9 +64,9 @@ int main(int argc, char *argv[])
const point samplePt
(
args.get<scalar>("x", 0),
args.get<scalar>("y", 0),
args.get<scalar>("z", 0)
args.getOrDefault<scalar>("x", 0),
args.getOrDefault<scalar>("y", 0),
args.getOrDefault<scalar>("z", 0)
);
Info<< "Looking for nearest face/vertex to " << samplePt << endl;

View File

@ -89,7 +89,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName surfFileName = args[1];
const scalar density = args.get<scalar>("density", 1);
const scalar density = args.getOrDefault<scalar>("density", 1);
vector refPt = Zero;
bool calcAroundRefPt = args.readIfPresent("referencePoint", refPt);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -612,8 +613,8 @@ int main(int argc, char *argv[])
const scalar distance(args.get<scalar>(2));
const scalar extendFactor(args.get<scalar>(3));
const bool checkSelfIntersect = args.found("checkSelfIntersection");
const label nSmooth = args.get<label>("nSmooth", 10);
const scalar featureAngle = args.get<scalar>("featureAngle", 180);
const label nSmooth = args.getOrDefault<label>("nSmooth", 10);
const scalar featureAngle = args.getOrDefault<scalar>("featureAngle", 180);
const bool debug = args.found("debug");

View File

@ -230,7 +230,7 @@ int main(int argc, char *argv[])
IOobject::NO_WRITE,
false
),
args.get<fileName>("dict", "")
args.getOrDefault<fileName>("dict", "")
);
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))

View File

@ -156,7 +156,7 @@ int main(int argc, char *argv[])
Time runTime(args.rootPath(), args.caseName());
const fileName exportName(args[1]);
const word importName(args.get<word>("name", "default"));
const word importName(args.getOrDefault<word>("name", "default"));
const word writeFileType
(
@ -191,7 +191,7 @@ int main(int argc, char *argv[])
IOobject::NO_WRITE,
false
),
args.get<fileName>("dict", "")
args.getOrDefault<fileName>("dict", "")
);
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))

View File

@ -168,7 +168,7 @@ int main(int argc, char *argv[])
const fileName importName(args[1]);
const word exportName(args.get<word>("name", "default"));
const word exportName(args.getOrDefault<word>("name", "default"));
const word readFileType
(
@ -203,7 +203,7 @@ int main(int argc, char *argv[])
IOobject::NO_WRITE,
false
),
args.get<fileName>("dict", "")
args.getOrDefault<fileName>("dict", "")
);
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -122,7 +122,7 @@ int main(int argc, char *argv[])
// use UnsortedMeshedSurface, not MeshedSurface to maintain ordering
UnsortedMeshedSurface<face> surf(importName);
const scalar scaling = args.get<scalar>("scale", -1);
const scalar scaling = args.getOrDefault<scalar>("scale", -1);
if (scaling > 0)
{
DetailInfo << " -scale " << scaling << nl;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -95,7 +96,7 @@ int main(int argc, char *argv[])
Info<< "outside" << endl;
}
const scalar scaling = args.get<scalar>("scale", -1);
const scalar scaling = args.getOrDefault<scalar>("scale", -1);
if (scaling > 0)
{
Info<< "Input scaling: " << scaling << nl;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -70,7 +71,7 @@ int main(int argc, char *argv[])
const scalar mergeTol = args.get<scalar>(2);
const fileName outFileName = args[3];
const scalar scaling = args.get<scalar>("scale", -1);
const scalar scaling = args.getOrDefault<scalar>("scale", -1);
Info<< "Reading surface from " << surfFileName << " ..." << nl
<< "Merging points within " << mergeTol << " metre." << nl;

View File

@ -177,7 +177,7 @@ int main(int argc, char *argv[])
IOobject::MUST_READ,
IOobject::NO_WRITE
),
args.get<fileName>("decomposeParDict", "")
args.getOrDefault<fileName>("decomposeParDict", "")
)
);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -213,7 +214,7 @@ int main(int argc, char *argv[])
<< " triangle ..." << endl;
}
const scalar searchTol = args.get<scalar>("tol", 1e-3);
const scalar searchTol = args.getOrDefault<scalar>("tol", 1e-3);
// Get search box. Anything not within this box will not be considered.
const boundBox& meshBb = mesh.bounds();

View File

@ -333,7 +333,7 @@ bool Foam::functionObjectList::readFunctionObject
}
// Insert the region name if specified
if (region != word::null)
if (!region.empty())
{
funcDict.set("region", region);
}
@ -403,7 +403,7 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
dictionary& functionsDict = controlDict.subDict("functions");
const word regionName = args.get<word>("region", "");
const word regionName = args.getOrDefault<word>("region", "");
bool modifiedControlDict = false;

View File

@ -288,6 +288,16 @@ void Foam::argList::checkITstream(const ITstream& is, const word& optName)
}
void Foam::argList::raiseBadInput(const word& optName) const
{
// Can use FatalError
// predicate checks are not used at the earliest stages
FatalErrorIn(executable())
<< "Option -" << optName << " with invalid input" << nl
<< exit(FatalError);
}
void Foam::argList::addArgument
(
const string& argName,

View File

@ -176,6 +176,9 @@ class argList
template<class T>
static inline void readList(ITstream& is, List<T>& list);
//- Trigger FatalError for given option
void raiseBadInput(const word& optName) const;
//- Set rootPath_, globalCase_, case_ from one of the following forms
// * [-case dir]
// * cwd
@ -392,9 +395,16 @@ public:
inline T get(const word& optName) const;
//- Get a value from the named option if present, or return default.
// Identical to getOrDefault().
template<class T>
inline T get(const word& optName, const T& deflt) const;
inline T getOrDefault(const word& optName, const T& deflt) const;
//- Get a List of values from the named option,
//- treating a single entry like a list of size 1.
// \param optName the option name to read from
// \param mandatory if the option is non-mandatory, the behaviour
// is similar to readListIfPresent().
template<class T>
inline List<T> getList(const word& optName, bool mandatory=true) const;
//- Read a value from the named option if present.
// \return true if the named option was found.
@ -412,38 +422,72 @@ public:
const T& deflt
) const;
//- Get a value from the named option if present, or return default.
template<class T>
inline T getOrDefault(const word& optName, const T& deflt) const;
//- Get a List of values from the named option,
//- treating a single entry like a list of size 1.
// \param optName the option name to read from
// \param mandatory if the option is non-mandatory, the behaviour
// is similar to readListIfPresent().
template<class T>
inline List<T> getList(const word& optName, bool mandatory=true) const;
//- If named option is present, get a List of values
//- treating a single entry like a list of size 1.
// \return true if the named option was found.
template<class T>
inline bool readListIfPresent(const word& optName, List<T>& list) const;
//- Read the named option and check its validity.
// FatalError if mandatory and not found, or if the predicate check
// failed.
//
// \param optName the option name
// \param val the value to read into
// \param pred the value check predicate
//
// \return true if the entry was found.
template<class T, class Predicate>
inline bool readCheck
(
const word& optName,
T& val,
const Predicate& pred,
bool mandatory = true
) const;
//- Alternative name for option get(const word& optName)
template<class T=string>
T opt(const word& optName) const
{
return this->get<T>(optName);
}
//- Read the named option if present and check its validity.
// FatalError if found and the predicate check failed.
//
// \param optName the option name
// \param val the value to read into
// \param pred the value check predicate
//
// \return true if the entry was found.
template<class T, class Predicate>
inline bool readCheckIfPresent
(
const word& optName,
T& val,
const Predicate& pred
) const;
//- Alternative name for option get(const word& optName, ...)
template<class T>
T opt(const word& optName, const T& deflt) const
{
return this->get<T>(optName, deflt);
}
//- Get a value from the named option with additional checking.
// FatalError if the predicate check failed.
//
// \param optName the option name
// \param pred the value check predicate
template<class T, class Predicate>
T getCheck
(
const word& optName,
const Predicate& pred
) const;
//- Get a value from the named option with additional checking
//- (if present), or return default.
// FatalError if the predicate check on the retrieved value failed.
//
// \param optName the option name
// \param deflt the default return value
// \param pred the value check predicate
template<class T, class Predicate>
T getCheckOrDefault
(
const word& optName,
const T& deflt,
const Predicate& pred
) const;
// Edit
@ -612,11 +656,36 @@ public:
// Housekeeping
//- Get a value from the named option if present, or return default.
//- Deprecated(2020-05) identical to get(const word& optName)
// \deprecated(2020-05) - use get() method
template<class T=string>
T opt(const word& optName) const
{
return this->get<T>(optName);
}
//- Deprecated(2020-05) identical to getOrDefault(...)
// \deprecated(2020-05) - use getOrDefault() method
template<class T>
T opt(const word& optName, const T& deflt) const
{
return this->getOrDefault<T>(optName, deflt);
}
//- Deprecated(2020-05) identical to getOrDefault(...)
// \deprecated(2020-05) - use getOrDefault() method
template<class T>
T get(const word& optName, const T& deflt) const
{
return this->getOrDefault<T>(optName, deflt);
}
//- Deprecated(2020-05) identical to getOrDefault(...)
// \deprecated(2020-05) - use getOrDefault() method
template<class T>
T lookupOrDefault(const word& optName, const T& deflt) const
{
return getOrDefault<T>(optName, deflt);
return this->getOrDefault<T>(optName, deflt);
}

View File

@ -282,7 +282,11 @@ inline T Foam::argList::get(const word& optName) const
template<class T>
inline T Foam::argList::get(const word& optName, const T& deflt) const
inline T Foam::argList::getOrDefault
(
const word& optName,
const T& deflt
) const
{
if (found(optName))
{
@ -328,22 +332,6 @@ inline bool Foam::argList::readIfPresent
}
template<class T>
inline T Foam::argList::getOrDefault
(
const word& optName,
const T& deflt
) const
{
if (found(optName))
{
return get<T>(optName);
}
return deflt;
}
template<class T>
inline Foam::List<T> Foam::argList::getList(const label index) const
{
@ -402,6 +390,80 @@ inline bool Foam::argList::readListIfPresent
}
template<class T, class Predicate>
inline bool Foam::argList::readCheck
(
const word& optName,
T& val,
const Predicate& pred,
bool mandatory
) const
{
if (readIfPresent<T>(optName, val))
{
if (!pred(val))
{
raiseBadInput(optName);
}
return true;
}
else if (mandatory)
{
FatalError(executable())
<< "Option -" << optName << " not specified" << nl
<< exit(FatalError);
}
return false;
}
template<class T, class Predicate>
inline bool Foam::argList::readCheckIfPresent
(
const word& optName,
T& val,
const Predicate& pred
) const
{
return readCheck<T>(optName, val, pred, false);
}
template<class T, class Predicate>
inline T Foam::argList::getCheck
(
const word& optName,
const Predicate& pred
) const
{
T val;
readCheck<T>(optName, val, pred, true);
return val;
}
template<class T, class Predicate>
inline T Foam::argList::getCheckOrDefault
(
const word& optName,
const T& deflt,
const Predicate& pred
) const
{
// Could predicate check default as well (for FULLDEBUG)
T val;
if (readCheck<T>(optName, val, pred, false))
{
return val;
}
return deflt;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline const Foam::string& Foam::argList::operator[](const label index) const

View File

@ -8,5 +8,5 @@ IOobject dictIO = IOobject::selectIO
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
),
args.get<fileName>("dict", "")
args.getOrDefault<fileName>("dict", "")
);

View File

@ -8,5 +8,5 @@ IOobject dictIO = IOobject::selectIO
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
),
args.get<fileName>("dict", "")
args.getOrDefault<fileName>("dict", "")
);

View File

@ -8,5 +8,5 @@ IOobject dictIO = IOobject::selectIO
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
),
args.get<fileName>("dict", "")
args.getOrDefault<fileName>("dict", "")
);

View File

@ -8,5 +8,5 @@ IOobject dictIO = IOobject::selectIO
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
),
args.get<fileName>("dict", "")
args.getOrDefault<fileName>("dict", "")
);