argListI.H
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) 2011-2013 OpenFOAM Foundation
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 "argList.H"
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
31 {
32  return executable_;
33 }
34 
35 
37 {
38  return rootPath_;
39 }
40 
41 
43 {
44  return case_;
45 }
46 
47 
49 {
50  return globalCase_;
51 }
52 
53 
55 {
56  return parRunControl_;
57 }
58 
59 
61 {
62  return rootPath()/caseName();
63 }
64 
65 
67 {
68  return args_;
69 }
70 
71 
73 {
74  return args_;
75 }
76 
77 
78 inline const Foam::string& Foam::argList::arg(const label index) const
79 {
80  return args_[index];
81 }
82 
83 
85 {
86  return args_.size();
87 }
88 
89 
91 {
92  return options_;
93 }
94 
95 
97 {
98  return options_;
99 }
100 
101 
102 inline const Foam::string& Foam::argList::option(const word& opt) const
103 {
104  return options_[opt];
105 }
106 
107 
108 inline bool Foam::argList::optionFound(const word& opt) const
109 {
110  return options_.found(opt);
111 }
112 
113 
115 {
116  return IStringStream(options_[opt]);
117 }
118 
119 
120 // * * * * * * * * * * * * Template Specializations * * * * * * * * * * * * //
121 
122 namespace Foam
123 {
124  // Template specialization for string
125  template<>
126  inline Foam::string
127  Foam::argList::argRead<Foam::string>(const label index) const
128  {
129  return args_[index];
130  }
131 
132  // Template specialization for word
133  template<>
134  inline Foam::word
135  Foam::argList::argRead<Foam::word>(const label index) const
136  {
137  return args_[index];
138  }
139 
140  // Template specialization for fileName
141  template<>
142  inline Foam::fileName
143  Foam::argList::argRead<Foam::fileName>(const label index) const
144  {
145  return args_[index];
146  }
147 
148  // Template specialization for string
149  template<>
150  inline Foam::string
151  Foam::argList::optionRead<Foam::string>(const word& opt) const
152  {
153  return options_[opt];
154  }
155 
156  // Template specialization for word
157  template<>
158  inline Foam::word
159  Foam::argList::optionRead<Foam::word>(const word& opt) const
160  {
161  return options_[opt];
162  }
163 
164  // Template specialization for fileName
165  template<>
166  inline Foam::fileName
167  Foam::argList::optionRead<Foam::fileName>(const word& opt) const
168  {
169  return options_[opt];
170  }
171 }
172 
173 
174 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
175 
176 template<class T>
177 inline T Foam::argList::argRead(const label index) const
178 {
179  T val;
180 
181  IStringStream(args_[index])() >> val;
182  return val;
183 }
184 
185 
186 template<class T>
187 inline T Foam::argList::optionRead(const word& opt) const
188 {
189  T val;
190 
191  optionLookup(opt)() >> val;
192  return val;
193 }
194 
195 
196 template<class T>
198 (
199  const word& opt,
200  T& val
201 ) const
202 {
203  if (optionFound(opt))
204  {
205  val = optionRead<T>(opt);
206  return true;
207  }
208  else
209  {
210  return false;
211  }
212 }
213 
214 
215 template<class T>
217 (
218  const word& opt,
219  T& val,
220  const T& deflt
221 ) const
222 {
223  if (optionReadIfPresent<T>(opt, val))
224  {
225  return true;
226  }
227  else
228  {
229  val = deflt;
230  return false;
231  }
232 }
233 
234 
235 template<class T>
237 (
238  const word& opt,
239  const T& deflt
240 ) const
241 {
242  if (optionFound(opt))
243  {
244  return optionRead<T>(opt);
245  }
246  else
247  {
248  return deflt;
249  }
250 }
251 
252 
253 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
254 
255 inline const Foam::string& Foam::argList::operator[](const label index) const
256 {
257  return args_[index];
258 }
259 
260 
261 inline const Foam::string& Foam::argList::operator[](const word& opt) const
262 {
263  return options_[opt];
264 }
265 
266 
267 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:69
T optionRead(const word &opt) const
Read a value from the named option.
Definition: argListI.H:187
Helper class for initializing parallel jobs from the command arguments.
Definition: parRun.H:46
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
const ParRunControl & parRunControl() const
Return parRunControl.
Definition: argListI.H:54
const string & arg(const label index) const
Return the argument corresponding to index.
Definition: argListI.H:78
const fileName & rootPath() const
Return root path.
Definition: argListI.H:36
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
Definition: argListI.H:237
const Foam::HashTable< string > & options() const
Return options.
Definition: argListI.H:90
const word & executable() const
Name of executable without the path.
Definition: argListI.H:30
fileName path() const
Return the path to the caseName.
Definition: argListI.H:60
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:42
const stringList & args() const
Return arguments.
Definition: argListI.H:66
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
A class for handling words, derived from string.
Definition: word.H:59
const fileName & globalCaseName() const
Return case name.
Definition: argListI.H:48
const string & option(const word &opt) const
Return the argument string associated with the named option.
Definition: argListI.H:102
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
T argRead(const label index) const
Read a value from the argument at index.
Definition: argListI.H:177
Input from memory buffer stream.
Definition: IStringStream.H:49
IStringStream optionLookup(const word &opt) const
Return an IStringStream from the named option.
Definition: argListI.H:114
label size() const
Return the number of arguments.
Definition: argListI.H:84
const string & operator[](const label index) const
Return the argument corresponding to index.
Definition: argListI.H:255
A class for handling character strings derived from std::string.
Definition: string.H:74
Namespace for OpenFOAM.