ENH: change argList get<> and getList<> from read<>, readList<>

- more consistent with dictionary method naming. The get<> or
  getList<> returns a value, doesn't read into a existing location.
This commit is contained in:
Mark Olesen
2018-08-09 11:27:36 +02:00
parent b5162f91fc
commit ae36f5f504
47 changed files with 101 additions and 99 deletions

View File

@ -51,7 +51,7 @@ int main(int argc, char *argv[])
labelList patchIDs
(
pbm.patchSet(args.readList<wordRe>(1)).sortedToc()
pbm.patchSet(args.getList<wordRe>(1)).sortedToc()
);
Info<< "Starting walk from patches "

View File

@ -108,7 +108,9 @@ int main(int argc, char *argv[])
if (args.found("label"))
{
Info<< "-label = " << args.opt<label>("label")
#ifdef Foam_argList_1712
<< " or " << args.optionRead<label>("label") // old-compat
#endif
<< " or " << readLabel(args["label"]) // with function
<< nl;
}
@ -116,7 +118,9 @@ int main(int argc, char *argv[])
if (args.found("scalar"))
{
Info<< "-scalar = " << args.opt<scalar>("scalar")
#ifdef Foam_argList_1712
<< " or " << args.optionRead<scalar>("scalar") // old-compat
#endif
<< " or " << readScalar(args["scalar"]) // with function
<< nl;
}
@ -124,7 +128,9 @@ int main(int argc, char *argv[])
if (args.found("string"))
{
Info<< "-string = " << args.opt("string")
#ifdef Foam_argList_1712
<< " or " << args.optionRead<scalar>("string") // old-compat
#endif
<< nl;
}
@ -133,8 +139,11 @@ int main(int argc, char *argv[])
Info<< nl;
for (label argi=1; argi < args.size(); ++argi)
{
Info<< "arg[" << argi << "] = " << args.read<string>(argi)
Info<< "arg[" << argi << "] = " << args.get<string>(argi)
#ifdef Foam_argList_1712
<< " or " << args.read<label>(argi) // old-compat
<< " or " << args.argRead<label>(argi) // old-compat
#endif
<< nl;
}

View File

@ -109,12 +109,8 @@ int main(int argc, char *argv[])
const bool allRegions = args.found("allRegions");
const bool verbose = args.found("verbose");
const label numSubdomains =
args.lookupOrDefault<label>("domains", 0);
const word methodName =
args.lookupOrDefault<word>("method", word::null);
const label numSubdomains = args.lookupOrDefault<label>("domains", 0);
const word methodName = args.lookupOrDefault<word>("method", word::null);
// Set time from database
#include "createTime.H"

View File

@ -46,7 +46,7 @@ int main(int argc, char *argv[])
label nReps = 10000;
const point sample = args.read<point>(1);
const point sample = args.get<point>(1);
const polyMesh::cellDecomposition decompMode = polyMesh::CELL_TETS;

View File

