evalEntry.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) 2019-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::functionEntries::evalEntry
28
29Description
30 Uses expressions::fieldExprDriver to evaluate mathematical expressions
31 with scalars, vectors etc.
32
33 The input can any form of string or, for convenience,
34 a '{}' delimited string literal.
35 In all cases, C/C++ comment stripping is performed.
36 The default size of the evaluated field is one,
37 which can be overridden by providing an initial integer value.
38
39 Some examples,
40 \verbatim
41 a 1;
42 b 3;
43 c #eval "sin(pi()*$a/$b)";
44
45 d #eval{
46 // ignore: sin(pi()*$a/$b)
47 sin(degToRad(45))
48 };
49
50 // With different field length:
51 points #eval 4 #{ vector(rand(), 0, 0) #};
52 \endverbatim
53
54Note
55 The string expansions support use of environment variables.
56 Unknown variables will expand to an empty string, so it can be advisable
57 to expand with an alternative. For example,
58
59 \verbatim
60 d #eval{ sin(degToRad( ${angle:-0} )) };
61 \endverbatim
62
63SourceFiles
64 evalEntry.C
65
66\*---------------------------------------------------------------------------*/
67
68#ifndef functionEntries_evalEntry_H
69#define functionEntries_evalEntry_H
70
71#include "functionEntry.H"
72
73// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74
75namespace Foam
76{
77namespace functionEntries
78{
79
80/*---------------------------------------------------------------------------*\
81 Class evalEntry Declaration
82\*---------------------------------------------------------------------------*/
84class evalEntry
85:
86 public functionEntry
87{
88
89 //- Evaluate and return a token list
90 static tokenList evaluate
91 (
92 const dictionary& parentDict,
93 const string& inputExpr,
94 label fieldWidth,
95 const Istream& is
96 );
97
98 //- Evaluate and return a token list
99 static tokenList evaluate(const dictionary& parentDict, Istream& is);
100
101
102public:
103
104 //- Execute in a primitiveEntry context, extracts token or line
105 static bool execute
106 (
107 const dictionary& parentDict,
108 primitiveEntry& thisEntry,
109 Istream& is
110 );
111
112 //- Execute in a primitiveEntry context, evaluating the given content
113 static bool execute
114 (
115 const dictionary& parentDict,
117 const string& inputExpr,
118 label fieldWidth,
119 Istream& is
120 );
121};
122
123
124// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125
126} // End namespace functionEntries
127} // End namespace Foam
128
129// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130
131#endif
132
133// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
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
Uses expressions::fieldExprDriver to evaluate mathematical expressions with scalars,...
Definition: evalEntry.H:86
static bool execute(const dictionary &parentDict, primitiveEntry &thisEntry, Istream &is)
Execute in a primitiveEntry context, extracts token or line.
Definition: evalEntry.C:250
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:69
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
Namespace for OpenFOAM.