ENH: support search options on more dictionary methods

- can now specify literal matches for sub-dictionary methods:

    isDict(key, keyType::REGEX)
    optionalSubDict(key, keyType::REGEX)
    subDict(key, keyType::REGEX)
    subOrEmptyDict(key, keyType::REGEX, mandatory)

There is no change in behaviour of the methods, just the search option
is now exposed as an optional parameter.

NOTE: minor breaking change for subOrEmptyDict()

  old: subOrEmptyDict(key, bool=false)
  new: subOrEmptyDict(key, keyType::option=keyType::REGEX, bool=false)

  This affects code that previously explicitly set the bool parameter.
  Within OpenFOAM itself, this only affected a single file:

      KinematicCloud.C
This commit is contained in:
Mark Olesen
2019-08-01 17:58:07 +02:00
parent bfd16ef3cb
commit db9fc1481c
3 changed files with 64 additions and 25 deletions

View File

@ -397,7 +397,11 @@ Foam::ITstream& Foam::dictionary::lookup
}
bool Foam::dictionary::substituteKeyword(const word& keyword, bool mergeEntry)
bool Foam::dictionary::substituteKeyword
(
const word& keyword,
bool mergeEntry
)
{
if (keyword.size() < 2)
{
@ -457,10 +461,13 @@ bool Foam::dictionary::substituteScopedKeyword
}
bool Foam::dictionary::isDict(const word& keyword) const
bool Foam::dictionary::isDict
(
const word& keyword,
enum keyType::option matchOpt
) const
{
// Allow patterns, non-recursive
return csearch(keyword, keyType::REGEX).isDict();
return csearch(keyword, matchOpt).isDict();
}
@ -484,10 +491,13 @@ const Foam::dictionary* Foam::dictionary::findDict
}
const Foam::dictionary& Foam::dictionary::subDict(const word& keyword) const
const Foam::dictionary& Foam::dictionary::subDict
(
const word& keyword,
enum keyType::option matchOpt
) const
{
// Allow patterns, non-recursive
const const_searcher finder(csearch(keyword, keyType::REGEX));
const const_searcher finder(csearch(keyword, matchOpt));
if (!finder.good())
{
@ -501,10 +511,13 @@ const Foam::dictionary& Foam::dictionary::subDict(const word& keyword) const
}
Foam::dictionary& Foam::dictionary::subDict(const word& keyword)
Foam::dictionary& Foam::dictionary::subDict
(
const word& keyword,
enum keyType::option matchOpt
)
{
// Allow patterns, non-recursive
searcher finder(search(keyword, keyType::REGEX));
searcher finder(search(keyword, matchOpt));
if (!finder.good())
{
@ -521,11 +534,11 @@ Foam::dictionary& Foam::dictionary::subDict(const word& keyword)
Foam::dictionary Foam::dictionary::subOrEmptyDict
(
const word& keyword,
enum keyType::option matchOpt,
const bool mandatory
) const
{
// Allow patterns, non-recursive
const const_searcher finder(csearch(keyword, keyType::REGEX));
const const_searcher finder(csearch(keyword, matchOpt));
if (finder.isDict())
{
@ -556,11 +569,11 @@ Foam::dictionary Foam::dictionary::subOrEmptyDict
const Foam::dictionary& Foam::dictionary::optionalSubDict
(
const word& keyword
const word& keyword,
enum keyType::option matchOpt
) const
{
// Allow patterns, non-recursive
const const_searcher finder(csearch(keyword, keyType::REGEX));
const const_searcher finder(csearch(keyword, matchOpt));
if (finder.isDict())
{

View File

@ -610,7 +610,7 @@ public:
//
// \param val the value to read into
// \param matchOpt the default search is non-recursive with patterns
// \param mandatory the keyword is mandatory
// \param mandatory the keyword is mandatory (default: true)
//
// \return true if the entry was found.
template<class T>
@ -720,29 +720,45 @@ public:
//- Check if entry is found and and is a sub-dictionary.
//
// Search type: non-recursive with patterns.
bool isDict(const word& keyword) const;
// \param matchOpt the default search is non-recursive with patterns
//
// \return true if the entry was found.
bool isDict
(
const word& keyword,
enum keyType::option matchOpt = keyType::REGEX
) const;
//- Find and return a sub-dictionary.
// Fatal if the entry does not exist or is not a sub-dictionary.
//
// Search type: non-recursive with patterns.
const dictionary& subDict(const word& keyword) const;
// \param matchOpt the default search is non-recursive with patterns
const dictionary& subDict
(
const word& keyword,
enum keyType::option matchOpt = keyType::REGEX
) const;
//- Find and return a sub-dictionary for manipulation.
// Fatal if the entry does not exist or is not a sub-dictionary.
//
// Search type: non-recursive with patterns.
dictionary& subDict(const word& keyword);
// \param matchOpt the default search is non-recursive with patterns
dictionary& subDict
(
const word& keyword,
enum keyType::option matchOpt = keyType::REGEX
);
//- Find and return a sub-dictionary as a copy, otherwise return
//- an empty dictionary.
// Warn if the entry exists but is not a sub-dictionary.
//
// Search type: non-recursive with patterns.
// \param matchOpt the default search is non-recursive with patterns
// \param mandatory the keyword is mandatory (default: false)
dictionary subOrEmptyDict
(
const word& keyword,
enum keyType::option matchOpt = keyType::REGEX,
const bool mandatory = false
) const;
@ -750,7 +766,11 @@ public:
// Warn if the entry exists but is not a sub-dictionary.
//
// Search type: non-recursive with patterns.
const dictionary& optionalSubDict(const word& keyword) const;
const dictionary& optionalSubDict
(
const word& keyword,
enum keyType::option matchOpt = keyType::REGEX
) const;
//- Return the table of contents
wordList toc() const;

View File

@ -325,7 +325,12 @@ Foam::KinematicCloud<CloudType>::KinematicCloud
constProps_(particleProperties_),
subModelProperties_
(
particleProperties_.subOrEmptyDict("subModels", solution_.active())
particleProperties_.subOrEmptyDict
(
"subModels",
keyType::REGEX,
solution_.active()
)
),
rndGen_(Pstream::myProcNo()),
cellOccupancyPtr_(),
@ -342,6 +347,7 @@ Foam::KinematicCloud<CloudType>::KinematicCloud
subModelProperties_.subOrEmptyDict
(
"particleForces",
keyType::REGEX,
solution_.active()
),
solution_.active()