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-2021 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
27Namespace
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 expressions_exprString_H
44#define expressions_exprString_H
45
46#include "string.H"
47#include "dictionary.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53namespace expressions
54{
55
56/*---------------------------------------------------------------------------*\
57 Class exprString Declaration
58\*---------------------------------------------------------------------------*/
59
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;
76
77 //- Copy construct from std::string
78 inline explicit exprString(const std::string& s, bool doValidate=true);
79
80 //- Move construct from std::string
81 inline explicit exprString(std::string&& s, bool doValidate=true);
82
83 //- Construct as copy of character array
84 inline explicit exprString(const char* s, bool doValidate=true);
85
86 //- Copy construct and expand with dictionary variables,
87 //- and strip C/C++ comments from the input
88 inline exprString
89 (
90 const std::string& str,
91 const dictionary& dict,
92 const bool stripComments = true
93 );
94
95 //- Move construct and expand with dictionary variables,
96 //- and strip C/C++ comments from the input
97 inline exprString
98 (
99 std::string&& str,
100 const dictionary& dict,
101 const bool stripComments = true
102 );
103
104 //- Construct from Istream and expand with dictionary variables,
105 //- and strip C/C++ comments from the input
106 inline exprString
107 (
108 Istream& is,
109 const dictionary& dict,
110 const bool stripComments = true
111 );
112
113
114 //- Destructor
115 ~exprString() = default;
116
117
118 // Static Member Functions
119
120 //- Inplace expansion with dictionary variables,
121 //- and strip C/C++ comments from the input.
122 //
123 // \par Expansion behaviour
124 // - alternatives = True
125 // - environment = True
126 // - allow empty = True
127 // - subDict = False
128 // .
129 static void inplaceExpand
130 (
131 std::string& str,
132 const dictionary& dict,
133 const bool stripComments = true
134 );
135
136 //- Get and expand expression with dictionary entries,
137 //- optionally strip C/C++ comments from the input.
138 // Expansion behaviour as per inplaceExpand
139 static exprString getEntry
140 (
141 const word& keyword,
142 const dictionary& dict,
143 const bool stripComments = true
144 );
145
146 //- Get and expand expression with dictionary entries,
147 //- optionally strip C/C++ comments from the input.
148 // Expansion behaviour as per inplaceExpand
150 (
151 const word& keyword,
152 const dictionary& dict,
153 const bool stripComments = true
154 );
155
156 //- Copy convert string to exprString.
157 // No expansions, know what you are doing.
158 inline static exprString toExpr(const std::string& str);
159
160 //- Move convert string to exprString.
161 // No expansions, know what you are doing.
162 inline static exprString toExpr(std::string&& str);
163
164
165 // Member Functions
166
167 //- Check for unexpanded '$' entries. Fatal if any exist.
168 inline bool valid() const;
169
170 //- Inplace expansion with dictionary variables,
171 //- and strip C/C++ comments from the input
172 void expand(const dictionary& dict, const bool stripComments = true);
173
174 //- Inplace trim leading and trailing whitespace
175 void trim();
176
177 //- Read/expand entry with dictionary variables,
178 //- and strip C/C++ comments from the input
179 bool readEntry
180 (
181 const word& keyword,
182 const dictionary& dict,
183 bool mandatory = true,
184 const bool stripComments = true
185 );
186
187
188 // Member Operators
189
190 //- Copy assign
191 exprString& operator=(const exprString& str) = default;
192
193 //- Move assign
194 exprString& operator=(exprString&& str) = default;
195
196 //- Copy assign from c-string. No expansions, no comment stripping
197 inline exprString& operator=(const char* str);
198
199 //- Copy assign from string. No expansions, no comment stripping
200 inline exprString& operator=(const std::string& str);
201
202 //- Move assign from string. No expansions, no comment stripping
203 inline exprString& operator=(std::string&& str);
204
205
206 // Write
207
208 //- Dictionary entry for expression string, normally suppressing
209 //- empty strings. Generally used verbatim output (readability)
210 // \return true if entry was written
211 bool writeEntry
212 (
213 const word& keyword,
214 Ostream& os,
215 bool writeEmpty = false
216 ) const;
217};
218
219
220// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221
222} // End namespace expressions
223
224
225// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226
227//- Hashing for exprString is the same as string
228template<> struct Hash<expressions::exprString> : string::hasher {};
229
230
231// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232
233} // End namespace Foam
234
235// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236
237#include "exprStringI.H"
238
239// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240
241#endif
242
243// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
void trim()
Inplace trim leading and trailing whitespace.
Definition: exprString.C:96
exprString(exprString &&rhs)=default
Move construct.
static exprString getOptional(const word &keyword, const dictionary &dict, const bool stripComments=true)
Definition: exprString.C:67
bool valid() const
Check for unexpanded '$' entries. Fatal if any exist.
Definition: exprStringI.H:125
exprString()=default
Default construct.
static void inplaceExpand(std::string &str, const dictionary &dict, const bool stripComments=true)
Definition: exprString.C:35
void expand(const dictionary &dict, const bool stripComments=true)
Definition: exprString.C:83
exprString & operator=(exprString &&str)=default
Move assign.
exprString & operator=(const exprString &str)=default
Copy assign.
static exprString getEntry(const word &keyword, const dictionary &dict, const bool stripComments=true)
Definition: exprString.C:52
static exprString toExpr(const std::string &str)
Copy convert string to exprString.
Definition: exprStringI.H:143
bool readEntry(const word &keyword, const dictionary &dict, bool mandatory=true, const bool stripComments=true)
Definition: exprString.C:103
~exprString()=default
Destructor.
exprString(const exprString &rhs)=default
Copy construct.
bool writeEntry(const word &keyword, Ostream &os, bool writeEmpty=false) const
Definition: exprString.C:126
A class for handling character strings derived from std::string.
Definition: string.H:79
A class for handling words, derived from Foam::string.
Definition: word.H:68
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))
Namespace for OpenFOAM.
dictionary dict
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...
Definition: Hash.H:54
Hashing functor for string and derived string classes.
Definition: string.H:148