diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index d42a934ad2..95339b4835 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -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 + 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 diff --git a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C index 5d2164e52b..232633dc7a 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C +++ b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C @@ -28,6 +28,30 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +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(entryPtr->stream()); +} + + template T Foam::dictionary::lookupOrDefault (