Loading...
Searching...
No Matches
exprStringI.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2012-2018 Bernhard Gschaider
9 Copyright (C) 2019-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27\*---------------------------------------------------------------------------*/
28
29#include "error.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
34(
35 const std::string& s,
36 bool doCheck
37)
38:
39 string(s)
40{
41 #ifdef FULLDEBUG
42 if (doCheck)
43 {
44 (void)valid();
45 }
46 #endif
47}
48
49
51(
52 std::string&& s,
53 bool doCheck
54)
55:
56 string(std::move(s))
57{
58 #ifdef FULLDEBUG
59 if (doCheck)
60 {
61 (void)valid();
62 }
63 #endif
64}
65
66
68(
69 const char* s,
70 bool doCheck
71)
72:
73 string(s)
74{
75 #ifdef FULLDEBUG
76 if (doCheck)
77 {
78 (void)valid();
79 }
80 #endif
81}
82
83
85(
86 const word& entryName,
87 const dictionary& dict,
88 const bool mandatory
89)
90{
91 if (mandatory)
92 {
93 readEntry(entryName, dict);
94 }
95 else
96 {
97 readIfPresent(entryName, dict);
98 }
99}
100
101
103(
104 Istream& is,
105 const dictionary& dict,
106 const bool removeComments
107)
108:
109 string(is)
110{
111 expand(dict, removeComments);
112}
113
114
115// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
116
118Foam::expressions::exprString::toExpr(const std::string& str)
119{
120 exprString expr;
121
122 expr.string::operator=(str);
123
124 return expr;
125}
126
127
130{
131 exprString expr;
132
133 expr.string::operator=(std::move(str));
134
135 return expr;
136}
137
138
141(
142 const std::string& str,
143 const dictionary& dict,
144 const bool stripComments
145)
146{
147 // Copy - no validate
148 exprString expr(str, false);
149
150 expr.expand(dict, stripComments);
151
152 return expr;
153}
154
155
158(
159 std::string&& str,
160 const dictionary& dict,
161 const bool stripComments
162)
163{
164 // Move - no validate
165 exprString expr(std::move(str), false);
166
167 expr.expand(dict, stripComments);
169 return expr;
170}
171
172
173// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
174
175inline bool Foam::expressions::exprString::valid() const
176{
177 const bool ok = !contains('$');
178
179 #ifdef FULLDEBUG
180 if (!ok)
181 {
183 << "Unexpanded '$' in " << *this << nl
184 << exit(FatalError);
186 #endif
187
188 return ok;
189}
190
191
193(
194 const word& key,
195 const dictionary& dict
196)
197{
199}
200
201
202// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
203
206{
207 string::operator=(str);
208
209 #ifdef FULLDEBUG
210 (void)valid();
211 #endif
212
213 return *this;
214}
215
216
218Foam::expressions::exprString::operator=(const std::string& str)
219{
220 string::operator=(str);
221
222 #ifdef FULLDEBUG
223 (void)valid();
224 #endif
225
226 return *this;
227}
228
229
232{
233 string::operator=(std::move(str));
234
235 #ifdef FULLDEBUG
236 (void)valid();
237 #endif
238
239 return *this;
240}
241
242
243// ************************************************************************* //
propsDict readIfPresent("fields", acceptFields)
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A variant of Foam::string with expansion of dictionary variables into a comma-separated form.
Definition exprString.H:58
bool readIfPresent(const word &keyword, const dictionary &dict)
Read/expand optional entry with dictionary variables, and strip any embedded C/C++ comments from the ...
bool valid() const
Check for unexpanded '$' entries. Fatal if any exist.
exprString()=default
Default construct.
void expand(const dictionary &dict, const bool stripComments=true)
Inplace expansion with dictionary variables, and strip any embedded C/C++ comments.
Definition exprString.C:47
exprString & operator=(const exprString &str)=default
Copy assign.
static exprString toExpr(const std::string &str)
Copy convert string to exprString.
bool readEntry(const word &keyword, const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ)
Read/expand entry with dictionary variables, and strip any embedded C/C++ comments from the input.
Definition exprString.C:67
A class for handling character strings derived from std::string.
Definition string.H:76
string()=default
Default construct.
bool contains(char c) const noexcept
True if string contains given character (cf. C++23).
Definition string.H:412
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict