added lookupOrAddDefault and readIfPresent functions
This commit is contained in:
parent
4fc2fe6596
commit
349ddc5f59
@ -197,6 +197,25 @@ public:
|
||||
template<class T>
|
||||
T lookupOrDefault(const word&, const T&, bool recusive=false) const;
|
||||
|
||||
//- Find and return a T, if not found return the given default value,
|
||||
// and add to dictionary. If recusive search parent dictionaries
|
||||
template<class T>
|
||||
T lookupOrAddDefault
|
||||
(
|
||||
const word&,
|
||||
const T&,
|
||||
bool recusive=false
|
||||
);
|
||||
|
||||
//- Find an entry if present, and assign to T
|
||||
template<class T>
|
||||
void readIfPresent
|
||||
(
|
||||
const word&,
|
||||
T&,
|
||||
bool recusive=false
|
||||
) const;
|
||||
|
||||
//- Check if entry is a sub-dictionary
|
||||
bool isDict(const word&) const;
|
||||
|
||||
|
@ -50,6 +50,48 @@ T Foam::dictionary::lookupOrDefault
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
T Foam::dictionary::lookupOrAddDefault
|
||||
(
|
||||
const word& keyword,
|
||||
const T& deft,
|
||||
bool recusive
|
||||
)
|
||||
{
|
||||
const entry* ePtr = lookupEntryPtr(keyword, recusive);
|
||||
|
||||
if (ePtr == NULL)
|
||||
{
|
||||
entry* defPtr = new primitiveEntry(keyword, deft);
|
||||
append(defPtr);
|
||||
hashedEntries_.insert(defPtr->keyword(), defPtr);
|
||||
|
||||
return deft;
|
||||
}
|
||||
else
|
||||
{
|
||||
return pTraits<T>(ePtr->stream());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::dictionary::readIfPresent
|
||||
(
|
||||
const word& keyword,
|
||||
T& deft,
|
||||
bool recusive
|
||||
) const
|
||||
{
|
||||
const entry* ePtr = lookupEntryPtr(keyword, recusive);
|
||||
|
||||
if (ePtr != NULL)
|
||||
{
|
||||
ePtr->stream() >> deft;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::dictionary::add(const word& keyword, const T& t)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user