mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: use readOption to fine-tune dictionary reading
- previously had 'mandatory' (bool) for advanced control of reading dictionary entries but its meaning was unclear in the calling code without extra code comments. Now use IOobjectOption::readOption instead, which allows further options (ie, NO_READ) and is more transparent as to its purpose in the code than a true/false bool flag was. This is a minor breaking change (infrequent, advanced usage only) - minor code cleanup in dictionary lookup methods
This commit is contained in:
@ -368,9 +368,9 @@ const Foam::entry& Foam::dictionary::lookupEntry
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
const const_searcher finder(csearch(keyword, matchOpt));
|
||||
const entry* eptr = findEntry(keyword, matchOpt);
|
||||
|
||||
if (!finder.good())
|
||||
if (!eptr)
|
||||
{
|
||||
FatalIOErrorInFunction(*this)
|
||||
<< "Entry '" << keyword << "' not found in dictionary "
|
||||
@ -378,7 +378,7 @@ const Foam::entry& Foam::dictionary::lookupEntry
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
return finder.ref();
|
||||
return *eptr;
|
||||
}
|
||||
|
||||
|
||||
@ -504,12 +504,12 @@ Foam::dictionary& Foam::dictionary::subDictOrAdd
|
||||
{
|
||||
searcher finder(search(keyword, matchOpt));
|
||||
|
||||
dictionary* ptr = finder.dictPtr();
|
||||
dictionary* dictPtr = finder.dictPtr();
|
||||
|
||||
if (ptr)
|
||||
if (dictPtr)
|
||||
{
|
||||
// Found and a sub-dictionary
|
||||
return *ptr;
|
||||
return *dictPtr;
|
||||
}
|
||||
|
||||
if (finder.good())
|
||||
@ -521,9 +521,9 @@ Foam::dictionary& Foam::dictionary::subDictOrAdd
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
ptr = this->set(keyword, dictionary())->dictPtr();
|
||||
dictPtr = this->set(keyword, dictionary())->dictPtr();
|
||||
|
||||
if (!ptr)
|
||||
if (!dictPtr)
|
||||
{
|
||||
FatalIOErrorInFunction(*this)
|
||||
<< "Failed to insert sub-dictionary '" << keyword
|
||||
@ -532,7 +532,7 @@ Foam::dictionary& Foam::dictionary::subDictOrAdd
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
return *ptr;
|
||||
return *dictPtr;
|
||||
}
|
||||
|
||||
|
||||
@ -545,10 +545,12 @@ Foam::dictionary Foam::dictionary::subOrEmptyDict
|
||||
{
|
||||
const const_searcher finder(csearch(keyword, matchOpt));
|
||||
|
||||
if (finder.isDict())
|
||||
const dictionary* dictPtr = finder.dictPtr();
|
||||
|
||||
if (dictPtr)
|
||||
{
|
||||
// Found and a sub-dictionary
|
||||
return finder.dict();
|
||||
return *dictPtr;
|
||||
}
|
||||
|
||||
if (mandatory)
|
||||
@ -581,10 +583,12 @@ const Foam::dictionary& Foam::dictionary::optionalSubDict
|
||||
{
|
||||
const const_searcher finder(csearch(keyword, matchOpt));
|
||||
|
||||
if (finder.isDict())
|
||||
const dictionary* dictPtr = finder.dictPtr();
|
||||
|
||||
if (dictPtr)
|
||||
{
|
||||
// Found and a sub-dictionary
|
||||
return finder.dict();
|
||||
return *dictPtr;
|
||||
}
|
||||
|
||||
if (finder.good())
|
||||
@ -787,10 +791,12 @@ Foam::entry* Foam::dictionary::set(entry* entryPtr)
|
||||
// Find non-recursive with patterns
|
||||
searcher finder(search(entryPtr->keyword(), keyType::REGEX));
|
||||
|
||||
dictionary* dictPtr = finder.dictPtr();
|
||||
|
||||
// Clear dictionary so merge acts like overwrite
|
||||
if (finder.isDict())
|
||||
if (dictPtr)
|
||||
{
|
||||
finder.dict().clear();
|
||||
dictPtr->clear();
|
||||
}
|
||||
|
||||
return add(entryPtr, true);
|
||||
|
||||
@ -98,6 +98,7 @@ SeeAlso
|
||||
#include "wordList.H"
|
||||
#include "className.H"
|
||||
#include "refPtr.H"
|
||||
#include "IOobjectOption.H"
|
||||
|
||||
// Some common data types
|
||||
#include "label.H"
|
||||
@ -175,14 +176,14 @@ public:
|
||||
|
||||
//- Construct for the given dictionary context.
|
||||
// Allow implicit conversion
|
||||
Searcher(dict_pointer dict)
|
||||
Searcher(dict_pointer dict) noexcept
|
||||
:
|
||||
dict_(dict),
|
||||
eptr_(nullptr)
|
||||
{}
|
||||
|
||||
//- Assign the entry
|
||||
void set(pointer eptr)
|
||||
void set(pointer eptr) noexcept
|
||||
{
|
||||
eptr_ = eptr;
|
||||
}
|
||||
@ -191,7 +192,7 @@ public:
|
||||
public:
|
||||
|
||||
//- Default construct
|
||||
Searcher()
|
||||
constexpr Searcher() noexcept
|
||||
:
|
||||
dict_(nullptr),
|
||||
eptr_(nullptr)
|
||||
@ -199,34 +200,19 @@ public:
|
||||
|
||||
|
||||
//- True if entry was found
|
||||
bool good() const noexcept
|
||||
{
|
||||
return eptr_;
|
||||
}
|
||||
bool good() const noexcept { return eptr_; }
|
||||
|
||||
//- True if entry was found
|
||||
bool found() const noexcept
|
||||
{
|
||||
return eptr_;
|
||||
}
|
||||
bool found() const noexcept { return eptr_; }
|
||||
|
||||
//- The containing dictionary context
|
||||
dict_reference context() const
|
||||
{
|
||||
return *dict_;
|
||||
}
|
||||
dict_reference context() const { return *dict_; }
|
||||
|
||||
//- A pointer to the entry (nullptr if not found)
|
||||
pointer ptr() const noexcept
|
||||
{
|
||||
return eptr_;
|
||||
}
|
||||
pointer ptr() const noexcept { return eptr_; }
|
||||
|
||||
//- A reference to the entry (Error if not found)
|
||||
reference ref() const
|
||||
{
|
||||
return *eptr_;
|
||||
}
|
||||
reference ref() const { return *eptr_; }
|
||||
|
||||
//- True if found entry is a dictionary.
|
||||
bool isDict() const noexcept
|
||||
@ -507,26 +493,26 @@ public:
|
||||
tokenList tokens() const;
|
||||
|
||||
|
||||
// Search and lookup
|
||||
// Searching
|
||||
|
||||
//- Search for an entry (const access) with the given keyword.
|
||||
//- Find an entry (const access) with the given keyword.
|
||||
//
|
||||
// \param keyword the keyword to search for
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
//
|
||||
// \return True if entry was found
|
||||
inline bool found
|
||||
// \return pointer to the entry found or a nullptr.
|
||||
inline const entry* findEntry
|
||||
(
|
||||
const word& keyword,
|
||||
enum keyType::option matchOpt = keyType::REGEX
|
||||
) const;
|
||||
|
||||
//- Find for an entry (non-const access) with the given keyword.
|
||||
//- Find an entry (non-const access) with the given keyword.
|
||||
//
|
||||
// \param keyword the keyword to search for
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
//
|
||||
// \return the entry pointer found or a nullptr.
|
||||
// \return pointer to the entry found or a nullptr.
|
||||
inline entry* findEntry
|
||||
(
|
||||
const word& keyword,
|
||||
@ -538,8 +524,8 @@ public:
|
||||
// \param keyword the keyword to search for
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
//
|
||||
// \return the entry pointer found or a nullptr.
|
||||
inline const entry* findEntry
|
||||
// \return True if entry was found
|
||||
inline bool found
|
||||
(
|
||||
const word& keyword,
|
||||
enum keyType::option matchOpt = keyType::REGEX
|
||||
@ -553,7 +539,7 @@ public:
|
||||
// \param keyword the keyword to search for
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
//
|
||||
// \return the entry pointer found or a nullptr.
|
||||
// \return pointer to the entry found or a nullptr.
|
||||
inline const entry* findScoped
|
||||
(
|
||||
const word& keyword,
|
||||
@ -561,7 +547,20 @@ public:
|
||||
) const;
|
||||
|
||||
//- Find and return a sub-dictionary pointer if present
|
||||
// (and a sub-dictionary) otherwise return nullptr.
|
||||
//- (and a sub-dictionary) otherwise return nullptr.
|
||||
//
|
||||
// \param keyword the keyword to search for
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
//
|
||||
// \return pointer to sub-dictionary found or a nullptr.
|
||||
inline const dictionary* findDict
|
||||
(
|
||||
const word& keyword,
|
||||
enum keyType::option matchOpt = keyType::REGEX
|
||||
) const;
|
||||
|
||||
//- Find and return a sub-dictionary pointer if present
|
||||
//- (and a sub-dictionary) otherwise return nullptr.
|
||||
//
|
||||
// \param keyword the keyword to search for
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
@ -573,19 +572,21 @@ public:
|
||||
enum keyType::option matchOpt = keyType::REGEX
|
||||
);
|
||||
|
||||
//- Find and return a sub-dictionary pointer if present
|
||||
// (and a sub-dictionary) otherwise return nullptr.
|
||||
//- Find a sub-dictionary.
|
||||
//
|
||||
// \param keyword the keyword to search for
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
//
|
||||
// \return pointer to sub-dictionary found or a nullptr.
|
||||
inline const dictionary* findDict
|
||||
// \return true if the sub-dictionary was found
|
||||
inline bool isDict
|
||||
(
|
||||
const word& keyword,
|
||||
enum keyType::option matchOpt = keyType::REGEX
|
||||
) const;
|
||||
|
||||
|
||||
// Lookup
|
||||
|
||||
//- Search for an entry (const access) with the given keyword.
|
||||
//
|
||||
// \param keyword the keyword to search for
|
||||
@ -659,16 +660,16 @@ public:
|
||||
// \param keyword the keyword to search for
|
||||
// \param val the value to read into
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
// \param mandatory the keyword is mandatory (default: true)
|
||||
// \param readOpt the entry is required/optional (default: MUST_READ)
|
||||
//
|
||||
// \return true if the entry was found.
|
||||
// \return true if the entry was read
|
||||
template<class T>
|
||||
bool readEntry
|
||||
(
|
||||
const word& keyword,
|
||||
T& val,
|
||||
enum keyType::option matchOpt = keyType::REGEX,
|
||||
bool mandatory = true
|
||||
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
|
||||
) const;
|
||||
|
||||
//- Find an entry if present, and assign to T val.
|
||||
@ -678,7 +679,7 @@ public:
|
||||
// \param val the value to read into
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
//
|
||||
// \return true if the entry was found.
|
||||
// \return true if the entry was read
|
||||
template<class T>
|
||||
bool readIfPresent
|
||||
(
|
||||
@ -742,9 +743,9 @@ public:
|
||||
// \param val the value to read into
|
||||
// \param pred the value check predicate
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
// \param mandatory the keyword is mandatory (default: true)
|
||||
// \param readOpt the entry is required/optional (default: MUST_READ)
|
||||
//
|
||||
// \return true if the entry was found.
|
||||
// \return true if the entry was read
|
||||
template<class T, class Predicate>
|
||||
bool readCheck
|
||||
(
|
||||
@ -752,7 +753,7 @@ public:
|
||||
T& val,
|
||||
const Predicate& pred,
|
||||
enum keyType::option matchOpt = keyType::REGEX,
|
||||
bool mandatory = true
|
||||
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
|
||||
) const;
|
||||
|
||||
//- Find an entry if present, and assign to T val.
|
||||
@ -763,7 +764,7 @@ public:
|
||||
// \param pred the value check predicate
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
//
|
||||
// \return true if the entry was found.
|
||||
// \return true if the entry read
|
||||
template<class T, class Predicate>
|
||||
bool readCheckIfPresent
|
||||
(
|
||||
@ -773,18 +774,6 @@ public:
|
||||
enum keyType::option matchOpt = keyType::REGEX
|
||||
) const;
|
||||
|
||||
//- Check if entry is found and is a sub-dictionary.
|
||||
//
|
||||
// \param keyword the keyword to search for
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
//
|
||||
// \return true if the entry was found.
|
||||
inline 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.
|
||||
//
|
||||
@ -1120,19 +1109,6 @@ public:
|
||||
enum keyType::option matchOpt = keyType::REGEX
|
||||
) const;
|
||||
|
||||
//- Search dictionary for given keyword and any compatibility names
|
||||
//
|
||||
// \param keyword the keyword to search for
|
||||
// \param compat list of old compatibility keywords and the last
|
||||
// OpenFOAM version for which they were used.
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
bool foundCompat
|
||||
(
|
||||
const word& keyword,
|
||||
std::initializer_list<std::pair<const char*,int>> compat,
|
||||
enum keyType::option matchOpt = keyType::REGEX
|
||||
) const;
|
||||
|
||||
//- Find and return an entry pointer if present, or return a nullptr,
|
||||
//- using any compatibility names if needed.
|
||||
//
|
||||
@ -1147,6 +1123,19 @@ public:
|
||||
enum keyType::option matchOpt
|
||||
) const;
|
||||
|
||||
//- Search dictionary for given keyword and any compatibility names
|
||||
//
|
||||
// \param keyword the keyword to search for
|
||||
// \param compat list of old compatibility keywords and the last
|
||||
// OpenFOAM version for which they were used.
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
bool foundCompat
|
||||
(
|
||||
const word& keyword,
|
||||
std::initializer_list<std::pair<const char*,int>> compat,
|
||||
enum keyType::option matchOpt = keyType::REGEX
|
||||
) const;
|
||||
|
||||
//- Find and return an entry if present, otherwise FatalIOError,
|
||||
//- using any compatibility names if needed.
|
||||
//
|
||||
@ -1217,9 +1206,9 @@ public:
|
||||
// OpenFOAM version for which they were used.
|
||||
// \param val the value to read
|
||||
// \param matchOpt search mode (default: non-recursive with patterns)
|
||||
// \param mandatory the keyword is mandatory (default: true)
|
||||
// \param readOpt the entry is required/optional (default: MUST_READ)
|
||||
//
|
||||
// \return true if the entry was found.
|
||||
// \return true if the entry was read
|
||||
template<class T>
|
||||
bool readCompat
|
||||
(
|
||||
@ -1227,7 +1216,7 @@ public:
|
||||
std::initializer_list<std::pair<const char*,int>> compat,
|
||||
T& val,
|
||||
enum keyType::option matchOpt = keyType::REGEX,
|
||||
bool mandatory = true
|
||||
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
|
||||
) const;
|
||||
|
||||
//- Find an entry if present, and assign to T val
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -71,17 +71,6 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchCompat
|
||||
}
|
||||
|
||||
|
||||
bool Foam::dictionary::foundCompat
|
||||
(
|
||||
const word& keyword,
|
||||
std::initializer_list<std::pair<const char*,int>> compat,
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
return csearchCompat(keyword, compat, matchOpt).good();
|
||||
}
|
||||
|
||||
|
||||
const Foam::entry* Foam::dictionary::findCompat
|
||||
(
|
||||
const word& keyword,
|
||||
@ -93,6 +82,17 @@ const Foam::entry* Foam::dictionary::findCompat
|
||||
}
|
||||
|
||||
|
||||
bool Foam::dictionary::foundCompat
|
||||
(
|
||||
const word& keyword,
|
||||
std::initializer_list<std::pair<const char*,int>> compat,
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
return static_cast<bool>(findCompat(keyword, compat, matchOpt));
|
||||
}
|
||||
|
||||
|
||||
const Foam::entry& Foam::dictionary::lookupEntryCompat
|
||||
(
|
||||
const word& keyword,
|
||||
@ -100,9 +100,9 @@ const Foam::entry& Foam::dictionary::lookupEntryCompat
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
const const_searcher finder(csearchCompat(keyword, compat, matchOpt));
|
||||
const entry* eptr = findCompat(keyword, compat, matchOpt);
|
||||
|
||||
if (!finder.good())
|
||||
if (!eptr)
|
||||
{
|
||||
FatalIOErrorInFunction(*this)
|
||||
<< "Entry '" << keyword << "' not found in dictionary "
|
||||
@ -110,7 +110,7 @@ const Foam::entry& Foam::dictionary::lookupEntryCompat
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
return finder.ref();
|
||||
return *eptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -83,13 +83,13 @@ inline const Foam::dictionary& Foam::dictionary::parent() const noexcept
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::dictionary::found
|
||||
inline const Foam::entry* Foam::dictionary::findEntry
|
||||
(
|
||||
const word& keyword,
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
return csearch(keyword, matchOpt).good();
|
||||
return csearch(keyword, matchOpt).ptr();
|
||||
}
|
||||
|
||||
|
||||
@ -99,17 +99,17 @@ inline Foam::entry* Foam::dictionary::findEntry
|
||||
enum keyType::option matchOpt
|
||||
)
|
||||
{
|
||||
return search(keyword, matchOpt).ptr();
|
||||
return const_cast<entry*>(csearch(keyword, matchOpt).ptr());
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::entry* Foam::dictionary::findEntry
|
||||
inline bool Foam::dictionary::found
|
||||
(
|
||||
const word& keyword,
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
return csearch(keyword, matchOpt).ptr();
|
||||
return static_cast<bool>(findEntry(keyword, matchOpt));
|
||||
}
|
||||
|
||||
|
||||
@ -123,16 +123,6 @@ inline const Foam::entry* Foam::dictionary::findScoped
|
||||
}
|
||||
|
||||
|
||||
inline Foam::dictionary* Foam::dictionary::findDict
|
||||
(
|
||||
const word& keyword,
|
||||
enum keyType::option matchOpt
|
||||
)
|
||||
{
|
||||
return search(keyword, matchOpt).dictPtr();
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::dictionary* Foam::dictionary::findDict
|
||||
(
|
||||
const word& keyword,
|
||||
@ -143,13 +133,23 @@ inline const Foam::dictionary* Foam::dictionary::findDict
|
||||
}
|
||||
|
||||
|
||||
inline Foam::dictionary* Foam::dictionary::findDict
|
||||
(
|
||||
const word& keyword,
|
||||
enum keyType::option matchOpt
|
||||
)
|
||||
{
|
||||
return const_cast<dictionary*>(csearch(keyword, matchOpt).dictPtr());
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::dictionary::isDict
|
||||
(
|
||||
const word& keyword,
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
return csearch(keyword, matchOpt).isDict();
|
||||
return static_cast<bool>(findDict(keyword, matchOpt));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -151,13 +151,13 @@ T Foam::dictionary::getOrDefault
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
const const_searcher finder(csearch(keyword, matchOpt));
|
||||
const entry* eptr = csearch(keyword, matchOpt).ptr();
|
||||
|
||||
if (finder.good())
|
||||
if (eptr)
|
||||
{
|
||||
T val;
|
||||
|
||||
ITstream& is = finder.ptr()->stream();
|
||||
ITstream& is = eptr->stream();
|
||||
is >> val;
|
||||
|
||||
checkITstream(is, keyword);
|
||||
@ -181,13 +181,13 @@ T Foam::dictionary::getOrAdd
|
||||
enum keyType::option matchOpt
|
||||
)
|
||||
{
|
||||
const const_searcher finder(csearch(keyword, matchOpt));
|
||||
const entry* eptr = csearch(keyword, matchOpt).ptr();
|
||||
|
||||
if (finder.good())
|
||||
if (eptr)
|
||||
{
|
||||
T val;
|
||||
|
||||
ITstream& is = finder.ptr()->stream();
|
||||
ITstream& is = eptr->stream();
|
||||
is >> val;
|
||||
|
||||
checkITstream(is, keyword);
|
||||
@ -223,13 +223,13 @@ T Foam::dictionary::getCheckOrDefault
|
||||
}
|
||||
#endif
|
||||
|
||||
const const_searcher finder(csearch(keyword, matchOpt));
|
||||
const entry* eptr = csearch(keyword, matchOpt).ptr();
|
||||
|
||||
if (finder.good())
|
||||
if (eptr)
|
||||
{
|
||||
T val;
|
||||
|
||||
ITstream& is = finder.ptr()->stream();
|
||||
ITstream& is = eptr->stream();
|
||||
is >> val;
|
||||
|
||||
checkITstream(is, keyword);
|
||||
@ -269,13 +269,13 @@ T Foam::dictionary::getCheckOrAdd
|
||||
}
|
||||
#endif
|
||||
|
||||
const const_searcher finder(csearch(keyword, matchOpt));
|
||||
const entry* eptr = csearch(keyword, matchOpt).ptr();
|
||||
|
||||
if (finder.good())
|
||||
if (eptr)
|
||||
{
|
||||
T val;
|
||||
|
||||
ITstream& is = finder.ptr()->stream();
|
||||
ITstream& is = eptr->stream();
|
||||
is >> val;
|
||||
|
||||
checkITstream(is, keyword);
|
||||
@ -303,21 +303,26 @@ bool Foam::dictionary::readEntry
|
||||
const word& keyword,
|
||||
T& val,
|
||||
enum keyType::option matchOpt,
|
||||
bool mandatory
|
||||
IOobjectOption::readOption readOpt
|
||||
) const
|
||||
{
|
||||
const const_searcher finder(csearch(keyword, matchOpt));
|
||||
|
||||
if (finder.good())
|
||||
if (readOpt == IOobjectOption::NO_READ)
|
||||
{
|
||||
ITstream& is = finder.ptr()->stream();
|
||||
return false;
|
||||
}
|
||||
|
||||
const entry* eptr = csearch(keyword, matchOpt).ptr();
|
||||
|
||||
if (eptr)
|
||||
{
|
||||
ITstream& is = eptr->stream();
|
||||
is >> val;
|
||||
|
||||
checkITstream(is, keyword);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (mandatory)
|
||||
else if (IOobjectOption::isReadRequired(readOpt))
|
||||
{
|
||||
FatalIOErrorInFunction(*this)
|
||||
<< "Entry '" << keyword << "' not found in dictionary "
|
||||
@ -336,14 +341,19 @@ bool Foam::dictionary::readCheck
|
||||
T& val,
|
||||
const Predicate& pred,
|
||||
enum keyType::option matchOpt,
|
||||
bool mandatory
|
||||
IOobjectOption::readOption readOpt
|
||||
) const
|
||||
{
|
||||
const const_searcher finder(csearch(keyword, matchOpt));
|
||||
|
||||
if (finder.good())
|
||||
if (readOpt == IOobjectOption::NO_READ)
|
||||
{
|
||||
ITstream& is = finder.ptr()->stream();
|
||||
return false;
|
||||
}
|
||||
|
||||
const entry* eptr = csearch(keyword, matchOpt).ptr();
|
||||
|
||||
if (eptr)
|
||||
{
|
||||
ITstream& is = eptr->stream();
|
||||
is >> val;
|
||||
|
||||
checkITstream(is, keyword);
|
||||
@ -355,7 +365,7 @@ bool Foam::dictionary::readCheck
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (mandatory)
|
||||
else if (IOobjectOption::isReadRequired(readOpt))
|
||||
{
|
||||
FatalIOErrorInFunction(*this)
|
||||
<< "Entry '" << keyword << "' not found in dictionary "
|
||||
@ -374,21 +384,26 @@ bool Foam::dictionary::readCompat
|
||||
std::initializer_list<std::pair<const char*,int>> compat,
|
||||
T& val,
|
||||
enum keyType::option matchOpt,
|
||||
bool mandatory
|
||||
IOobjectOption::readOption readOpt
|
||||
) const
|
||||
{
|
||||
const const_searcher finder(csearchCompat(keyword, compat, matchOpt));
|
||||
|
||||
if (finder.good())
|
||||
if (readOpt == IOobjectOption::NO_READ)
|
||||
{
|
||||
ITstream& is = finder.ptr()->stream();
|
||||
return false;
|
||||
}
|
||||
|
||||
const entry* eptr = csearchCompat(keyword, compat, matchOpt).ptr();
|
||||
|
||||
if (eptr)
|
||||
{
|
||||
ITstream& is = eptr->stream();
|
||||
is >> val;
|
||||
|
||||
checkITstream(is, keyword);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (mandatory)
|
||||
else if (IOobjectOption::isReadRequired(readOpt))
|
||||
{
|
||||
FatalIOErrorInFunction(*this)
|
||||
<< "Entry '" << keyword << "' not found in dictionary "
|
||||
@ -408,8 +423,14 @@ bool Foam::dictionary::readIfPresent
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
// Read is non-mandatory
|
||||
return readEntry<T>(keyword, val, matchOpt, false);
|
||||
// Reading is optional
|
||||
return readEntry<T>
|
||||
(
|
||||
keyword,
|
||||
val,
|
||||
matchOpt,
|
||||
IOobjectOption::READ_IF_PRESENT
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -422,8 +443,15 @@ bool Foam::dictionary::readCheckIfPresent
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
// Read is non-mandatory
|
||||
return readCheck<T, Predicate>(keyword, val, pred, matchOpt, false);
|
||||
// Reading is optional
|
||||
return readCheck<T, Predicate>
|
||||
(
|
||||
keyword,
|
||||
val,
|
||||
pred,
|
||||
matchOpt,
|
||||
IOobjectOption::READ_IF_PRESENT
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -436,13 +464,13 @@ T Foam::dictionary::getOrDefaultCompat
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
const const_searcher finder(csearchCompat(keyword, compat, matchOpt));
|
||||
const entry* eptr = csearchCompat(keyword, compat, matchOpt).ptr();
|
||||
|
||||
if (finder.good())
|
||||
if (eptr)
|
||||
{
|
||||
T val;
|
||||
|
||||
ITstream& is = finder.ptr()->stream();
|
||||
ITstream& is = eptr->stream();
|
||||
is >> val;
|
||||
|
||||
checkITstream(is, keyword);
|
||||
@ -467,8 +495,15 @@ bool Foam::dictionary::readIfPresentCompat
|
||||
enum keyType::option matchOpt
|
||||
) const
|
||||
{
|
||||
// Read is non-mandatory
|
||||
return readCompat<T>(keyword, compat, val, matchOpt, false);
|
||||
// Reading is optional
|
||||
return readCompat<T>
|
||||
(
|
||||
keyword,
|
||||
compat,
|
||||
val,
|
||||
matchOpt,
|
||||
IOobjectOption::READ_IF_PRESENT
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -74,10 +74,10 @@ bool Foam::expressions::exprString::readEntry
|
||||
(
|
||||
const word& keyword,
|
||||
const dictionary& dict,
|
||||
bool mandatory
|
||||
IOobjectOption::readOption readOpt
|
||||
)
|
||||
{
|
||||
const bool ok = dict.readEntry(keyword, *this, keyType::LITERAL, mandatory);
|
||||
const bool ok = dict.readEntry(keyword, *this, keyType::LITERAL, readOpt);
|
||||
|
||||
if (ok && !empty())
|
||||
{
|
||||
|
||||
@ -175,7 +175,7 @@ public:
|
||||
(
|
||||
const word& keyword, //!< Lookup key. Uses LITERAL (not REGEX)
|
||||
const dictionary& dict,
|
||||
bool mandatory = true
|
||||
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
|
||||
);
|
||||
|
||||
//- Read/expand optional entry with dictionary variables,
|
||||
|
||||
@ -195,7 +195,7 @@ inline bool Foam::expressions::exprString::readIfPresent
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
return readEntry(key, dict, false); // non-mandatory
|
||||
return readEntry(key, dict, IOobjectOption::READ_IF_PRESENT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1373,12 +1373,17 @@ void Foam::argList::parse
|
||||
|
||||
if (dictStream && dictStream->good())
|
||||
{
|
||||
// Get numberOfSubdomains if it exists.
|
||||
// - mandatory when running with distributed roots
|
||||
|
||||
IOobjectOption::readOption nDomainsReadOpt
|
||||
= IOobjectOption::READ_IF_PRESENT;
|
||||
|
||||
dictionary decompDict(*dictStream);
|
||||
bool nDomainsMandatory = false;
|
||||
|
||||
if (decompDict.getOrDefault("distributed", false))
|
||||
{
|
||||
nDomainsMandatory = true;
|
||||
nDomainsReadOpt = IOobjectOption::MUST_READ;
|
||||
runControl_.distributed(true);
|
||||
decompDict.readEntry("roots", roots);
|
||||
|
||||
@ -1390,14 +1395,12 @@ void Foam::argList::parse
|
||||
}
|
||||
}
|
||||
|
||||
// Get numberOfSubdomains if it exists.
|
||||
// - mandatory when running with distributed roots
|
||||
decompDict.readEntry
|
||||
(
|
||||
"numberOfSubdomains",
|
||||
dictNProcs,
|
||||
keyType::LITERAL,
|
||||
nDomainsMandatory
|
||||
nDomainsReadOpt
|
||||
);
|
||||
}
|
||||
else
|
||||
|
||||
@ -54,12 +54,16 @@ Foam::Function1<Type>::New
|
||||
<< "For " << entryName << " with dictionary entries: "
|
||||
<< flatOutput(coeffs->toc()) << nl;
|
||||
|
||||
// The "type" entry - mandatory if no redirectType provided
|
||||
coeffs->readEntry
|
||||
(
|
||||
"type",
|
||||
modelType,
|
||||
keyType::LITERAL,
|
||||
modelType.empty() // "type" entry is mandatory if no 'redirect'
|
||||
(
|
||||
modelType.empty()
|
||||
? IOobjectOption::MUST_READ : IOobjectOption::READ_IF_PRESENT
|
||||
)
|
||||
);
|
||||
|
||||
// Fallthrough
|
||||
|
||||
@ -300,18 +300,16 @@ Type Foam::motionSmootherAlgo::get
|
||||
const Type& defaultValue
|
||||
)
|
||||
{
|
||||
// If noExit, emit FatalIOError message without exiting
|
||||
IOobjectOption::readOption readOpt
|
||||
(
|
||||
noExit
|
||||
? IOobjectOption::READ_IF_PRESENT : IOobjectOption::MUST_READ
|
||||
);
|
||||
|
||||
Type val(defaultValue);
|
||||
|
||||
if
|
||||
(
|
||||
!dict.readEntry
|
||||
(
|
||||
keyword,
|
||||
val,
|
||||
matchOpt,
|
||||
!noExit
|
||||
)
|
||||
)
|
||||
if (!dict.readEntry(keyword, val, matchOpt, readOpt))
|
||||
{
|
||||
FatalIOError
|
||||
<< "Entry '" << keyword << "' not found in dictionary "
|
||||
|
||||
@ -62,12 +62,17 @@ Foam::patchDistMethod::New
|
||||
)
|
||||
{
|
||||
word modelType(defaultPatchDistMethod);
|
||||
|
||||
// The "method" entry - mandatory if no default was provided
|
||||
dict.readEntry
|
||||
(
|
||||
"method",
|
||||
modelType,
|
||||
keyType::REGEX,
|
||||
modelType.empty() // Mandatory if no default was provided
|
||||
keyType::LITERAL,
|
||||
(
|
||||
modelType.empty()
|
||||
? IOobjectOption::MUST_READ : IOobjectOption::READ_IF_PRESENT
|
||||
)
|
||||
);
|
||||
|
||||
Info<< "Selecting patchDistMethod " << modelType << endl;
|
||||
|
||||
@ -1038,13 +1038,17 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
|
||||
}
|
||||
}
|
||||
|
||||
// Mandatory if we didn't pick up a value from selectionNames_
|
||||
// The "name" entry
|
||||
// - mandatory if we didn't pick up a value from selectionNames_
|
||||
dict.readEntry
|
||||
(
|
||||
"name",
|
||||
regionName_,
|
||||
keyType::LITERAL,
|
||||
regionName_.empty()
|
||||
(
|
||||
regionName_.empty()
|
||||
? IOobjectOption::MUST_READ : IOobjectOption::READ_IF_PRESENT
|
||||
)
|
||||
);
|
||||
|
||||
// Ensure there is always content for selectionNames_
|
||||
|
||||
@ -148,26 +148,15 @@ void Foam::medialAxisMeshMover::update(const dictionary& coeffDict)
|
||||
)
|
||||
);
|
||||
|
||||
// Note: parameter name changed
|
||||
// "minMedianAxisAngle" -> "minMedialAxisAngle" (DEC-2013)
|
||||
// but not previously reported.
|
||||
scalar minMedialAxisAngle(Zero);
|
||||
if
|
||||
const scalar minMedialAxisAngle
|
||||
(
|
||||
!coeffDict.readCompat
|
||||
meshRefinement::get<scalar>
|
||||
(
|
||||
coeffDict,
|
||||
"minMedialAxisAngle",
|
||||
{{ "minMedianAxisAngle", 1712 }},
|
||||
minMedialAxisAngle,
|
||||
keyType::REGEX,
|
||||
!dryRun_
|
||||
dryRun_
|
||||
)
|
||||
)
|
||||
{
|
||||
FatalIOError
|
||||
<< "Entry '" << "minMedialAxisAngle"
|
||||
<< "' not found in dictionary " << coeffDict.name() << endl;
|
||||
}
|
||||
);
|
||||
|
||||
const scalar minMedialAxisAngleCos(Foam::cos(degToRad(minMedialAxisAngle)));
|
||||
|
||||
|
||||
@ -3803,7 +3803,7 @@ const Foam::dictionary& Foam::meshRefinement::subDict
|
||||
auto& err = FatalIOErrorInFunction(dict);
|
||||
|
||||
err << "Entry '" << keyword << "' not found in dictionary "
|
||||
<< dict.name() << nl;
|
||||
<< dict.relativeName() << nl;
|
||||
|
||||
if (noExit)
|
||||
{
|
||||
@ -3827,14 +3827,14 @@ Foam::ITstream& Foam::meshRefinement::lookup
|
||||
enum keyType::option matchOpt
|
||||
)
|
||||
{
|
||||
const auto finder(dict.csearch(keyword, matchOpt));
|
||||
const entry* eptr = dict.findEntry(keyword, matchOpt);
|
||||
|
||||
if (!finder.good())
|
||||
if (!eptr)
|
||||
{
|
||||
auto& err = FatalIOErrorInFunction(dict);
|
||||
|
||||
err << "Entry '" << keyword << "' not found in dictionary "
|
||||
<< dict.name() << nl;
|
||||
<< dict.relativeName() << nl;
|
||||
|
||||
if (noExit)
|
||||
{
|
||||
@ -3847,7 +3847,7 @@ Foam::ITstream& Foam::meshRefinement::lookup
|
||||
}
|
||||
}
|
||||
|
||||
return finder.ref().stream();
|
||||
return eptr->stream();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -335,9 +335,16 @@ Type Foam::meshRefinement::get
|
||||
const Type& deflt
|
||||
)
|
||||
{
|
||||
// If noExit, emit FatalIOError message without exiting
|
||||
IOobjectOption::readOption readOpt
|
||||
(
|
||||
noExit
|
||||
? IOobjectOption::READ_IF_PRESENT : IOobjectOption::MUST_READ
|
||||
);
|
||||
|
||||
Type val(deflt);
|
||||
|
||||
if (!dict.readEntry(keyword, val, matchOpt, !noExit))
|
||||
if (!dict.readEntry(keyword, val, matchOpt, readOpt))
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Entry '" << keyword << "' not found in dictionary "
|
||||
|
||||
@ -53,12 +53,13 @@ Foam::PatchFunction1<Type>::New
|
||||
<< "For " << entryName << " with dictionary entries: "
|
||||
<< flatOutput(coeffs->toc()) << nl;
|
||||
|
||||
// The "type" entry - mandatory, no fallback type provided
|
||||
coeffs->readEntry
|
||||
(
|
||||
"type",
|
||||
modelType,
|
||||
keyType::LITERAL
|
||||
// "type" entry is mandatory, there is no 'redirect'
|
||||
keyType::LITERAL,
|
||||
IOobjectOption::MUST_READ
|
||||
);
|
||||
}
|
||||
else if (eptr)
|
||||
|
||||
@ -59,13 +59,17 @@ namespace Foam
|
||||
// Read min/max or min/span
|
||||
static void readBoxDim(const dictionary& dict, treeBoundBox& bb)
|
||||
{
|
||||
dict.readEntry<point>("min", bb.min());
|
||||
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ;
|
||||
|
||||
const bool hasSpan = dict.found("span");
|
||||
if (!dict.readEntry<point>("max", bb.max(), keyType::REGEX, !hasSpan))
|
||||
dict.readEntry("min", bb.min(), keyType::LITERAL, readOpt);
|
||||
|
||||
if (dict.readIfPresent("span", bb.max(), keyType::LITERAL))
|
||||
{
|
||||
bb.max() = bb.min() + dict.get<vector>("span");
|
||||
bb.max() += bb.min();
|
||||
readOpt = IOobjectOption::READ_IF_PRESENT;
|
||||
}
|
||||
|
||||
dict.readEntry("max", bb.max(), keyType::LITERAL, readOpt);
|
||||
}
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -72,13 +72,17 @@ namespace Foam
|
||||
// Read min/max or min/span
|
||||
static void readBoxDim(const dictionary& dict, treeBoundBox& bb)
|
||||
{
|
||||
dict.readEntry<point>("min", bb.min());
|
||||
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ;
|
||||
|
||||
const bool hasSpan = dict.found("span");
|
||||
if (!dict.readEntry<point>("max", bb.max(), keyType::REGEX, !hasSpan))
|
||||
dict.readEntry("min", bb.min(), keyType::LITERAL, readOpt);
|
||||
|
||||
if (dict.readIfPresent("span", bb.max(), keyType::LITERAL))
|
||||
{
|
||||
bb.max() = bb.min() + dict.get<vector>("span");
|
||||
bb.max() += bb.min();
|
||||
readOpt = IOobjectOption::READ_IF_PRESENT;
|
||||
}
|
||||
|
||||
dict.readEntry("max", bb.max(), keyType::LITERAL, readOpt);
|
||||
}
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -72,13 +72,17 @@ namespace Foam
|
||||
// Read min/max or min/span
|
||||
static void readBoxDim(const dictionary& dict, treeBoundBox& bb)
|
||||
{
|
||||
dict.readEntry<point>("min", bb.min());
|
||||
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ;
|
||||
|
||||
const bool hasSpan = dict.found("span");
|
||||
if (!dict.readEntry<point>("max", bb.max(), keyType::REGEX, !hasSpan))
|
||||
dict.readEntry("min", bb.min(), keyType::LITERAL, readOpt);
|
||||
|
||||
if (dict.readIfPresent("span", bb.max(), keyType::LITERAL))
|
||||
{
|
||||
bb.max() = bb.min() + dict.get<vector>("span");
|
||||
bb.max() += bb.min();
|
||||
readOpt = IOobjectOption::READ_IF_PRESENT;
|
||||
}
|
||||
|
||||
dict.readEntry("max", bb.max(), keyType::LITERAL, readOpt);
|
||||
}
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -72,13 +72,17 @@ namespace Foam
|
||||
// Read min/max or min/span
|
||||
static void readBoxDim(const dictionary& dict, treeBoundBox& bb)
|
||||
{
|
||||
dict.readEntry<point>("min", bb.min());
|
||||
IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ;
|
||||
|
||||
const bool hasSpan = dict.found("span");
|
||||
if (!dict.readEntry<point>("max", bb.max(), keyType::REGEX, !hasSpan))
|
||||
dict.readEntry("min", bb.min(), keyType::LITERAL, readOpt);
|
||||
|
||||
if (dict.readIfPresent("span", bb.max(), keyType::LITERAL))
|
||||
{
|
||||
bb.max() = bb.min() + dict.get<vector>("span");
|
||||
bb.max() += bb.min();
|
||||
readOpt = IOobjectOption::READ_IF_PRESENT;
|
||||
}
|
||||
|
||||
dict.readEntry("max", bb.max(), keyType::LITERAL, readOpt);
|
||||
}
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
Reference in New Issue
Block a user