Commit 349ddc5f authored by Andrew Heather's avatar Andrew Heather
Browse files

added lookupOrAddDefault and readIfPresent functions

parent 4fc2fe65
......@@ -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)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment