FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

dictionaryTemplates.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "dictionary.H"
00027 #include <OpenFOAM/primitiveEntry.H>
00028 
00029 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00030 
00031 template<class T>
00032 T Foam::dictionary::lookupOrDefault
00033 (
00034     const word& keyword,
00035     const T& deflt,
00036     bool recursive,
00037     bool patternMatch
00038 ) const
00039 {
00040     const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
00041 
00042     if (entryPtr)
00043     {
00044         return pTraits<T>(entryPtr->stream());
00045     }
00046     else
00047     {
00048         return deflt;
00049     }
00050 }
00051 
00052 
00053 template<class T>
00054 T Foam::dictionary::lookupOrAddDefault
00055 (
00056     const word& keyword,
00057     const T& deflt,
00058     bool recursive,
00059     bool patternMatch
00060 )
00061 {
00062     const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
00063 
00064     if (entryPtr)
00065     {
00066         return pTraits<T>(entryPtr->stream());
00067     }
00068     else
00069     {
00070         add(new primitiveEntry(keyword, deflt));
00071         return deflt;
00072     }
00073 }
00074 
00075 
00076 template<class T>
00077 bool Foam::dictionary::readIfPresent
00078 (
00079     const word& k,
00080     T& val,
00081     bool recursive,
00082     bool patternMatch
00083 ) const
00084 {
00085     const entry* entryPtr = lookupEntryPtr(k, recursive, patternMatch);
00086 
00087     if (entryPtr)
00088     {
00089         entryPtr->stream() >> val;
00090         return true;
00091     }
00092     else
00093     {
00094         return false;
00095     }
00096 }
00097 
00098 
00099 template<class T>
00100 void Foam::dictionary::add(const keyType& k, const T& t, bool overwrite)
00101 {
00102     add(new primitiveEntry(k, t), overwrite);
00103 }
00104 
00105 
00106 template<class T>
00107 void Foam::dictionary::set(const keyType& k, const T& t)
00108 {
00109     set(new primitiveEntry(k, t));
00110 }
00111 
00112 #if __GNUC__ == 4 && __GNUC_MINOR__ < 4
00113 // gcc < 4.4 doesn't seem to find Switch::operator bool().
00114 #include <OpenFOAM/Switch.H>
00115 namespace Foam {
00116 template<>
00117 inline Switch dictionary::lookupOrDefault<Switch>
00118 (
00119     const word& keyword,
00120     const Switch& deflt,
00121     bool recursive,
00122     bool patternMatch
00123 ) const
00124 {
00125     const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
00126 
00127     if (entryPtr)
00128     {
00129         return Switch(entryPtr->stream());
00130     }
00131     else
00132     {
00133         return deflt;
00134     }
00135 }
00136 
00137 template<>
00138 inline
00139 Switch Foam::dictionary::lookupOrAddDefault<Switch>
00140 (
00141     const word& keyword,
00142     const Switch& deflt,
00143     bool recursive,
00144     bool patternMatch
00145 )
00146 {
00147     const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
00148 
00149     if (entryPtr)
00150     {
00151         return Switch(entryPtr->stream());
00152     }
00153     else
00154     {
00155         add(new primitiveEntry(keyword, deflt));
00156         return deflt;
00157     }
00158 }
00159 }
00160 #endif
00161 
00162 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines