From f38ad72ad058a5e3bcb03650fb59e49160a3d10c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 19 Dec 2017 08:20:45 +0100 Subject: [PATCH] ENH: add argList::optionCount method - convenience for checking is any/all particular options have been specified. Eg, if (args.optionCount({"opt1", "opt2", "opt3"}) < 3) ... --- applications/test/argList/Test-argList.C | 3 +++ src/OpenFOAM/global/argList/argList.C | 31 ++++++++++++++++++++++++ src/OpenFOAM/global/argList/argList.H | 6 +++++ 3 files changed, 40 insertions(+) diff --git a/applications/test/argList/Test-argList.C b/applications/test/argList/Test-argList.C index e885ff9fb0..b3394845f5 100644 --- a/applications/test/argList/Test-argList.C +++ b/applications/test/argList/Test-argList.C @@ -58,6 +58,9 @@ int main(int argc, char *argv[]) argList args(argc, argv); + Info<<"have: " + <& 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 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 diff --git a/src/OpenFOAM/global/argList/argList.H b/src/OpenFOAM/global/argList/argList.H index fe4f5cb724..0e1d3631a5 100644 --- a/src/OpenFOAM/global/argList/argList.H +++ b/src/OpenFOAM/global/argList/argList.H @@ -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& optionNames) const; + + //- Return how many of the specified options were used + label optionCount(std::initializer_list optionNames) const; + //- Return an input token stream for the named option inline ITstream optionLookup(const word& optionName) const;