mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add argList::optionCount method
- convenience for checking is any/all particular options have been
specified. Eg,
if (args.optionCount({"opt1", "opt2", "opt3"}) < 3) ...
This commit is contained in:
@ -58,6 +58,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
argList args(argc, argv);
|
argList args(argc, argv);
|
||||||
|
|
||||||
|
Info<<"have: "
|
||||||
|
<<args.optionCount({"label", "scalar"}) << " options" << nl;
|
||||||
|
|
||||||
label ival;
|
label ival;
|
||||||
scalar sval;
|
scalar sval;
|
||||||
|
|
||||||
|
|||||||
@ -1283,6 +1283,37 @@ Foam::argList::~argList()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * 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)
|
bool Foam::argList::setOption(const word& optionName, const string& param)
|
||||||
{
|
{
|
||||||
// Some options are always protected
|
// Some options are always protected
|
||||||
|
|||||||
@ -302,6 +302,12 @@ public:
|
|||||||
//- Return true if the named option is found
|
//- Return true if the named option is found
|
||||||
inline bool optionFound(const word& optionName) const;
|
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
|
//- Return an input token stream for the named option
|
||||||
inline ITstream optionLookup(const word& optionName) const;
|
inline ITstream optionLookup(const word& optionName) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user