diff --git a/applications/test/List/ListTest.C b/applications/test/List/ListTest.C index d06c65d98aa9740243accf3c69b3b57ca9918ff0..0fee9a9e3b5bd907a611dbad46e91ccd8984a321 100644 --- a/applications/test/List/ListTest.C +++ b/applications/test/List/ListTest.C @@ -50,6 +50,8 @@ int main(int argc, char *argv[]) argList::validOptions.insert("reList", "reList"); argList::validOptions.insert("wordList", "wordList"); argList::validOptions.insert("stringList", "stringList"); + argList::validOptions.insert("float", "xx"); + argList::validOptions.insert("flag", ""); # include "setRootCase.H" @@ -84,19 +86,31 @@ int main(int argc, char *argv[]) stringList sLst; - if (args.options().found("reList")) + scalar xxx(-1); + + if (args.optionFound("flag")) + { + Info<<"-flag:" << args.option("flag") << endl; + } + + if (args.optionReadIfPresent<scalar>("float", xxx)) + { + Info<<"read float " << xxx << endl; + } + + if (args.optionFound("reList")) { - reLst = readList<wordRe>(IStringStream(args.options()["reList"])()); + reLst = args.optionReadList<wordRe>("reList"); } - if (args.options().found("wordList")) + if (args.optionFound("wordList")) { - wLst = readList<word>(IStringStream(args.options()["wordList"])()); + wLst = args.optionReadList<word>("wordList"); } - if (args.options().found("stringList")) + if (args.optionFound("stringList")) { - sLst = readList<string>(IStringStream(args.options()["stringList"])()); + sLst = args.optionReadList<string>("stringList"); } Info<< nl diff --git a/src/OpenFOAM/global/argList/argList.H b/src/OpenFOAM/global/argList/argList.H index c5fcf5d53c7ab2aed02df2565430d8eb153d2a9b..9fdb0bb6d2224ceebdc76b53a66239849c5dd4e4 100644 --- a/src/OpenFOAM/global/argList/argList.H +++ b/src/OpenFOAM/global/argList/argList.H @@ -56,10 +56,10 @@ Description global case (same for serial and parallel jobs). Note - - Adjustment of the valid (mandatory) arguments by directly manipulating - the static member argList::validArgs. - - Adjustment of the valid options by directly manipulating - the static member argList::validOptions. + - Adjustment of the valid (mandatory) arguments + by directly manipulating the static member argList::validArgs. + - Adjustment of the valid options + by directly manipulating the static member argList::validOptions. SourceFiles argList.C @@ -76,6 +76,7 @@ SourceFiles #include "word.H" #include "fileName.H" #include "parRun.H" +#include "IStringStream.H" #include "sigFpe.H" #include "sigInt.H" @@ -165,6 +166,36 @@ public: // Access + //- Name of executable + const word& executable() const + { + return executable_; + } + + //- Return root path + const fileName& rootPath() const + { + return rootPath_; + } + + //- Return case name + const fileName& globalCaseName() const + { + return globalCase_; + } + + //- Return case name (parallel run) or global case (serial run) + const fileName& caseName() const + { + return case_; + } + + //- Return the path + fileName path() const + { + return rootPath()/caseName(); + } + //- Return arguments const stringList& args() const { @@ -181,34 +212,54 @@ public: return options_; } - //- Name of executable - const word& executable() const + //- Return the argument string associated with the named option + const string& option(const word& opt) const { - return executable_; + return options_.operator[](opt); } - //- Return root path - const fileName& rootPath() const + //- Return true if the named option is found + bool optionFound(const word& opt) const { - return rootPath_; + return options_.found(opt); } - //- Return case name - const fileName& globalCaseName() const + //- Return an IStringStream to the named option + IStringStream optionLookup(const word& opt) const { - return globalCase_; + return IStringStream(option(opt)); } - //- Return case name (parallel run) or global case (serial run) - const fileName& caseName() const + //- Read a value from the named option + template<class T> + T optionRead(const word& opt) const { - return case_; + T val; + optionLookup(opt)() >> val; + return val; } - //- Return the path - fileName path() const + //- Read a value from the named option if present. + // Return true if the named option was found. + template<class T> + bool optionReadIfPresent(const word& opt, T& val) const { - return rootPath()/caseName(); + if (optionFound(opt)) + { + optionLookup(opt)() >> val; + return true; + } + else + { + return false; + } + } + + //- Read a List of values from the named option + template<class T> + List<T> optionReadList(const word& opt) const + { + return readList<T>(optionLookup(opt)()); }