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