expressionEntry.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) 2014-2018 Bernhard Gschaider
9 Copyright (C) 2019 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::exprTools::expressionEntry
29
30Description
31 Convert dictionary entry to a stringified expression.
32
33 The general OpenFOAM dictionary expansions will result in
34 space-separated values. For example,
35
36 \verbatim
37 origin (0.21 0 0.01);
38
39 condition "mag(pos() - $centre) < 0.5";
40 \endverbatim
41
42 this will expand to the following:
43
44 \verbatim
45 condition "mag(pos() - (0.21 0 0.01)) < 0.5";
46 \endverbatim
47
48 For these type of expressions, we'd would like better control.
49 Using instead the special expansions, we can add an effective
50 type cast.
51
52 \verbatim
53 condition "mag(pos() - $[(vector)centre]) < 0.5";
54 \endverbatim
55
56 which will expand to the following:
57
58 \verbatim
59 condition "mag(pos() - vector(0.21,0,0.01)) < 0.5";
60 \endverbatim
61
62SourceFiles
63 expressionEntry.C
64 expressionEntryI.H
65
66\*---------------------------------------------------------------------------*/
67
68#ifndef exprTools_expressionEntry_H
69#define exprTools_expressionEntry_H
70
71#include "exprString.H"
72#include "primitiveEntry.H"
74
75// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76
77namespace Foam
78{
79namespace exprTools
80{
81
82/*---------------------------------------------------------------------------*\
83 Class expressionEntry Declaration
84\*---------------------------------------------------------------------------*/
87{
88protected:
89
90 //- Stringified version of data with comma-separated components.
91 //- Uses prefix corresponding to the pTraits of Type.
92 template<class Type>
93 static string toExprStr(const Type& data);
94
95 //- Comma-separated stringified version of primitiveEntry of Type.
96 //- Prefix corresponding to the pTraits of Type
97 template<class Type>
98 static string toExprStr(ITstream& is);
99
100
101public:
102
103 //- Runtime type information
104 TypeNameNoDebug("expressionEntry");
107 (
108 autoPtr,
110 empty,
111 (),
112 ()
113 );
114
115
116 // Constructors
117
118 //- Construct null
119 expressionEntry() = default;
120
121
122 // Selectors
123
124 //- Return an entry to expression converter
125 static autoPtr<expressionEntry> New(const word& name);
126
127
128 //- Destructor
129 virtual ~expressionEntry() = default;
130
131
132 // Static Member Functions
133
134 //- Generic concatenate tokens to space-separated string.
135 inline static string evaluate(const entry& e);
136
137 //- Inplace expand expression with dictionary variables/entries
138 //
139 // \par Expansion behaviour
140 // - alternatives = True
141 // - environment = True
142 // - allow empty = True
143 // - subDict = False
144 // .
145 static void inplaceExpand
146 (
147 std::string& s,
148 const dictionary& dict
149 );
150
151 //- Expand expression with dictionary entries
153 (
154 const std::string& str,
155 const dictionary& dict
156 );
157
158
159 // Member Functions
160
161 //- To string. Normally with comma separators.
162 virtual string toExpr(const entry& e) const
163 {
164 return evaluate(e);
165 }
166};
167
168
169// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170
171} // End namespace exprTools
172} // End namespace Foam
173
174// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175
176#include "expressionEntryI.H"
177
178// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179
180#endif
181
182// ************************************************************************* //
An input stream of tokens.
Definition: ITstream.H:56
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
Convert dictionary entry to a stringified expression.
virtual string toExpr(const entry &e) const
To string. Normally with comma separators.
static expressions::exprString expand(const std::string &str, const dictionary &dict)
Expand expression with dictionary entries.
declareRunTimeSelectionTable(autoPtr, expressionEntry, empty,(),())
expressionEntry()=default
Construct null.
static string toExprStr(const Type &data)
static string evaluate(const entry &e)
Generic concatenate tokens to space-separated string.
TypeNameNoDebug("expressionEntry")
Runtime type information.
static void inplaceExpand(std::string &s, const dictionary &dict)
Inplace expand expression with dictionary variables/entries.
static string toExprStr(ITstream &is)
virtual ~expressionEntry()=default
Destructor.
static autoPtr< expressionEntry > New(const word &name)
Return an entry to expression converter.
A class for handling words, derived from Foam::string.
Definition: word.H:68
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.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Macros to ease declaration of run-time selection tables.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes)
dictionary dict
volScalarField & e
Definition: createFields.H:11
#define TypeNameNoDebug(TypeNameString)
Declare a ClassNameNoDebug() with extra virtual type info.
Definition: typeInfo.H:68