FreeFOAM The Cross-Platform CFD Toolkit
dictionaryTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "dictionary.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class T>
33 (
34  const word& keyword,
35  const T& deflt,
36  bool recursive,
37  bool patternMatch
38 ) const
39 {
40  const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
41 
42  if (entryPtr)
43  {
44  return pTraits<T>(entryPtr->stream());
45  }
46  else
47  {
48  return deflt;
49  }
50 }
51 
52 
53 template<class T>
55 (
56  const word& keyword,
57  const T& deflt,
58  bool recursive,
59  bool patternMatch
60 )
61 {
62  const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
63 
64  if (entryPtr)
65  {
66  return pTraits<T>(entryPtr->stream());
67  }
68  else
69  {
70  add(new primitiveEntry(keyword, deflt));
71  return deflt;
72  }
73 }
74 
75 
76 template<class T>
78 (
79  const word& k,
80  T& val,
81  bool recursive,
82  bool patternMatch
83 ) const
84 {
85  const entry* entryPtr = lookupEntryPtr(k, recursive, patternMatch);
86 
87  if (entryPtr)
88  {
89  entryPtr->stream() >> val;
90  return true;
91  }
92  else
93  {
94  return false;
95  }
96 }
97 
98 
99 template<class T>
100 void Foam::dictionary::add(const keyType& k, const T& t, bool overwrite)
101 {
102  add(new primitiveEntry(k, t), overwrite);
103 }
104 
105 
106 template<class T>
107 void Foam::dictionary::set(const keyType& k, const T& t)
108 {
109  set(new primitiveEntry(k, t));
110 }
111 
112 #if __GNUC__ == 4 && __GNUC_MINOR__ < 4
113 // gcc < 4.4 doesn't seem to find Switch::operator bool().
114 #include <OpenFOAM/Switch.H>
115 namespace Foam {
116 template<>
117 inline Switch dictionary::lookupOrDefault<Switch>
118 (
119  const word& keyword,
120  const Switch& deflt,
121  bool recursive,
122  bool patternMatch
123 ) const
124 {
125  const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
126 
127  if (entryPtr)
128  {
129  return Switch(entryPtr->stream());
130  }
131  else
132  {
133  return deflt;
134  }
135 }
136 
137 template<>
138 inline
139 Switch Foam::dictionary::lookupOrAddDefault<Switch>
140 (
141  const word& keyword,
142  const Switch& deflt,
143  bool recursive,
144  bool patternMatch
145 )
146 {
147  const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
148 
149  if (entryPtr)
150  {
151  return Switch(entryPtr->stream());
152  }
153  else
154  {
155  add(new primitiveEntry(keyword, deflt));
156  return deflt;
157  }
158 }
159 }
160 #endif
161 
162 // ************************ vim: set sw=4 sts=4 et: ************************ //