STYLE: minor simplification of coding in dictionary

This commit is contained in:
Mark Olesen
2017-03-06 18:32:48 +01:00
parent f05be160e2
commit c6bcd65dfd

View File

@ -60,52 +60,51 @@ const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr
// Non-scoped lookup // Non-scoped lookup
return lookupEntryPtr(keyword, recursive, patternMatch); return lookupEntryPtr(keyword, recursive, patternMatch);
} }
else else if (dotPos == 0)
{ {
if (dotPos == 0) // Starting with a '.' -> go up for every further '.' found
{ ++dotPos;
// Starting with a '.'. Go up for every 2nd '.' found
const dictionary* dictPtr = this; const dictionary* dictPtr = this;
for
string::size_type begVar = dotPos + 1; (
string::const_iterator iter = keyword.begin() + begVar; string::const_iterator it = keyword.begin()+1;
string::size_type endVar = begVar; it != keyword.end() && *it == '.';
while (iter != keyword.end() && *iter == '.') ++dotPos, ++it
)
{ {
++iter;
++endVar;
// Go to parent // Go to parent
if (&dictPtr->parent_ == &dictionary::null) if (&dictPtr->parent_ != &dictionary::null)
{
dictPtr = &dictPtr->parent_;
}
else
{ {
FatalIOErrorInFunction FatalIOErrorInFunction
( (
*this *this
) << "No parent of current dictionary" ) << "No parent of current dictionary when searching for "
<< " when searching for " << keyword.substr(1)
<< keyword.substr(begVar, keyword.size()-begVar)
<< exit(FatalIOError); << exit(FatalIOError);
return nullptr;
} }
dictPtr = &dictPtr->parent_;
} }
return dictPtr->lookupScopedSubEntryPtr return dictPtr->lookupScopedSubEntryPtr
( (
keyword.substr(endVar), keyword.substr(dotPos),
false, false,
patternMatch patternMatch
); );
} }
else else
{ {
// Extract the first word // The first word
const word firstWord = keyword.substr(0, dotPos);
const entry* entPtr = lookupScopedSubEntryPtr const entry* entPtr = lookupScopedSubEntryPtr
( (
firstWord, keyword.substr(0, dotPos),
false, //recursive false,
patternMatch patternMatch
); );
@ -115,41 +114,32 @@ const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr
// a.b.c.d it would try // a.b.c.d it would try
// a.b, a.b.c, a.b.c.d // a.b, a.b.c, a.b.c.d
string::size_type nextDotPos = keyword.find
(
'.',
dotPos+1
);
while (true) while (true)
{ {
const entry* subEntPtr = lookupEntryPtr dotPos = keyword.find('.', dotPos+1);
entPtr = lookupEntryPtr
( (
keyword.substr(0, nextDotPos), keyword.substr(0, dotPos),
false, false,
patternMatch patternMatch
); );
if (nextDotPos == string::npos)
if (dotPos == string::npos)
{ {
// Parsed the whole word. Return entry or null. // Parsed the whole word. Return entry or null.
return subEntPtr; return entPtr;
} }
if (subEntPtr && subEntPtr->isDict()) if (entPtr && entPtr->isDict())
{ {
return subEntPtr->dict().lookupScopedSubEntryPtr return entPtr->dict().lookupScopedSubEntryPtr
( (
keyword.substr keyword.substr(dotPos),
(
nextDotPos,
keyword.size()-nextDotPos
),
false, false,
patternMatch patternMatch
); );
} }
nextDotPos = keyword.find('.', nextDotPos+1);
} }
} }
@ -157,18 +147,15 @@ const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr
{ {
return entPtr->dict().lookupScopedSubEntryPtr return entPtr->dict().lookupScopedSubEntryPtr
( (
keyword.substr(dotPos, keyword.size()-dotPos), keyword.substr(dotPos),
false, false,
patternMatch patternMatch
); );
} }
else }
{
return nullptr; return nullptr;
} }
}
}
}
bool Foam::dictionary::findInPatterns bool Foam::dictionary::findInPatterns
@ -597,10 +584,9 @@ const Foam::entry* Foam::dictionary::lookupScopedEntryPtr
dictPtr = &dictPtr->parent_; dictPtr = &dictPtr->parent_;
} }
// At top. Recurse to find entries
return dictPtr->lookupScopedSubEntryPtr return dictPtr->lookupScopedSubEntryPtr
( (
keyword.substr(1, keyword.size()-1), keyword.substr(1),
false, false,
patternMatch patternMatch
); );
@ -1038,7 +1024,6 @@ bool Foam::dictionary::changeKeyword
IDLList<entry>::replace(iter2(), iter()); IDLList<entry>::replace(iter2(), iter());
delete iter2(); delete iter2();
hashedEntries_.erase(iter2); hashedEntries_.erase(iter2);
} }
else else
{ {