@ -101,8 +101,8 @@ int main(int argc, char *argv[])
}
{
label start = args.read<label>(argI);
label size = args.read<label>(argI+1);
label start = args.get<label>(argI);
label size = args.get<label>(argI+1);
++argI;
range.reset(start, size);

View File

@ -196,7 +196,7 @@ int main(int argc, char *argv[])
}
{
const label celli = args.lookupOrDefault("cell", 0);
const label celli = args.lookupOrDefault<label>("cell", 0);
tensorField mI(momentOfInertia::meshInertia(mesh));

View File

@ -65,7 +65,7 @@ int main(int argc, char *argv[])
bool useBSpline = args.found("B");
bool useCatmullRom = args.found("CMR");
label nSeg = args.lookupOrDefault<label>("n", 20);
const label nSeg = args.lookupOrDefault<label>("n", 20);
if (!useCatmullRom && !useBSpline)
{

View File

@ -138,7 +138,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const bool optStdout = args.found("stdout");
const scalar scaleFactor = args.lookupOrDefault("scale", 0.0);
const scalar scaleFactor = args.lookupOrDefault<scalar>("scale", 0);
const fileName importName = args[1];
const fileName exportName = optStdout ? "-stdout" : args[2];

View File

@ -366,13 +366,15 @@ int main(int argc, char *argv[])
const word oldInstance = mesh.pointsInstance();
const scalar featureAngle = args.read<scalar>(1);
const scalar featureAngle = args.get<scalar>(1);
const scalar minCos = Foam::cos(degToRad(featureAngle));
// Sin of angle between two consecutive edges on a face.
// If sin(angle) larger than this the face will be considered concave.
scalar concaveAngle = args.lookupOrDefault("concaveAngle", 30.0);
scalar concaveSin = Foam::sin(degToRad(concaveAngle));
const scalar concaveAngle =
args.lookupOrDefault<scalar>("concaveAngle", 30);
const scalar concaveSin = Foam::sin(degToRad(concaveAngle));
const bool overwrite = args.found("overwrite");
const bool meshQuality = args.found("meshQuality");

View File

@ -81,8 +81,8 @@ int main(int argc, char *argv[])
const word oldInstance = mesh.pointsInstance();
// Find set of patches from the list of regular expressions provided
const wordRes patches(args.readList<wordRe>(1));
const scalar weight = args.read<scalar>(2);
const wordRes patches(args.getList<wordRe>(1));
const scalar weight = args.get<scalar>(2);
const bool overwrite = args.found("overwrite");
const labelHashSet patchSet(mesh.boundaryMesh().patchSet(patches));

View File

@ -556,7 +556,7 @@ int main(int argc, char *argv[])
const word oldInstance = mesh.pointsInstance();
const scalar featureAngle = args.read<scalar>(1);
const scalar featureAngle = args.get<scalar>(1);
const scalar minCos = Foam::cos(degToRad(featureAngle));
const scalar minSin = Foam::sin(degToRad(featureAngle));
@ -564,7 +564,7 @@ int main(int argc, char *argv[])
const bool geometry = args.found("geometry");
const bool overwrite = args.found("overwrite");
const scalar edgeTol = args.lookupOrDefault("tol", 0.2);
const scalar edgeTol = args.lookupOrDefault<scalar>("tol", 0.2);
Info<< "Trying to split cells with internal angles > feature angle\n" << nl
<< "featureAngle : " << featureAngle << nl

View File

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

View File

@ -186,7 +186,7 @@ int main(int argc, char *argv[])
}
// By default, no scaling
const scalar scaleFactor = args.lookupOrDefault("scale", 1.0);
const scalar scaleFactor = args.lookupOrDefault<scalar>("scale", 1);
// Default to binary output, unless otherwise specified
const IOstream::streamFormat format =

View File

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

View File

@ -103,7 +103,7 @@ int main(int argc, char *argv[])
(
args[1],
// Default no scaling
args.lookupOrDefault("scale", 1.0)
args.lookupOrDefault<scalar>("scale", 1)
);

View File

@ -897,7 +897,7 @@ int main(int argc, char *argv[])
FatalError.exit();
}
const scalar scaleFactor = args.lookupOrDefault("scale", 1.0);
const scalar scaleFactor = args.lookupOrDefault<scalar>("scale", 1);
const bool writeSets = args.found("writeSets");
const bool writeZones = args.found("writeZones");

View File

@ -96,7 +96,7 @@ int main(int argc, char *argv[])
}
// Default rescale from [m] to [mm]
const scalar scaleFactor = args.lookupOrDefault("scale", 1000.0);
const scalar scaleFactor = args.lookupOrDefault<scalar>("scale", 1000);
const bool writeBndFile = !args.found("noBnd");
#include "createPolyMesh.H"

View File

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

View File

@ -90,7 +90,7 @@ int main(int argc, char *argv[])
FatalError.exit();
}
const scalar scaleFactor = args.lookupOrDefault("scale", 1.0);
const scalar scaleFactor = args.lookupOrDefault<scalar>("scale", 1);
const bool readBlank = !args.found("noBlank");
const bool singleBlock = args.found("singleBlock");

View File

@ -113,7 +113,7 @@ int main(int argc, char *argv[])
prefix,
runTime,
// Default rescale from [mm] to [m]
args.lookupOrDefault("scale", 0.001),
args.lookupOrDefault<scalar>("scale", 0.001),
args.found("solids")
);

View File

@ -61,7 +61,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
const labelVector n(args.read<labelVector>(1));
const labelVector n(args.get<labelVector>(1));
const fileName exportName = args[2];
Info<< "Reading surfaces as specified in the foamyHexMeshDict and"

View File

@ -1667,7 +1667,7 @@ int main(int argc, char *argv[])
{
includePatches = bMesh.patchSet
(
args.readList<wordRe>("patches")
args.getList<wordRe>("patches")
);
}
else

View File

@ -91,7 +91,7 @@ int main(int argc, char *argv[])
<< " s\n" << endl << endl;
const scalar featureAngle = args.read<scalar>(1);
const scalar featureAngle = args.get<scalar>(1);
const bool overwrite = args.found("overwrite");
const scalar minCos = Foam::cos(degToRad(featureAngle));

View File

@ -48,7 +48,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const scalar scaleFactor = args.read<scalar>(1);
const scalar scaleFactor = args.get<scalar>(1);
#include "createTime.H"
#include "createNamedMesh.H"

View File

@ -58,7 +58,7 @@ int main(int argc, char *argv[])
#include "createNamedPolyMesh.H"
const word zoneName = args[1];
const point outsidePoint = args.read<point>(2);
const point outsidePoint = args.get<point>(2);
Info<< "Orienting faceZone " << zoneName
<< " such that " << outsidePoint << " is outside"

View File

@ -401,7 +401,7 @@ int main(int argc, char *argv[])
}
}
const scalar featureAngle = args.read<scalar>(1);
const scalar featureAngle = args.get<scalar>(1);
const scalar minCos = Foam::cos(degToRad(featureAngle));
Info<< "Feature:" << featureAngle << endl

View File

@ -83,11 +83,8 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
vector n1(args.read<vector>(1));
n1 /= mag(n1);
vector n2(args.read<vector>(2));
n2 /= mag(n2);
const vector n1(args.get<vector>(1).normalise());
const vector n2(args.get<vector>(2).normalise());
const tensor rotT(rotationTensor(n1, n2));

View File

@ -391,7 +391,6 @@ int main(int argc, char *argv[])
meshInstance = fieldsInstance;
}
Info<< "Reading cell set from " << selectionName << nl << endl;
@ -400,12 +399,12 @@ int main(int argc, char *argv[])
if (args.found("patches"))
{
const wordRes patchNames(args.readList<wordRe>("patches"));
const wordRes patchNames(args.getList<wordRe>("patches"));
exposedPatchIDs = mesh.boundaryMesh().patchSet(patchNames).sortedToc();
Info<< "Adding exposed internal faces to nearest of patches "
<< patchNames << nl << endl;
<< flatOutput(patchNames) << nl << endl;
if (exposedPatchIDs.empty())
{
@ -414,7 +413,6 @@ int main(int argc, char *argv[])
<< mesh.boundaryMesh().names()
<< exit(FatalError);
}
}
else if (args.found("patch"))
{

View File

@ -363,7 +363,7 @@ int main(int argc, char *argv[])
List<scalar> scaling;
if (args.readListIfPresent("scale", scaling))
{
// readList handles single or multiple values
// readListIfPresent handles single or multiple values
if (scaling.size() == 1)
{

View File

@ -237,11 +237,11 @@ int main(int argc, char *argv[])
if (args.found("patches"))
{
writeOpts.patchSelection(args.readList<wordRe>("patches"));
writeOpts.patchSelection(args.getList<wordRe>("patches"));
}
if (args.found("faceZones"))
{
writeOpts.faceZoneSelection(args.readList<wordRe>("faceZones"));
writeOpts.faceZoneSelection(args.getList<wordRe>("faceZones"));
}
//

View File

@ -90,11 +90,8 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const label maxOut =
Foam::max(0, args.lookupOrDefault<label>("max", 0));
const label span =
Foam::max(1, args.lookupOrDefault<label>("span", 1));
const label maxOut = Foam::max(0, args.lookupOrDefault<label>("max", 0));
const label span = Foam::max(1, args.lookupOrDefault<label>("span", 1));
const scalar relax = args.lookupOrDefault<scalar>("scale", 1);

View File

@ -86,7 +86,7 @@ int main(int argc, char *argv[])
args.readIfPresent("regions", regionNames);
}
const wordRe patchGroup(args.read<wordRe>(1));
const wordRe patchGroup(args.get<wordRe>(1));
fileName commsDir(runTime.path()/"comms");
args.readIfPresent("commsDir", commsDir);

View File

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

View File

@ -71,8 +71,8 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName inFileName = args[1];
const scalar minLen = args.read<scalar>(2);
const scalar minQuality = args.read<scalar>(3);
const scalar minLen = args.get<scalar>(2);
const scalar minQuality = args.get<scalar>(3);
const fileName outFileName = args[4];
Info<< "Reading surface " << inFileName << nl

View File

@ -85,7 +85,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName inFileName = args[1];
const scalar reduction = args.read<scalar>(2);
const scalar reduction = args.get<scalar>(2);
const fileName outFileName = args[3];
if (reduction <= 0 || reduction > 1)

View File

@ -289,7 +289,7 @@ int main(int argc, char *argv[])
const IOdictionary dict(dictIO);
const scalar dist(args.read<scalar>(1));
const scalar dist(args.get<scalar>(1));
const scalar matchTolerance(max(1e-6*dist, SMALL));
const label maxIters = 100;

View File

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

View File

@ -607,8 +607,8 @@ int main(int argc, char *argv[])
#include "createTime.H"
const word inputName(args[1]);
const scalar distance(args.read<scalar>(2));
const scalar extendFactor(args.read<scalar>(3));
const scalar distance(args.get<scalar>(2));
const scalar extendFactor(args.get<scalar>(3));
const bool checkSelfIntersect = args.found("checkSelfIntersection");
const label nSmooth = args.lookupOrDefault("nSmooth", 10);
const scalar featureAngle = args.lookupOrDefault<scalar>

View File

@ -146,9 +146,9 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName surfFileName = args[1];
const scalar lambda = args.read<scalar>(2);
const scalar mu = args.read<scalar>(3);
const label iters = args.read<label>(4);
const scalar lambda = args.get<scalar>(2);
const scalar mu = args.get<scalar>(3);
const label iters = args.get<label>(4);
const fileName outFileName = args[5];
if (lambda < 0 || lambda > 1)

View File

@ -173,10 +173,7 @@ int main(int argc, char *argv[])
if (args.found("patches"))
{
includePatches = bMesh.patchSet
(
args.readList<wordRe>("patches")
);
includePatches = bMesh.patchSet(args.getList<wordRe>("patches"));
}
else
{
@ -197,7 +194,7 @@ int main(int argc, char *argv[])
if (args.found("faceZones"))
{
wordReList zoneNames(args.readList<wordRe>("faceZones"));
wordReList zoneNames(args.getList<wordRe>("faceZones"));
const wordList allZoneNames(fzm.names());
for (const wordRe& zoneName : zoneNames)
{

View File

@ -73,7 +73,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName surfFileName = args[1];
const point visiblePoint = args.read<point>(2);
const point visiblePoint = args.get<point>(2);
const fileName outFileName = args[3];
const bool orientInside = args.found("inside");

View File

@ -65,7 +65,7 @@ int main(int argc, char *argv[])
argList args(argc, argv);
const fileName surfFileName = args[1];
const scalar mergeTol = args.read<scalar>(2);
const scalar mergeTol = args.get<scalar>(2);
const fileName outFileName = args[3];
const scalar scaling = args.lookupOrDefault<scalar>("scale", -1);

View File

@ -238,7 +238,7 @@ int main(int argc, char *argv[])
List<scalar> scaling;
if (args.readListIfPresent("scale", scaling))
{
// readList handles single or multiple values
// readListIfPresent handles single or multiple values
if (scaling.size() == 1)
{

View File

@ -435,7 +435,7 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
{
modifiedControlDict = true;
wordList funcNames = args.readList<word>("funcs");
wordList funcNames = args.getList<word>("funcs");
for (const word& funcName : funcNames)
{

View File

@ -1117,12 +1117,10 @@ void Foam::argList::parse
// If running distributed (different roots for different procs)
label dictNProcs = -1;
if (options_.found("roots"))
if (this->readListIfPresent("roots", roots))
{
distributed_ = true;
source = "-roots";
roots = this->readList<fileName>("roots");
if (roots.size() != 1)
{
dictNProcs = roots.size()+1;

View File

@ -317,15 +317,15 @@ public:
//- Return non-const access to the command options
inline HashTable<string>& options();
//- Read a value from the argument at index.
// Index 1 is the first non-option argument.
//- Get a value from the argument at index.
// Index 1 is the first (non-option) argument.
template<class T>
inline T read(const label index) const;
inline T get(const label index) const;
//- Read a value from the argument at index.
// Index 1 is the first non-option argument.
// Index 1 is the first (non-option) argument.
template<class T>
inline List<T> readList(const label index) const;
inline List<T> getList(const label index) const;
//- Return true if the named option is found
inline bool found(const word& optName) const;
@ -372,7 +372,7 @@ public:
//- Read a List of values from the named option,
//- treating a single entry like a list of size 1.
template<class T>
inline List<T> readList(const word& optName) const;
inline List<T> getList(const word& optName) const;
//- If named option is present, read a List of values
//- treating a single entry like a list of size 1.
@ -516,7 +516,7 @@ public:
//- The string corresponding to the argument index.
// Index 0 is the executable.
// Index 1 is the first non-option argument.
// Index 1 is the first (non-option) argument.
inline const string& operator[](const label index) const;
//- The string associated with the named option
@ -528,12 +528,21 @@ public:
#ifdef Foam_argList_1712
//- Read a value from the argument at index.
// Index 1 is the first non-option argument.
// Index 1 is the first (non-option) argument.
// \deprecated in favour of get() - AUG-2018
template<class T>
inline T read(const label index) const
{
return this->get<T>(index);
}
//- Read a value from the argument at index.
// Index 1 is the first (non-option) argument.
// \deprecated in favour of read() - JAN-2018
template<class T>
inline T argRead(const label index) const
{
return this->read<T>(index);
return this->get<T>(index);
}
//- Return true if the named option is found
@ -600,11 +609,11 @@ public:
}
//- Read a List of values from the named option
// \deprecated in favour of readList() - JAN-2018
// \deprecated in favour of getList() - JAN-2018
template<class T>
inline List<T> optionReadList(const word& optName) const
{
return this->readList<T>(optName);
return this->getList<T>(optName);
}
#endif /* Foam_argList_1712 */

View File

@ -133,22 +133,22 @@ inline Foam::ITstream Foam::argList::lookup(const word& optName) const
namespace Foam
{
template<> inline int32_t argList::read<int32_t>(const label index) const
template<> inline int32_t argList::get<int32_t>(const label index) const
{
return Foam::readInt32(args_[index]);
}
template<> inline int64_t argList::read<int64_t>(const label index) const
template<> inline int64_t argList::get<int64_t>(const label index) const
{
return Foam::readInt64(args_[index]);
}
template<> inline float argList::read<float>(const label index) const
template<> inline float argList::get<float>(const label index) const
{
return Foam::readFloat(args_[index]);
}
template<> inline double argList::read<double>(const label index) const
template<> inline double argList::get<double>(const label index) const
{
return Foam::readDouble(args_[index]);
}
@ -176,19 +176,19 @@ namespace Foam
template<>
inline string argList::read<Foam::string>(const label index) const
inline string argList::get<Foam::string>(const label index) const
{
return args_[index];
}
template<>
inline word argList::read<Foam::word>(const label index) const
inline word argList::get<Foam::word>(const label index) const
{
return args_[index];
}
template<>
inline fileName argList::read<Foam::fileName>(const label index) const
inline fileName argList::get<Foam::fileName>(const label index) const
{
return args_[index];
}
@ -217,7 +217,7 @@ namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline T Foam::argList::read(const label index) const
inline T Foam::argList::get(const label index) const
{
ITstream is(Foam::name(index), args_[index]);
@ -296,7 +296,7 @@ inline T Foam::argList::lookupOrDefault
template<class T>
inline Foam::List<T> Foam::argList::readList(const label index) const
inline Foam::List<T> Foam::argList::getList(const label index) const
{
ITstream is(Foam::name(index), args_[index]);
@ -310,7 +310,7 @@ inline Foam::List<T> Foam::argList::readList(const label index) const
template<class T>
inline Foam::List<T> Foam::argList::readList(const word& optName) const
inline Foam::List<T> Foam::argList::getList(const word& optName) const
{
ITstream is(optName, options_[optName]);