dictionary: Added lookupType function for convenient lookup and setting of value

of the specified type
This commit is contained in:
Henry Weller
2017-03-16 20:50:11 +00:00
parent 2c31e665ba
commit 19e602b065
2 changed files with 38 additions and 2 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -334,7 +334,19 @@ public:
) const;
//- Find and return a T,
// if not found return the given default value
// if not found throw a fatal error.
// If recursive, search parent dictionaries.
// If patternMatch, use regular expressions.
template<class T>
T lookupType
(
const word&,
bool recursive=false,
bool patternMatch=true
) const;
//- Find and return a T,
// if not found return the given default value.
// If recursive, search parent dictionaries.
// If patternMatch, use regular expressions.
template<class T>

View File

@ -28,6 +28,30 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
T Foam::dictionary::lookupType
(
const word& keyword,
bool recursive,
bool patternMatch
) const
{
const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
if (entryPtr == nullptr)
{
FatalIOErrorInFunction
(
*this
) << "keyword " << keyword << " is undefined in dictionary "
<< name()
<< exit(FatalIOError);
}
return pTraits<T>(entryPtr->stream());
}
template<class T>
T Foam::dictionary::lookupOrDefault
(