exprDriverI.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) 2010-2018 Bernhard Gschaider <bgschaid@hfd-research.com>
9  Copyright (C) 2019-2020 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 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
32 (
33  const word& name
34 ) const
35 {
36  return variables_.found(name);
37 }
38 
39 
42 (
43  const word& name
44 ) const
45 {
46  return variables_[name];
47 }
48 
49 
52 (
53  const word& name
54 )
55 {
56  return variables_[name];
57 }
58 
59 
60 template<class Type>
62 (
63  const word& name,
64  const Type& val
65 )
66 {
67  exprResult result;
68  result.setSingleValue(val);
69  variables_.set(name, std::move(result));
70 }
71 
72 
73 
74 template<class Type>
76 (
77  const expressions::exprString& expr,
78  bool wantPointData
79 )
80 {
81  parse(expr);
82 
83  return getResult<Type>(wantPointData);
84 }
85 
86 
87 
88 template<class Type>
90 (
91  const expressions::exprString& expr,
92  bool wantPointData
93 )
94 {
95  parse(expr);
96 
97  // noWarn = true
98  return result_.getUniform(1, true).cref<Type>().first();
99 }
100 
101 
102 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103 
105 {
106  return stashedTokenId_;
107 }
108 
109 
111 (
112  int tokenId
113 ) const
114 {
115  const int old = stashedTokenId_;
116  stashedTokenId_ = tokenId;
117  return old;
118 }
119 
120 
121 // ************************************************************************* //
Foam::expressions::exprDriver::stashedTokenId
int stashedTokenId() const
Get "look-behind" parsing context (internal bookkeeping)
Definition: exprDriverI.H:104
Foam::expressions::exprDriver::evaluateUniform
Type evaluateUniform(const expressions::exprString &expr, bool wantPointData=false)
Evaluate the expression and return a single value.
Definition: exprDriverI.H:90
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::expressions::exprDriver::resetStashedTokenId
int resetStashedTokenId(int tokenId=0) const
Reset "look-behind" parsing context (mutable operation)
Definition: exprDriverI.H:111
Foam::expressions::exprDriver::hasVariable
virtual bool hasVariable(const word &name) const
True if named variable exists.
Definition: exprDriverI.H:32
Foam::expressions::exprResult
A polymorphic field/result from evaluating an expression.
Definition: exprResult.H:128
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::expressions::exprResult::setSingleValue
void setSingleValue(const Type &val)
Set single-value uniform result.
Definition: exprResultI.H:461
Foam::expressions::exprDriver::addUniformVariable
void addUniformVariable(const word &name, const T &val)
Add a uniform variable from an outside caller.
Foam::expressions::exprDriver::variable
virtual exprResult & variable(const word &name)
Non-const access to the named variable (sub-classes only)
Definition: exprDriverI.H:52
Foam::expressions::exprDriver::stashedTokenId_
int stashedTokenId_
Internal bookkeeping as "look-behind" parsing context.
Definition: exprDriver.H:139
Foam::expressions::exprDriver::evaluate
tmp< Field< Type > > evaluate(const expressions::exprString &expr, bool wantPointData=false)
Evaluate the expression and return the field.
Foam::expressions::exprString
Definition: exprString.H:60