Commit 5415991e authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: argList::getList with optional parameter

- this allows it to work like readListIfPresent() but with a list as
  the return value, which can be useful for a const context.
parent a38b459a
......@@ -215,8 +215,8 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
wordRes selectedFields;
args.readListIfPresent<wordRe>("fields", selectedFields);
// Non-mandatory
const wordRes selectedFields(args.getList<wordRe>("fields", false));
if (selectedFields.empty())
{
......
......@@ -288,8 +288,8 @@ int main(int argc, char *argv[])
Info<< "Subtracting mapped source field from target" << endl;
}
wordRes selectedFields;
args.readListIfPresent<wordRe>("fields", selectedFields);
// Non-mandatory
const wordRes selectedFields(args.getList<wordRe>("fields", false));
const bool noLagrangian = args.found("noLagrangian");
......
......@@ -371,12 +371,15 @@ public:
const T& deflt
) const;
//- Read a List of values from the named option,
//- Get a List of values from the named option,
//- treating a single entry like a list of size 1.
// \param optName the option name to read from
// \param mandatory if the option is non-mandatory, the behaviour
// is similar to readListIfPresent().
template<class T>
inline List<T> getList(const word& optName) const;
inline List<T> getList(const word& optName, bool mandatory=true) const;
//- If named option is present, read a List of values
//- If named option is present, get a List of values
//- treating a single entry like a list of size 1.
// \return true if the named option was found.
template<class T>
......
......@@ -322,14 +322,22 @@ inline Foam::List<T> Foam::argList::getList(const label index) const
template<class T>
inline Foam::List<T> Foam::argList::getList(const word& optName) const
inline Foam::List<T> Foam::argList::getList
(
const word& optName,
bool mandatory
) const
{
ITstream is(optName, options_[optName]);
List<T> list;
readList(is, list);
checkITstream(is, optName);
if (mandatory || found(optName))
{
ITstream is(optName, options_[optName]);
readList(is, list);
checkITstream(is, optName);
}
return list;
}
......@@ -345,6 +353,7 @@ inline bool Foam::argList::readListIfPresent
if (found(optName))
{
ITstream is(optName, options_[optName]);
readList(is, list);
checkITstream(is, optName);
......
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