mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
added lookupOrAddDefault and readIfPresent functions
This commit is contained in:
@ -197,6 +197,25 @@ public:
|
|||||||
template<class T>
|
template<class T>
|
||||||
T lookupOrDefault(const word&, const T&, bool recusive=false) const;
|
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
|
//- Check if entry is a sub-dictionary
|
||||||
bool isDict(const word&) const;
|
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>
|
template<class T>
|
||||||
void Foam::dictionary::add(const word& keyword, const T& t)
|
void Foam::dictionary::add(const word& keyword, const T& t)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user