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  Original code Copyright (C) 2012-2018 Bernhard Gschaider
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 Namespace
28  Foam::expressions::exprString
29 
30 Description
31  A variant of Foam::string with expansion of dictionary variables
32  into a comma-separated form.
33 
34 SourceFiles
35  exprString.C
36  exprStringI.H
37 
38 SeeAlso
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 
51 namespace Foam
52 {
53 namespace expressions
54 {
55 
56 /*---------------------------------------------------------------------------*\
57  Class exprString Declaration
58 \*---------------------------------------------------------------------------*/
59 
61 :
62  public string
63 {
64 public:
65 
66  // Constructors
67 
68  //- Construct null
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  //
139  // Expansion behaviour as per inplaceExpand
141  (
142  const word& name,
143  const dictionary& dict,
144  const bool stripComments = false
145  );
146 
147  //- Copy convert string to exprString.
148  // No expansions, know what you are doing.
149  inline static exprString toExpr(const std::string& str);
150 
151  //- Move convert string to exprString.
152  // No expansions, know what you are doing.
153  inline static exprString toExpr(std::string&& str);
154 
155 
156  // Member Functions
157 
158  //- Inplace expansion with dictionary variables,
159  //- and strip C/C++ comments from the input
161  (
162  const dictionary& dict,
163  const bool stripComments = true
164  );
165 
166  //- Check for unexpanded '$' entries. Fatal if any exist.
167  inline bool valid() const;
168 
169 
170  // Member Operators
171 
172  //- Copy assign
173  exprString& operator=(const exprString& str) = default;
174 
175  //- Move assign
176  exprString& operator=(exprString&& str) = default;
177 
178  //- Copy assign from c-string. No expansions, no comment stripping
179  inline exprString& operator=(const char* str);
180 
181  //- Copy assign from string. No expansions, no comment stripping
182  inline exprString& operator=(const std::string& str);
183 
184  //- Move assign from string. No expansions, no comment stripping
185  inline exprString& operator=(std::string&& str);
186 };
187 
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace expressions
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #include "exprStringI.H"
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 #endif
201 
202 // ************************************************************************* //
Foam::expressions::exprString::expand
exprString & expand(const dictionary &dict, const bool stripComments=true)
Definition: exprString.C:74
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
s
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))
Definition: gmvOutputSpray.H:25
Foam::expressions::exprString::toExpr
static exprString toExpr(const std::string &str)
Copy convert string to exprString.
Definition: exprStringI.H:143
string.H
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:73
exprStringI.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::expressions::exprString::exprString
exprString()=default
Construct null.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::expressions::exprString::valid
bool valid() const
Check for unexpanded '$' entries. Fatal if any exist.
Definition: exprStringI.H:125
Foam::expressions::exprString
Definition: exprString.H:60
dictionary.H
Foam::expressions::exprString::getExpression
static exprString getExpression(const word &name, const dictionary &dict, const bool stripComments=false)
Definition: exprString.C:52
Foam::expressions::exprString::inplaceExpand
static void inplaceExpand(std::string &str, const dictionary &dict, const bool stripComments=true)
Definition: exprString.C:35
Foam::expressions::exprString::operator=
exprString & operator=(const exprString &str)=default
Copy assign.
Foam::expressions::exprString::~exprString
~exprString()=default
Destructor.