Loading...
Searching...
No Matches
exprString.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/>.
26
27Class
28 Foam::expressions::exprString
29
30Description
31 A variant of Foam::string with expansion of dictionary variables
32 into a comma-separated form.
33
34SourceFiles
35 exprString.C
36 exprStringI.H
37
38SeeAlso
39 Foam::exprTools::expressionEntry
40
41\*---------------------------------------------------------------------------*/
42
43#ifndef Foam_expressions_exprString_H
44#define Foam_expressions_exprString_H
45
46#include "word.H"
47#include "dictionary.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53namespace expressions
54{
56/*---------------------------------------------------------------------------*\
57 Class exprString Declaration
58\*---------------------------------------------------------------------------*/
59
60class exprString
61:
62 public string
63{
64public:
65
66 // Constructors
67
68 //- Default construct
69 exprString() = default;
70
71 //- Copy construct
72 exprString(const exprString& rhs) = default;
73
74 //- Move construct
75 exprString(exprString&& rhs) = default;
77 //- Copy construct from std::string
78 inline explicit exprString(const std::string& s, bool doCheck=true);
79
80 //- Move construct from std::string
81 inline explicit exprString(std::string&& s, bool doCheck=true);
82
83 //- Construct as copy of character array
84 inline explicit exprString(const char* s, bool doCheck=true);
85
86 //- Construct from dictionary entry lookup.
87 //- Expands dictionary variables and strips and strips any
88 //- embedded C/C++ comments
89 inline exprString
90 (
91 const word& entryName,
92 const dictionary& dict,
93 const bool mandatory = true
94 );
95
96 //- Construct from Istream with dictionary context for expanding
97 //- dictionary variables. Strips any embedded C/C++ comments
98 inline exprString
99 (
100 Istream& is,
101 const dictionary& dict,
102 const bool stripComments = true
103 );
104
105
106 //- Destructor
107 ~exprString() = default;
108
109
110 // Static Member Functions
111
112 //- Copy convert string to exprString.
113 // No expansions, know what you are doing.
114 inline static exprString toExpr(const std::string& str);
115
116 //- Move convert string to exprString.
117 // No expansions, know what you are doing.
118 inline static exprString toExpr(std::string&& str);
119
120 //- Copy convert string to exprString with dictionary expansions,
121 //- stripping any embedded C/C++ comments
122 //
123 // \sa inplaceExpand() for expansion details
124 static exprString toExpr
125 (
126 const std::string& str,
127 const dictionary& dict,
128 const bool stripComments = true
129 );
130
131 //- Move convert string to exprString with dictionary expansions,
132 //- stripping any embedded C/C++ comments
133 //
134 // \sa inplaceExpand() for expansion details
135 static exprString toExpr
136 (
137 std::string&& str,
138 const dictionary& dict,
139 const bool stripComments = true
140 );
141
142 //- Inplace expansion with dictionary variables,
143 //- and strip any embedded C/C++ comments
144 //
145 // \par Expansion behaviour
146 // - alternatives = True
147 // - environment = True
148 // - allow empty = True
149 // - subDict = False
150 // .
151 static void inplaceExpand
152 (
153 std::string& str,
154 const dictionary& dict,
155 const bool stripComments = true
156 );
157
158
159 // Member Functions
160
161 //- Check for unexpanded '$' entries. Fatal if any exist.
162 inline bool valid() const;
163
164 //- Inplace expansion with dictionary variables,
165 //- and strip any embedded C/C++ comments.
166 // \sa inplaceExpand() for expansion details
167 void expand(const dictionary& dict, const bool stripComments = true);
168
169 //- Inplace trim leading and trailing whitespace
170 void trim();
171
172 //- Read/expand entry with dictionary variables,
173 //- and strip any embedded C/C++ comments from the input
174 bool readEntry
175 (
176 const word& keyword,
177 const dictionary& dict,
179 );
180
181 //- Read/expand optional entry with dictionary variables,
182 //- and strip any embedded C/C++ comments from the input
183 inline bool readIfPresent
184 (
185 const word& keyword,
186 const dictionary& dict
187 );
188
189
190 // Member Operators
191
192 //- Copy assign
193 exprString& operator=(const exprString& str) = default;
194
195 //- Move assign
196 exprString& operator=(exprString&& str) = default;
197
198 //- Copy assign from c-string. No expansions, no comment stripping
199 inline exprString& operator=(const char* str);
200
201 //- Copy assign from string. No expansions, no comment stripping
202 inline exprString& operator=(const std::string& str);
203
204 //- Move assign from string. No expansions, no comment stripping
205 inline exprString& operator=(std::string&& str);
206
207
208 // Write
209
210 //- Dictionary entry for expression string, normally suppressing
211 //- empty strings. Generally uses verbatim output (readability)
212 // \return true if entry was written
213 bool writeEntry
214 (
215 const word& keyword,
216 Ostream& os,
217 bool writeEmpty = false
218 ) const;
219};
220
221
222// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223
224} // End namespace expressions
225
226
227// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228
229//- Hashing for exprString is the same as string
230template<> struct Hash<expressions::exprString> : string::hasher {};
231
232
233// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235} // End namespace Foam
236
237// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238
240
241// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242
243#endif
244
245// ************************************************************************* //
readOption
Enumeration defining read preferences.
@ MUST_READ
Reading required.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
bool readIfPresent(const word &keyword, const dictionary &dict)
Read/expand optional entry with dictionary variables, and strip any embedded C/C++ comments from the ...
void trim()
Inplace trim leading and trailing whitespace.
Definition exprString.C:60
exprString(exprString &&rhs)=default
Move construct.
bool valid() const
Check for unexpanded '$' entries. Fatal if any exist.
exprString()=default
Default construct.
static void inplaceExpand(std::string &str, const dictionary &dict, const bool stripComments=true)
Inplace expansion with dictionary variables, and strip any embedded C/C++ comments.
Definition exprString.C:29
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=(exprString &&str)=default
Move assign.
exprString & operator=(const exprString &str)=default
Copy assign.
static exprString toExpr(const std::string &str)
Copy convert string to exprString.
~exprString()=default
Destructor.
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
exprString(const exprString &rhs)=default
Copy construct.
bool writeEntry(const word &keyword, Ostream &os, bool writeEmpty=false) const
Dictionary entry for expression string, normally suppressing empty strings. Generally uses verbatim o...
Definition exprString.C:89
string()=default
Default construct.
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
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))
A namespace for expression-related classes/traits etc.
Namespace for OpenFOAM.
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
dictionary dict
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...
Definition Hash.H:48
Hashing functor for string and derived string classes.
Definition string.H:173