Skip to content
Snippets Groups Projects
Commit dfc4c690 authored by Mark Olesen's avatar Mark Olesen
Browse files

dictionary class : spelling and have bool return for readIfPresent

parent 84898c6c
No related merge requests found
......@@ -30,9 +30,9 @@ Description
of values (e.g. words and numbers).
The dictionary class is the base class for IOdictionary.
It serves the purpose of a bootstrap dictionary for the objectRegistry
data dictionaries, since unlike the IOdictionary class, it does not use
a objectRegistry itself to work.
It also serves as a bootstrap dictionary for the objectRegistry data
dictionaries since, unlike the IOdictionary class, it does not use an
objectRegistry itself to work.
ToDo
A merge() member function with a non-const dictionary parameter.
......@@ -199,25 +199,31 @@ public:
//- Find and return a T, if not found return the given default value
// If recursive search parent dictionaries
template<class T>
T lookupOrDefault(const word&, const T&, bool recursive=false) const;
T lookupOrDefault
(
const word&,
const T&,
bool recursive=false
) const;
//- Find and return a T, if not found return the given default value,
// and add to dictionary. If recusive search parent dictionaries
// and add to dictionary. If recursive search parent dictionaries
template<class T>
T lookupOrAddDefault
(
const word&,
const T&,
bool recusive=false
bool recursive=false
);
//- Find an entry if present, and assign to T
// Returns true if the entry was found
template<class T>
void readIfPresent
bool readIfPresent
(
const word&,
T&,
bool recusive=false
bool recursive=false
) const;
//- Check if entry is a sub-dictionary
......
......@@ -54,40 +54,42 @@ template<class T>
T Foam::dictionary::lookupOrAddDefault
(
const word& keyword,
const T& deft,
bool recusive
const T& deflt,
bool recursive
)
{
const entry* ePtr = lookupEntryPtr(keyword, recusive);
const entry* entryPtr = lookupEntryPtr(keyword, recursive);
if (ePtr == NULL)
if (entryPtr == NULL)
{
entry* defPtr = new primitiveEntry(keyword, deft);
append(defPtr);
hashedEntries_.insert(defPtr->keyword(), defPtr);
return deft;
add(new primitiveEntry(keyword, deflt));
return deflt;
}
else
{
return pTraits<T>(ePtr->stream());
return pTraits<T>(entryPtr->stream());
}
}
template<class T>
void Foam::dictionary::readIfPresent
bool Foam::dictionary::readIfPresent
(
const word& keyword,
T& deft,
bool recusive
const word& k,
T& val,
bool recursive
) const
{
const entry* ePtr = lookupEntryPtr(keyword, recusive);
const entry* entryPtr = lookupEntryPtr(k, recursive);
if (ePtr != NULL)
if (entryPtr == NULL)
{
return false;
}
else
{
ePtr->stream() >> deft;
entryPtr->stream() >> val;
return true;
}
}
......
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