calcEntry.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::functionEntries::calcEntry
26 
27 Description
28  Uses dynamic compilation to provide calculating functionality
29  for entering dictionary entries.
30 
31  E.g.
32 
33  \verbatim
34  a 1.0;
35  b 3;
36  c #calc "$a*$b";
37  \endverbatim
38 
39  Note the explicit trailing 0 ('1.0') to force a to be read (and written)
40  as a floating point number.
41 
42  Special care is required for calc entries that include a division since
43  "/" is also used as the scoping operator to identify keywords in
44  sub-dictionaries. For example, "$a/b" expects a keyword "b" within a
45  sub-dictionary named "a". A division can be correctly executed by using a
46  space between a variables and "/", e.g.
47 
48  \verbatim
49  c #calc "$a / $b";
50  \endverbatim
51 
52  or "()" scoping around the variable, e.g.
53 
54  \verbatim
55  c #calc "($a)/$b";
56  \endverbatim
57 
58  Note:
59  Internally this is just a wrapper around codeStream functionality - the
60  #calc string gets used to construct a dictionary for codeStream.
61 
62 SourceFiles
63  calcEntry.C
64 
65 \*---------------------------------------------------------------------------*/
66 
67 #ifndef calcEntry_H
68 #define calcEntry_H
69 
70 #include "functionEntry.H"
71 
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 
74 namespace Foam
75 {
76 
77 class dlLibraryTable;
78 
79 namespace functionEntries
80 {
81 
82 /*---------------------------------------------------------------------------*\
83  Class calcEntry Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 class calcEntry
87 :
88  public functionEntry
89 {
90  // Private Member Functions
91 
92  //- Perform the calculation and return the resulting string
93  static string calc
94  (
95  const dictionary& dict,
96  Istream& is
97  );
98 
99 
100 public:
101 
102  //- Runtime type information
103  ClassName("calc");
104 
105 
106  // Constructors
107 
108  //- Disallow default bitwise copy construction
109  calcEntry(const calcEntry&) = delete;
110 
111 
112  // Member Functions
113 
114  //- Execute the functionEntry in a sub-dict context
115  static bool execute(dictionary& dict, Istream&);
116 
117  //- Execute the functionEntry in a primitiveEntry context
118  static bool execute
119  (
120  const dictionary& dict,
122  Istream&
123  );
124 
125 
126  // Member Operators
127 
128  //- Disallow default bitwise assignment
129  void operator=(const calcEntry&) = delete;
130 };
131 
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 } // End namespace functionEntries
136 } // End namespace Foam
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 #endif
141 
142 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Uses dynamic compilation to provide calculating functionality for entering dictionary entries.
Definition: calcEntry.H:88
ClassName("calc")
Runtime type information.
static bool execute(dictionary &dict, Istream &)
Execute the functionEntry in a sub-dict context.
Definition: calcEntry.C:103
calcEntry(const calcEntry &)=delete
Disallow default bitwise copy construction.
void operator=(const calcEntry &)=delete
Disallow default bitwise assignment.
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:66
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
const dictionary & dict() const
This entry is not a dictionary,.
Namespace for OpenFOAM.