Commit 345a2a42 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: simplify method names for reading argList options and arguments

- use succincter method names that more closely resemble dictionary
  and HashTable method names. This improves method name consistency
  between classes and also requires less typing effort:

    args.found(optName)        vs.  args.optionFound(optName)
    args.readIfPresent(..)     vs.  args.optionReadIfPresent(..)
    ...
    args.opt<scalar>(optName)  vs.  args.optionRead<scalar>(optName)
    args.read<scalar>(index)   vs.  args.argRead<scalar>(index)

- the older method names forms have been retained for code compatibility,
  but are now deprecated
parent 2feb11db
......@@ -28,7 +28,7 @@ surfaceScalarField phi
fvc::flux(U)
);
if (args.optionFound("initialiseUBCs"))
if (args.found("initialiseUBCs"))
{
U.correctBoundaryConditions();
phi = fvc::flux(U);
......@@ -41,7 +41,7 @@ if (args.optionFound("initialiseUBCs"))
word pName("p");
// Update name of the pressure field from the command-line option
args.optionReadIfPresent("pName", pName);
args.readIfPresent("pName", pName);
// Infer the pressure BCs from the velocity
wordList pBCTypes
......
......@@ -28,7 +28,7 @@ surfaceScalarField phi
fvc::flux(U)
);
if (args.optionFound("initialiseUBCs"))
if (args.found("initialiseUBCs"))
{
U.correctBoundaryConditions();
phi = fvc::flux(U);
......@@ -41,7 +41,7 @@ if (args.optionFound("initialiseUBCs"))
word pName("p");
// Update name of the pressure field from the command-line option
args.optionReadIfPresent("pName", pName);
args.readIfPresent("pName", pName);
// Infer the pressure BCs from the velocity
wordList pBCTypes
......
......@@ -193,13 +193,13 @@ int main(int argc, char *argv[])
phi.write();
// Optionally write Phi
if (args.optionFound("writePhi"))
if (args.found("writePhi"))
{
Phi.write();
}
// Calculate the pressure field from the Euler equation
if (args.optionFound("writep"))
if (args.found("writep"))
{
Info<< nl << "Calculating approximate pressure field" << endl;
......
......@@ -181,13 +181,13 @@ int main(int argc, char *argv[])
phi.write();
// Optionally write Phi
if (args.optionFound("writePhi"))
if (args.found("writePhi"))
{
Phi.write();
}
// Calculate the pressure field from the Euler equation
if (args.optionFound("writep"))
if (args.found("writep"))
{
Info<< nl << "Calculating approximate pressure field" << endl;
......
......@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
psi.write();
if (!args.optionFound("noH") || args.optionFound("HdotGradH"))
if (!args.found("noH") || args.found("HdotGradH"))
{
volVectorField H
(
......@@ -99,7 +99,7 @@ int main(int argc, char *argv[])
fvc::reconstruct(fvc::snGrad(psi)*mesh.magSf())
);
if (!args.optionFound("noH"))
if (!args.found("noH"))
{
Info<< nl
<< "Creating field H for time "
......@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
H.write();
}
if (args.optionFound("HdotGradH"))
if (args.found("HdotGradH"))
{
Info<< nl
<< "Creating field HdotGradH for time "
......@@ -129,7 +129,7 @@ int main(int argc, char *argv[])
}
}
if (!args.optionFound("noB"))
if (!args.found("noB"))
{
Info<< nl
<< "Creating field B for time "
......
......@@ -123,7 +123,7 @@ volScalarField alphac
);
word kinematicCloudName("kinematicCloud");
args.optionReadIfPresent("cloud", kinematicCloudName);
args.readIfPresent("cloud", kinematicCloudName);
Info<< "Constructing kinematicCloud " << kinematicCloudName << endl;
basicKinematicTypeCloud kinematicCloud
......
......@@ -58,7 +58,7 @@ volScalarField mu
);
word kinematicCloudName("kinematicCloud");
args.optionReadIfPresent("cloud", kinematicCloudName);
args.readIfPresent("cloud", kinematicCloudName);
Info<< "Constructing kinematicCloud " << kinematicCloudName << endl;
basicKinematicCollidingCloud kinematicCloud
......
......@@ -51,7 +51,7 @@ autoPtr<compressible::turbulenceModel> turbulence
const word kinematicCloudName
(
args.optionLookupOrDefault<word>("cloud", "kinematicCloud")
args.lookupOrDefault<word>("cloud", "kinematicCloud")
);
Info<< "Constructing kinematicCloud " << kinematicCloudName << endl;
......
......@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
Info<< nl << "Specify an option! " << nl << endl;
}
if (args.optionFound("label"))
if (args.found("label"))
{
FixedList<label, 100000> list1(1);
FixedList<label, 100000> list2(0);
......@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
runSwapTest(1000001, list1, list2);
}
if (args.optionFound("float"))
if (args.found("float"))
{
FixedList<double, 100000> list1(1.0);
FixedList<double, 100000> list2(0.0);
......@@ -112,7 +112,7 @@ int main(int argc, char *argv[])
runSwapTest(1000001, list1, list2);
}
if (args.optionFound("vector"))
if (args.found("vector"))
{
FixedList<vector, 100000> list1(vector::one);
FixedList<vector, 100000> list2(vector::zero);
......@@ -120,7 +120,7 @@ int main(int argc, char *argv[])
runSwapTest(100001, list1, list2);
}
if (args.optionFound("labelList"))
if (args.found("labelList"))
{
typedef labelList testType;
testType initVal(500);
......@@ -134,7 +134,7 @@ int main(int argc, char *argv[])
runSwapTest(100001, list1, list2);
}
if (args.optionFound("vectorList"))
if (args.found("vectorList"))
{
typedef vectorList testType;
testType initVal(500);
......@@ -148,7 +148,7 @@ int main(int argc, char *argv[])
runSwapTest(100001, list1, list2);
}
if (args.optionFound("fixedLabel"))
if (args.found("fixedLabel"))
{
typedef FixedList<label,1000> testType;
......@@ -163,7 +163,7 @@ int main(int argc, char *argv[])
runSwapTest(100001, list1, list2);
}
if (args.optionFound("fixedLabelList"))
if (args.found("fixedLabelList"))
{
typedef labelList testType;
typedef FixedList<testType,10> containerType;
......
......@@ -53,8 +53,8 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
bool writeObj = args.optionFound("writeObj");
bool normalise = args.optionFound("normalise");
bool writeObj = args.found("writeObj");
bool normalise = args.found("normalise");
#include "createMesh.H"
......
......@@ -151,9 +151,9 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const bool optStd = args.optionFound("std");
const bool optSet = args.optionFound("set");
const bool optFnd = args.optionFound("find");
const bool optStd = args.found("std");
const bool optSet = args.found("set");
const bool optFnd = args.found("find");
cpuTime timer;
......
......@@ -49,9 +49,9 @@ int main(int argc, char *argv[])
#include "createTime.H"
wordReList matcher;
if (args.optionFound("re"))
if (args.found("re"))
{
matcher = args.optionReadList<wordRe>("re");
matcher = args.readList<wordRe>("re");
Info<<"limit names: " << matcher << nl;
}
......
......@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
printInfo(idl3);
fileName binaryOutput;
if (args.optionReadIfPresent("binary", binaryOutput))
if (args.readIfPresent("binary", binaryOutput))
{
Info<<"Writing output to " << binaryOutput << endl;
......
......@@ -331,29 +331,29 @@ int main(int argc, char *argv[])
scalar xxx(-1);
if (args.optionFound("flag"))
if (args.found("flag"))
{
Info<<"-flag:" << args["flag"] << endl;
}
if (args.optionReadIfPresent<scalar>("float", xxx))
if (args.readIfPresent<scalar>("float", xxx))
{
Info<<"read float " << xxx << endl;
}
if (args.optionFound("reList"))
if (args.found("reList"))
{
reLst = args.optionReadList<wordRe>("reList");
reLst = args.readList<wordRe>("reList");
}
if (args.optionFound("wordList"))
if (args.found("wordList"))
{
wLst = args.optionReadList<word>("wordList");
wLst = args.readList<word>("wordList");
}
if (args.optionFound("stringList"))
if (args.found("stringList"))
{
sLst = args.optionReadList<string>("stringList");
sLst = args.readList<string>("stringList");
}
Info<< nl
......
......@@ -212,28 +212,28 @@ int main(int argc, char *argv[])
std::initializer_list<label> increments
= {10000, 20000, 40000, 80000, 160000};
if (args.optionFound("label"))
if (args.found("label"))
{
List<label> list(10, 1);
runResizeTest(100000, list, increments);
}
if (args.optionFound("float"))
if (args.found("float"))
{
List<double> list(10, 1.0);
runResizeTest(10000, list, increments);
}
if (args.optionFound("vector"))
if (args.found("vector"))
{
List<vector> list(10, vector::one);
runResizeTest(10000, list, increments);
}
if (args.optionFound("labelList"))
if (args.found("labelList"))
{
typedef labelList testType;
testType initVal(500, label(1));
......@@ -243,7 +243,7 @@ int main(int argc, char *argv[])
runResizeTest(200, list, increments);
}
if (args.optionFound("vectorList"))
if (args.found("vectorList"))
{
typedef vectorList testType;
testType initVal(500, vector::one);
......@@ -253,7 +253,7 @@ int main(int argc, char *argv[])
runResizeTest(100, list, increments);
}
if (args.optionFound("order"))
if (args.found("order"))
{
List<label> list(100000000, 1);
......
......@@ -95,7 +95,7 @@ int main(int argc, char *argv[])
argList args(argc, argv, false, true);
if (args.optionFound("mask"))
if (args.found("mask"))
{
Info<< "bit width: " << unsigned(sizeof(unsigned)*CHAR_BIT) << endl;
reportInfo<1>();
......@@ -135,7 +135,7 @@ int main(int argc, char *argv[])
Info<< "size: " << packLst.size() << nl;
if (args.optionFound("count"))
if (args.found("count"))
{
unsigned int rawCount = 0;
forAll(rawLst, elemI)
......@@ -149,7 +149,7 @@ int main(int argc, char *argv[])
<< "packed count: " << packLst.count() << nl;
}
if (args.optionFound("info"))
if (args.found("info"))
{
packLst.printInfo(Info);
}
......
......@@ -27,6 +27,7 @@ Description
#include "argList.H"
#include "IOstreams.H"
#include "Switch.H"
#include "StringStream.H"
using namespace Foam;
......@@ -40,9 +41,9 @@ int main(int argc, char *argv[])
argList::noParallel();
// argList::noFunctionObjects();
argList::removeOption("case");
argList::addOption("label", "value", "Test parsing of label");
argList::addOption("label", "value", "Test parsing of label");
argList::addOption("scalar", "value", "Test parsing of scalar");
argList::addOption("string", "value", "Test string lookup");
// These are actually lies (never had -parseLabel, -parseScalar etc),
// but good for testing...
......@@ -56,10 +57,15 @@ int main(int argc, char *argv[])
// Fake a future option...
argList::addOptionCompat("label", {"parse-label", 2112});
argList args(argc, argv);
argList::addArgument("label");
argList::addArgument("...");
argList::addArgument("label");
argList::nonMandatoryArgs();
argList args(argc, argv, false, true);
Info<<"have: "
<<args.optionCount({"label", "scalar"}) << " options" << nl;
<<args.count({"label", "scalar"}) << " options" << nl;
label ival;
scalar sval;
......@@ -67,23 +73,59 @@ int main(int argc, char *argv[])
Info<< nl;
Info<< "-label = " << flush;
if (args.optionReadIfPresent("label", ival))
if (args.readIfPresent("label", ival))
{
Info<< ival << endl;
Info<< ival << nl;
}
else
{
Info<< "not specified" << endl;
Info<< "not specified" << nl;
}
Info<< "-scalar = " << flush;
if (args.optionReadIfPresent("scalar", sval))
if (args.readIfPresent("scalar", sval))
{
Info<< sval << endl;
Info<< sval << nl;
}
else
{
Info<< "not specified" << endl;
Info<< "not specified" << nl;
}
// Using direct reading
Info<< nl;
if (args.found("label"))
{
Info<< "-label = " << args.opt<label>("label")
<< " or " << args.optionRead<label>("label") // old-compat
<< " or " << readLabel(args["label"]) // with function
<< nl;
}
if (args.found("scalar"))
{
Info<< "-scalar = " << args.opt<scalar>("scalar")
<< " or " << args.optionRead<scalar>("scalar") // old-compat
<< " or " << readScalar(args["scalar"]) // with function
<< nl;
}
if (args.found("string"))
{
Info<< "-string = " << args.opt("string")
<< " or " << args.optionRead<scalar>("string") // old-compat
<< nl;
}
// Arg reading
Info<< nl;
for (label argi=1; argi < args.size(); ++argi)
{
Info<< "arg[" << argi << "] = " << args.read<string>(argi)
<< " or " << args.argRead<label>(argi) // old-compat
<< nl;
}
Info<< "\nEnd\n" << endl;
......
......@@ -74,9 +74,9 @@ int main(int argc, char *argv[])
const fileName decompFile = args[1];
const bool region = args.optionFound("region");
const bool allRegions = args.optionFound("allRegions");
const bool verbose = args.optionFound("verbose");
const bool region = args.found("region");
const bool allRegions = args.found("allRegions");
const bool verbose = args.found("verbose");
// Set time from database
#include "createTime.H"
......@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
// Allow override of decomposeParDict location
fileName decompDictFile;
args.optionReadIfPresent("decomposeParDict", decompDictFile);
args.readIfPresent("decomposeParDict", decompDictFile);
wordList regionNames;
wordList regionDirs;
......@@ -109,7 +109,7 @@ int main(int argc, char *argv[])
else
{
word regionName;
if (args.optionReadIfPresent("region", regionName))
if (args.readIfPresent("region", regionName))
{
regionNames = wordList(1, regionName);
regionDirs = regionNames;
......
......@@ -105,15 +105,15 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const bool region = args.optionFound("region");
const bool allRegions = args.optionFound("allRegions");
const bool verbose = args.optionFound("verbose");
const bool region = args.found("region");
const bool allRegions = args.found("allRegions");
const bool verbose = args.found("verbose");
const label numSubdomains =
args.optionLookupOrDefault<label>("domains", 0);
args.lookupOrDefault<label>("domains", 0);
const word methodName =
args.optionLookupOrDefault<word>("method", word::null);
args.lookupOrDefault<word>("method", word::null);
// Set time from database
......@@ -123,7 +123,7 @@ int main(int argc, char *argv[])
// Allow override of decomposeParDict location
fileName decompDictFile;
args.optionReadIfPresent("decomposeParDict", decompDictFile);
args.readIfPresent("decomposeParDict", decompDictFile);
wordList regionNames;
wordList regionDirs;
......@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
else
{
word regionName;
if (args.optionReadIfPresent("region", regionName))
if (args.readIfPresent("region", regionName))
{
regionNames = wordList(1, regionName);
regionDirs = regionNames;
......
......@@ -54,8 +54,8 @@ int main(int argc, char *argv[])
argList::addArgument("dict .. dictN");
argList args(argc, argv, false, true);
const bool optInfo = args.optionFound("info");
const bool optValue = args.optionFound("value");
const bool optInfo = args.found("info");
const bool optValue = args.found("value");
for (label argi=1; argi < args.size(); ++argi)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment