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

@ -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;