mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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.
This commit is contained in:
@ -215,8 +215,8 @@ int main(int argc, char *argv[])
|
|||||||
#include "setRootCase.H"
|
#include "setRootCase.H"
|
||||||
#include "createTime.H"
|
#include "createTime.H"
|
||||||
|
|
||||||
wordRes selectedFields;
|
// Non-mandatory
|
||||||
args.readListIfPresent<wordRe>("fields", selectedFields);
|
const wordRes selectedFields(args.getList<wordRe>("fields", false));
|
||||||
|
|
||||||
if (selectedFields.empty())
|
if (selectedFields.empty())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -288,8 +288,8 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "Subtracting mapped source field from target" << endl;
|
Info<< "Subtracting mapped source field from target" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
wordRes selectedFields;
|
// Non-mandatory
|
||||||
args.readListIfPresent<wordRe>("fields", selectedFields);
|
const wordRes selectedFields(args.getList<wordRe>("fields", false));
|
||||||
|
|
||||||
const bool noLagrangian = args.found("noLagrangian");
|
const bool noLagrangian = args.found("noLagrangian");
|
||||||
|
|
||||||
|
|||||||
@ -371,12 +371,15 @@ public:
|
|||||||
const T& deflt
|
const T& deflt
|
||||||
) const;
|
) 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.
|
//- 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>
|
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.
|
//- treating a single entry like a list of size 1.
|
||||||
// \return true if the named option was found.
|
// \return true if the named option was found.
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
@ -322,14 +322,22 @@ inline Foam::List<T> Foam::argList::getList(const label index) const
|
|||||||
|
|
||||||
|
|
||||||
template<class T>
|
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;
|
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;
|
return list;
|
||||||
}
|
}
|
||||||
@ -345,6 +353,7 @@ inline bool Foam::argList::readListIfPresent
|
|||||||
if (found(optName))
|
if (found(optName))
|
||||||
{
|
{
|
||||||
ITstream is(optName, options_[optName]);
|
ITstream is(optName, options_[optName]);
|
||||||
|
|
||||||
readList(is, list);
|
readList(is, list);
|
||||||
|
|
||||||
checkITstream(is, optName);
|
checkITstream(is, optName);
|
||||||
|
|||||||
Reference in New Issue
Block a user