Commit f38ad72a authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: add argList::optionCount method

- convenience for checking is any/all particular options have been
  specified. Eg,

  if (args.optionCount({"opt1", "opt2", "opt3"}) < 3) ...
parent 4a6fc124
......@@ -58,6 +58,9 @@ int main(int argc, char *argv[])
argList args(argc, argv);
Info<<"have: "
<<args.optionCount({"label", "scalar"}) << " options" << nl;
label ival;
scalar sval;
......
......@@ -1283,6 +1283,37 @@ Foam::argList::~argList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::argList::optionCount(const UList<word>& optionNames) const
{
label n = 0;
for (const word& optName : optionNames)
{
if (options_.found(optName))
{
++n;
}
}
return n;
}
Foam::label Foam::argList::optionCount
(
std::initializer_list<word> optionNames
) const
{
label n = 0;
for (const word& optName : optionNames)
{
if (options_.found(optName))
{
++n;
}
}
return n;
}
bool Foam::argList::setOption(const word& optionName, const string& param)
{
// Some options are always protected
......
......@@ -302,6 +302,12 @@ public:
//- Return true if the named option is found
inline bool optionFound(const word& optionName) const;
//- Return how many of the specified options were used
label optionCount(const UList<word>& optionNames) const;
//- Return how many of the specified options were used
label optionCount(std::initializer_list<word> optionNames) const;
//- Return an input token stream for the named option
inline ITstream optionLookup(const word& optionName) const;
......
Supports Markdown
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