Extract command arguments and options from the supplied argc and argv parameters. More...
Classes | |
class | initValidTables |
Public Member Functions | |
argList (int &argc, char **&argv, bool checkArgs=true, bool checkOpts=true, bool initialise=true) | |
Construct from argc and argv. More... | |
argList (const argList &args, const HashTable< string > &options, bool checkArgs=true, bool checkOpts=true, bool initialise=true) | |
Construct copy with new options. More... | |
virtual | ~argList () |
Destructor. More... | |
void | parse (bool checkArgs, bool checkOpts, bool initialise) |
Parse. More... | |
const string & | commandLine () const |
Return the command line string. More... | |
const word & | executable () const |
Name of executable without the path. More... | |
const fileName & | rootPath () const |
Return root path. More... | |
const fileName & | caseName () const |
Return case name (parallel run) or global case (serial run) More... | |
const fileName & | globalCaseName () const |
Return case name. More... | |
const ParRunControl & | parRunControl () const |
Return parRunControl. More... | |
fileName | path () const |
Return the path to the caseName. More... | |
const stringList & | args () const |
Return arguments. More... | |
stringList & | args () |
Return non-const access to arguments. More... | |
const string & | arg (const label index) const |
Return the argument corresponding to index. More... | |
label | size () const |
Return the number of arguments. More... | |
template<class T > | |
T | argRead (const label index) const |
Read a value from the argument at index. More... | |
const Foam::HashTable< string > & | options () const |
Return options. More... | |
Foam::HashTable< string > & | options () |
Return non-const access to options. More... | |
const string & | option (const word &opt) const |
Return the argument string associated with the named option. More... | |
bool | optionFound (const word &opt) const |
Return true if the named option is found. More... | |
IStringStream | optionLookup (const word &opt) const |
Return an IStringStream from the named option. More... | |
template<class T > | |
T | optionRead (const word &opt) const |
Read a value from the named option. More... | |
template<class T > | |
bool | optionReadIfPresent (const word &opt, T &) const |
Read a value from the named option if present. More... | |
template<class T > | |
bool | optionReadIfPresent (const word &opt, T &, const T &deflt) const |
Read a value from the named option if present. More... | |
template<class T > | |
T | optionLookupOrDefault (const word &opt, const T &deflt) const |
Read a value from the named option if present. More... | |
template<class T > | |
List< T > | optionReadList (const word &opt) const |
Read a List of values from the named option. More... | |
const string & | operator[] (const label index) const |
Return the argument corresponding to index. More... | |
const string & | operator[] (const word &opt) const |
Return the argument string associated with the named option. More... | |
bool | setOption (const word &opt, const string ¶m="") |
Set option directly (use with caution) More... | |
bool | unsetOption (const word &opt) |
Unset option directly (use with caution) More... | |
void | printNotes () const |
Print notes (if any) More... | |
void | printUsage () const |
Print usage. More... | |
void | displayDoc (bool source=false) const |
Display documentation in browser. More... | |
bool | check (bool checkArgs=true, bool checkOpts=true) const |
Check argument list. More... | |
bool | checkRootCase () const |
Check root path and case path. More... | |
Static Public Member Functions | |
static void | addBoolOption (const word &opt, const string &usage="") |
Add to a bool option to validOptions with usage information. More... | |
static void | addOption (const word &opt, const string ¶m="", const string &usage="") |
Add to an option to validOptions with usage information. More... | |
static void | addUsage (const word &opt, const string &usage) |
Add option usage information to optionUsage. More... | |
static void | addNote (const string &) |
Add extra notes for the usage information. More... | |
static void | removeOption (const word &opt) |
Remove option from validOptions and from optionUsage. More... | |
static void | noParallel () |
Remove the parallel options. More... | |
static bool | postProcess (int argc, char *argv[]) |
Return true if the post-processing option is specified. More... | |
static bool | hasArgs (int argc, char *argv[]) |
Return true if there are arguments. More... | |
Static Public Attributes | |
static SLList< string > | validArgs |
A list of valid (mandatory) arguments. More... | |
static HashTable< string > | validOptions |
A list of valid options. More... | |
static HashTable< string > | validParOptions |
A list of valid parallel options. More... | |
static HashTable< string > | optionUsage |
Short usage information for validOptions. More... | |
static SLList< string > | notes |
Additional notes for usage. More... | |
static string::size_type | usageMin = 20 |
Min offset for displaying usage (default: 20) More... | |
static string::size_type | usageMax = 80 |
Max screen width for displaying usage (default: 80) More... | |
static word | postProcessOptionName |
Standard name for the post-processing option. More... | |
Extract command arguments and options from the supplied argc and argv parameters.
Sequences with "(" ... ")" are transformed into a stringList. For example,
program -listFiles \( *.txt \)
would create a stringList:
( "file1.txt" "file2.txt" ... "fileN.txt" )
The backslash-escaping is required to avoid interpretation by the shell.
Default command-line options:
Note:
Documentation/docBrowser
entry in the ~OpenFOAM/controlDict
file. The %f token is used as a placeholder for the file name.argList | ( | int & | argc, |
char **& | argv, | ||
bool | checkArgs = true , |
||
bool | checkOpts = true , |
||
bool | initialise = true |
||
) |
Construct from argc and argv.
checking the arguments and options as requested
Definition at line 437 of file argList.C.
References fileOperation::defaultFileHandler, Foam::endl(), error::exit(), Foam::FatalError, Foam::getEnv(), Foam::libs, fileName::name(), fileOperationInitialise::New(), dlLibraryTable::open(), argList::parse(), argList::printUsage(), argList::validOptions, and argList::validParOptions.
Referenced by argList::hasArgs().
argList | ( | const argList & | args, |
const HashTable< string > & | options, | ||
bool | checkArgs = true , |
||
bool | checkOpts = true , |
||
bool | initialise = true |
||
) |
Construct copy with new options.
Definition at line 583 of file argList.C.
References argList::parse().
|
virtual |
Destructor.
Definition at line 1100 of file argList.C.
References Foam::fileHandler(), and Foam::jobInfo_.
Parse.
Definition at line 605 of file argList.C.
References dictionary::add(), dynamicCode::allowSystemOperations, argList::check(), clock::clockTime(), UPstream::commsTypeNames, Foam::cwd(), clock::date(), UPstream::defaultCommsType, fileOperation::defaultFileHandler, argList::displayDoc(), Foam::endl(), argList::executable(), Foam::exit(), error::exit(), Foam::FatalError, FatalErrorIn, FatalErrorInFunction, IOobject::fileCheckTypesNames, Foam::fileHandler(), IOobject::fileModificationChecking, regIOobject::fileModificationSkew, Foam::findStrings(), Tuple2< Type1, Type2 >::first(), UPstream::firstSlave(), UPstream::floatTransfer, Foam::FOAMbuild, Foam::FOAMversion, forAll, found, Foam::getEnv(), IOstream::good(), Foam::hostName(), Foam::Info, Foam::isDir(), Foam::jobInfo_, UPstream::lastSlave(), dictionary::lookup(), dictionary::lookupOrDefault(), UPstream::master(), UPstream::masterNo(), UPstream::myProcNo(), Foam::name(), fileOperation::New(), Foam::nl, UPstream::nPollProcInterfaces, UPstream::nProcs(), UPstream::nProcsSimpleSum, Foam::pgid(), Foam::pid(), Foam::ppid(), argList::printUsage(), Foam::constant::atomic::re, UPstream::scheduled, Tuple2< Type1, Type2 >::second(), List< T >::setSize(), List< T >::size(), IOobject::timeStamp, IOobject::timeStampMaster, Foam::userName(), IOobject::writeBanner(), IOobject::writeDivider(), and Foam::writeInfoHeader.
Referenced by argList::argList().
|
inline |
Return the command line string.
Definition at line 30 of file argListI.H.
Referenced by functionObjectList::New().
|
inline |
Name of executable without the path.
Definition at line 36 of file argListI.H.
Referenced by forAll(), if(), argList::parse(), and Time::Time().
|
inline |
Return root path.
Definition at line 42 of file argListI.H.
Referenced by argList::checkRootCase(), and argList::path().
|
inline |
Return case name (parallel run) or global case (serial run)
Definition at line 48 of file argListI.H.
Referenced by argList::path().
|
inline |
Return case name.
Definition at line 54 of file argListI.H.
|
inline |
Return parRunControl.
Definition at line 60 of file argListI.H.
|
inline |
Return the path to the caseName.
Definition at line 66 of file argListI.H.
References argList::caseName(), and argList::rootPath().
Referenced by argList::checkRootCase(), and Time::Time().
|
inline |
Return arguments.
Definition at line 72 of file argListI.H.
|
inline |
Return non-const access to arguments.
Definition at line 78 of file argListI.H.
|
inline |
Return the argument corresponding to index.
Definition at line 84 of file argListI.H.
Referenced by argList::hasArgs().
|
inline |
Return the number of arguments.
Definition at line 90 of file argListI.H.
References List< T >::size().
Referenced by argList::printUsage().
Read a value from the argument at index.
Index 0 corresponds to the name of the executable. Index 1 corresponds to the first argument.
Definition at line 183 of file argListI.H.
References Foam::T().
|
inline |
Return options.
Definition at line 96 of file argListI.H.
Referenced by Time::Time().
|
inline |
Return non-const access to options.
Definition at line 102 of file argListI.H.
|
inline |
Return the argument string associated with the named option.
Definition at line 108 of file argListI.H.
Return true if the named option is found.
Definition at line 114 of file argListI.H.
Referenced by if(), functionObjectList::New(), argList::optionLookupOrDefault(), argList::optionReadIfPresent(), timeSelector::select(), timeSelector::selectIfPresent(), Foam::selectRegionNames(), and Foam::systemDictIO().
|
inline |
Return an IStringStream from the named option.
Definition at line 120 of file argListI.H.
Referenced by functionObjectList::New(), argList::optionRead(), argList::optionReadList(), and timeSelector::select().
Read a value from the named option.
Definition at line 193 of file argListI.H.
References argList::optionLookup(), argList::optionReadIfPresent(), and Foam::T().
Referenced by if().
Read a value from the named option if present.
Return true if the named option was found.
Definition at line 204 of file argListI.H.
References argList::optionFound().
Referenced by argList::optionRead(), and Foam::selectRegionNames().
Read a value from the named option if present.
Return true if the named option was found, otherwise use the supplied default and return false.
Definition at line 223 of file argListI.H.
References argList::optionLookupOrDefault(), and Foam::T().
Read a value from the named option if present.
Return supplied default otherwise.
Definition at line 243 of file argListI.H.
References argList::optionFound().
Referenced by argList::optionReadIfPresent().
Read a List of values from the named option.
Definition at line 316 of file argList.H.
References argList::addBoolOption(), argList::addNote(), argList::addOption(), argList::addUsage(), argList::check(), argList::checkRootCase(), argList::displayDoc(), argList::hasArgs(), argList::noParallel(), argList::operator[](), argList::optionLookup(), argList::postProcess(), argList::printNotes(), argList::printUsage(), argList::removeOption(), argList::setOption(), and argList::unsetOption().
|
inline |
Return the argument corresponding to index.
Index 0 corresponds to the name of the executable. Index 1 corresponds to the first argument.
Definition at line 261 of file argListI.H.
Referenced by argList::optionReadList().
|
inline |
Return the argument string associated with the named option.
Definition at line 267 of file argListI.H.
Add to a bool option to validOptions with usage information.
Definition at line 118 of file argList.C.
References argList::addOption().
Referenced by timeSelector::addOptions(), argList::initValidTables::initValidTables(), and argList::optionReadList().
Add to an option to validOptions with usage information.
An option with an empty param is a bool option
Definition at line 128 of file argList.C.
References argList::addUsage(), argList::optionUsage, and argList::validOptions.
Referenced by argList::addBoolOption(), timeSelector::addOptions(), argList::initValidTables::initValidTables(), and argList::optionReadList().
Add option usage information to optionUsage.
Definition at line 143 of file argList.C.
References argList::optionUsage.
Referenced by argList::addOption(), and argList::optionReadList().
|
static |
Add extra notes for the usage information.
This string is used "as-is" without additional formatting
Definition at line 159 of file argList.C.
References argList::notes.
Referenced by argList::optionReadList().
|
static |
Remove option from validOptions and from optionUsage.
Definition at line 168 of file argList.C.
References argList::optionUsage, and argList::validOptions.
Referenced by argList::initValidTables::clear(), argList::noParallel(), and argList::optionReadList().
|
static |
Remove the parallel options.
Definition at line 175 of file argList.C.
References Foam::Info, Foam::isspace(), Foam::nl, Foam::pos(), argList::removeOption(), argList::usageMax, argList::usageMin, and argList::validParOptions.
Referenced by argList::optionReadList().
|
static |
Return true if the post-processing option is specified.
Definition at line 284 of file argList.C.
References argList::postProcessOptionName.
Referenced by argList::optionReadList().
|
static |
Return true if there are arguments.
Definition at line 298 of file argList.C.
References argList::arg(), argList::argList(), fileName::clean(), Foam::cwd(), fileName::isAbsolute(), fileName::name(), fileName::path(), Foam::setEnv(), and argList::validOptions.
Referenced by argList::optionReadList().
Set option directly (use with caution)
An option with an empty param is a bool option. Not all valid options can also be set: eg, -case, -roots, ... Return true if the existing option value needed changing, or if the option did not previously exist.
Definition at line 1112 of file argList.C.
References Foam::endl(), error::exit(), Foam::FatalError, Foam::nl, and argList::validOptions.
Referenced by argList::optionReadList().
Unset option directly (use with caution)
Not all valid options can also be unset: eg, -case, -roots ... Return true if the option existed before being unset.
Definition at line 1188 of file argList.C.
References Foam::endl(), error::exit(), Foam::FatalError, Foam::nl, and argList::validOptions.
Referenced by argList::optionReadList().
void printNotes | ( | ) | const |
Print notes (if any)
Definition at line 1224 of file argList.C.
References forAllConstIter, Foam::Info, Foam::nl, and argList::notes.
Referenced by argList::optionReadList(), and argList::printUsage().
void printUsage | ( | ) | const |
Print usage.
Definition at line 1238 of file argList.C.
References Foam::endl(), Foam::FOAMbuild, Foam::FOAMversion, forAll, forAllConstIter, Foam::Info, Foam::nl, argList::optionUsage, argList::printNotes(), argList::size(), argList::validArgs, and argList::validOptions.
Referenced by argList::argList(), argList::check(), forAll(), argList::optionReadList(), and argList::parse().
void displayDoc | ( | bool | source = false | ) | const |
Display documentation in browser.
Optionally display the application source code
Definition at line 1323 of file argList.C.
References Foam::component(), Foam::debug::controlDict(), Foam::endl(), string::expand(), forAll, found, Foam::getEnv(), Foam::Info, Foam::isFile(), dictionary::lookup(), Foam::nl, string::null, fileName::null, string::replace(), dictionary::subDict(), and Foam::system().
Referenced by argList::optionReadList(), and argList::parse().
Check argument list.
Definition at line 1400 of file argList.C.
References Foam::endl(), Foam::FatalError, forAllConstIter, UPstream::master(), argList::printUsage(), argList::validArgs, argList::validOptions, and argList::validParOptions.
Referenced by argList::optionReadList(), and argList::parse().
bool checkRootCase | ( | ) | const |
Check root path and case path.
Definition at line 1441 of file argList.C.
References Foam::endl(), Foam::FatalError, Foam::fileHandler(), Foam::isDir(), UPstream::master(), argList::path(), and argList::rootPath().
Referenced by argList::optionReadList().
|
static |
A list of valid (mandatory) arguments.
Definition at line 153 of file argList.H.
Referenced by argList::check(), and argList::printUsage().
|
static |
A list of valid options.
Definition at line 156 of file argList.H.
Referenced by argList::addOption(), argList::argList(), argList::check(), argList::hasArgs(), argList::printUsage(), argList::removeOption(), timeSelector::select(), argList::setOption(), and argList::unsetOption().
|
static |
A list of valid parallel options.
Definition at line 159 of file argList.H.
Referenced by argList::argList(), argList::check(), argList::initValidTables::initValidTables(), and argList::noParallel().
|
static |
Short usage information for validOptions.
Definition at line 162 of file argList.H.
Referenced by argList::addOption(), argList::addUsage(), argList::printUsage(), and argList::removeOption().
|
static |
Additional notes for usage.
Definition at line 165 of file argList.H.
Referenced by argList::addNote(), and argList::printNotes().
|
static |
Min offset for displaying usage (default: 20)
Definition at line 168 of file argList.H.
Referenced by argList::noParallel().
|
static |
Max screen width for displaying usage (default: 80)
Definition at line 171 of file argList.H.
Referenced by argList::noParallel().
|
static |
Standard name for the post-processing option.
Definition at line 174 of file argList.H.
Referenced by argList::postProcess().