mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: expose null constructible dictionary searcher
This commit is contained in:
@ -271,7 +271,7 @@ const Foam::entry& Foam::dictionary::lookupEntry
|
|||||||
bool patternMatch
|
bool patternMatch
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
auto finder = csearch(keyword, recursive, patternMatch);
|
const const_searcher finder(csearch(keyword, recursive, patternMatch));
|
||||||
|
|
||||||
if (!finder.found())
|
if (!finder.found())
|
||||||
{
|
{
|
||||||
@ -320,7 +320,7 @@ bool Foam::dictionary::substituteKeyword(const word& keyword, bool mergeEntry)
|
|||||||
const word varName(keyword.substr(1), false);
|
const word varName(keyword.substr(1), false);
|
||||||
|
|
||||||
// Lookup the variable name in the given dictionary
|
// Lookup the variable name in the given dictionary
|
||||||
const_searcher finder = csearch(varName, true, true);
|
const const_searcher finder(csearch(varName, true, true));
|
||||||
|
|
||||||
// If defined insert its entries into this dictionary
|
// If defined insert its entries into this dictionary
|
||||||
if (finder.found())
|
if (finder.found())
|
||||||
@ -354,7 +354,7 @@ bool Foam::dictionary::substituteScopedKeyword
|
|||||||
const word varName(keyword.substr(1), false);
|
const word varName(keyword.substr(1), false);
|
||||||
|
|
||||||
// Lookup the variable name in the given dictionary
|
// Lookup the variable name in the given dictionary
|
||||||
const_searcher finder = csearchScoped(varName, true, true);
|
const const_searcher finder(csearchScoped(varName, true, true));
|
||||||
|
|
||||||
// If defined insert its entries into this dictionary
|
// If defined insert its entries into this dictionary
|
||||||
if (finder.found())
|
if (finder.found())
|
||||||
@ -397,7 +397,7 @@ Foam::dictionary* Foam::dictionary::subDictPtr(const word& keyword)
|
|||||||
const Foam::dictionary& Foam::dictionary::subDict(const word& keyword) const
|
const Foam::dictionary& Foam::dictionary::subDict(const word& keyword) const
|
||||||
{
|
{
|
||||||
// Find non-recursive with patterns
|
// Find non-recursive with patterns
|
||||||
auto finder = csearch(keyword, false, true);
|
const const_searcher finder(csearch(keyword, false, true));
|
||||||
|
|
||||||
if (!finder.found())
|
if (!finder.found())
|
||||||
{
|
{
|
||||||
@ -416,7 +416,7 @@ 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)
|
||||||
{
|
{
|
||||||
// Find non-recursive with patterns
|
// Find non-recursive with patterns
|
||||||
auto finder = search(keyword, false, true);
|
searcher finder = search(keyword, false, true);
|
||||||
|
|
||||||
if (!finder.found())
|
if (!finder.found())
|
||||||
{
|
{
|
||||||
@ -439,7 +439,7 @@ Foam::dictionary Foam::dictionary::subOrEmptyDict
|
|||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// Find non-recursive with patterns
|
// Find non-recursive with patterns
|
||||||
auto finder = csearch(keyword, false, true);
|
const const_searcher finder(csearch(keyword, false, true));
|
||||||
|
|
||||||
if (finder.isDict())
|
if (finder.isDict())
|
||||||
{
|
{
|
||||||
@ -475,7 +475,7 @@ const Foam::dictionary& Foam::dictionary::optionalSubDict
|
|||||||
const word& keyword
|
const word& keyword
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
auto finder = csearch(keyword, false, true);
|
const const_searcher finder(csearch(keyword, false, true));
|
||||||
|
|
||||||
if (finder.isDict())
|
if (finder.isDict())
|
||||||
{
|
{
|
||||||
@ -535,6 +535,11 @@ Foam::List<Foam::keyType> Foam::dictionary::keys(bool patterns) const
|
|||||||
|
|
||||||
bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
|
bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
|
||||||
{
|
{
|
||||||
|
if (!entryPtr)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
auto iter = hashedEntries_.find(entryPtr->keyword());
|
auto iter = hashedEntries_.find(entryPtr->keyword());
|
||||||
|
|
||||||
if (mergeEntry && iter.found())
|
if (mergeEntry && iter.found())
|
||||||
@ -543,8 +548,8 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
|
|||||||
if (iter()->isDict() && entryPtr->isDict())
|
if (iter()->isDict() && entryPtr->isDict())
|
||||||
{
|
{
|
||||||
iter()->dict().merge(entryPtr->dict());
|
iter()->dict().merge(entryPtr->dict());
|
||||||
delete entryPtr;
|
|
||||||
|
|
||||||
|
delete entryPtr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,6 +581,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
|
|||||||
<< " in dictionary " << name() << endl;
|
<< " in dictionary " << name() << endl;
|
||||||
|
|
||||||
parent_type::remove(entryPtr);
|
parent_type::remove(entryPtr);
|
||||||
|
|
||||||
delete entryPtr;
|
delete entryPtr;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -657,8 +663,13 @@ void Foam::dictionary::add
|
|||||||
|
|
||||||
void Foam::dictionary::set(entry* entryPtr)
|
void Foam::dictionary::set(entry* entryPtr)
|
||||||
{
|
{
|
||||||
|
if (!entryPtr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Find non-recursive with patterns
|
// Find non-recursive with patterns
|
||||||
auto finder = search(entryPtr->keyword(), false, true);
|
searcher finder(search(entryPtr->keyword(), false, true));
|
||||||
|
|
||||||
// Clear dictionary so merge acts like overwrite
|
// Clear dictionary so merge acts like overwrite
|
||||||
if (finder.isDict())
|
if (finder.isDict())
|
||||||
|
|||||||
@ -222,13 +222,6 @@ public:
|
|||||||
pointer eptr_;
|
pointer eptr_;
|
||||||
|
|
||||||
|
|
||||||
//- Construct null
|
|
||||||
Searcher()
|
|
||||||
:
|
|
||||||
dict_(nullptr),
|
|
||||||
eptr_(nullptr)
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Construct for the given dictionary context
|
//- Construct for the given dictionary context
|
||||||
Searcher(dict_pointer dict)
|
Searcher(dict_pointer dict)
|
||||||
:
|
:
|
||||||
@ -245,6 +238,14 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//- Construct null
|
||||||
|
Searcher()
|
||||||
|
:
|
||||||
|
dict_(nullptr),
|
||||||
|
eptr_(nullptr)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
//- Entry was found.
|
//- Entry was found.
|
||||||
inline bool found() const
|
inline bool found() const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -587,6 +587,7 @@ Foam::dictionary* Foam::dictionary::makeScopedDictPtr(const fileName& dictPath)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Note: a failed add() deletes the eptr passed
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user