Commit 19e602b0 authored by Henry Weller's avatar Henry Weller
Browse files

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

of the specified type
parent 2c31e665
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -334,7 +334,19 @@ public: ...@@ -334,7 +334,19 @@ public:
) const; ) const;
//- Find and return a T, //- 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 recursive, search parent dictionaries.
// If patternMatch, use regular expressions. // If patternMatch, use regular expressions.
template<class T> template<class T>
......
...@@ -28,6 +28,30 @@ License ...@@ -28,6 +28,30 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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> template<class T>
T Foam::dictionary::lookupOrDefault T Foam::dictionary::lookupOrDefault
( (
......
Markdown is supported
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