TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Parser_U.h
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef Parser_U_included
17#define Parser_U_included
18
19#include <Parser.h>
20
21
22
23/*! @brief class Parser_U Version of the Parser class, deriving from Objet_U.
24 *
25 * It allows during its use to benefit from the memory management specific to Objet_U
26 * unlike the Math/Parser class
27 *
28 *
29 * @sa Parser
30 */
31class Parser_U : public Objet_U
32{
33 Declare_instanciable_sans_constructeur_ni_destructeur(Parser_U);
34
35public :
36
37 Parser_U();
38 Parser_U(const Parser_U&);
39 ~Parser_U() override;
40
41 const Parser_U& operator=(const Parser_U&);
42
43
44
45 /**
46 * Constructs the tree corresponding to the character string. This tree must be constructed only once and the character string is evaluated by traversing this tree using the eval() method as many times as desired.
47 */
48 inline void parseString();
49
50
51 /**
52 * Used to evaluate the mathematical expression corresponding to the character string. For this, you must first construct the tree using the parseString() method.
53 */
54 inline double eval();
55
56 /**
57 * Sets the value of the variable represented by a string sv.
58 */
59 inline void setVar(const char* sv, double val);
60
61 /**
62 * Returns the maximum number of fixed variables.
63 */
64 inline int getmaxVar();
65
66 /**
67 * Returns the number of registered variables.
68 */
69 inline int getNbVar();
70
71 /**
72 * Sets the value of the variable represented by the string v.
73 */
74 inline void setVar(const std::string& v, double val);
75
76 /**
77 * Sets the value of the variable with the specified number. This number corresponds to the order in which variables were added via the addVar() method.
78 */
79 inline void setVar(int i, double val);
80#ifdef INT_is_64_
81 inline void setVar(trustIdType i, double val)
82 {
83 parser->setVar((int)i, val);
84 };
85#endif
86 /**
87 * Sets the maximum number of variables to be specified with the addVar method.
88 */
89 inline void setNbVar(int nvar);
90
91 /**
92 * Allows adding a variable by specifying its representative string (e.g.: x, y1, etc.)
93 */
94 inline void addVar(const char *v);
95
96 inline std::string& getString() ;
97 inline void setString(const std::string& s) ;
98 inline void setString(const Nom& nom) ;
99 inline void addCst(const Constante& cst);
100 inline void setImpulsion(double tinit, double periode);
101 Parser& getParser() { return *parser; }
102
103
104
105private :
106
107 Parser *parser;
108
109};
110
111
112
113/**
114 * Builds the tree corresponding to the character string. This tree must be built once and the string is evaluated by traversing this tree via the eval() method as many times as desired.
115 */
117{
118 parser->parseString();
119}
120
121
122/**
123 * Used to evaluate the mathematical expression corresponding to the character string. For this, the tree must first be built using the parseString() method.
124 */
125inline double Parser_U::eval()
126{
127 return parser->eval();
128}
129
130/**
131 * Returns the maximum number of fixed variables.
132 */
134{
135 return parser->getmaxVar();
136}
137
138/**
139 * Returns the number of registered variables.
140 */
142{
143 return parser->getNbVar();
144}
145
146/**
147 * Sets the value of the variable represented by the string sv.
148 */
149inline void Parser_U::setVar(const char* sv, double val)
150{
151 parser->setVar(sv, val);
152}
153
154/**
155 * Sets the value of the variable represented by the string v.
156 */
157inline void Parser_U::setVar(const std::string& v, double val)
158{
159 parser->setVar(v, val);
160}
161
162/**
163 * Sets the value of the variable with the specified number. This number corresponds to the order in which variables were added via the addVar() method.
164 */
165inline void Parser_U::setVar(int i, double val)
166{
167 parser->setVar(i, val);
168}
169
170
171/**
172 * Sets the maximum number of variables to be specified with the addVar method.
173 */
174inline void Parser_U::setNbVar(int nvar)
175{
176 parser->setNbVar(nvar);
177}
178
179
180/**
181 * Allows adding a variable by specifying its representative string (e.g.: x, y1, etc.)
182 */
183inline void Parser_U::addVar(const char *v)
184{
185 parser->addVar(v);
186}
187
188inline std::string& Parser_U::getString()
189{
190 return parser->getString();
191}
192
193
194inline void Parser_U::setString(const std::string& s)
195{
196 parser->setString(s);
197}
198
199inline void Parser_U::setString(const Nom& nom)
200{
201 const char *s = nom.getChar();
202 std::string ss(s);
203 std::transform(ss.begin(), ss.end(), ss.begin(), ::toupper);
204 setString(ss);
205}
206
207inline void Parser_U::addCst(const Constante& cst)
208{
209 parser->addCst(cst);
210}
211
212inline void Parser_U::setImpulsion(double tinit, double periode)
213{
214 parser->setImpulsion(tinit, periode);
215}
216
217
218
219
220
221#endif
Defines a constant in the data set.
Definition Constante.h:27
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
const char * getChar() const
Definition Nom.h:91
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
~Parser_U() override
Definition Parser_U.cpp:54
void setVar(const char *sv, double val)
Definition Parser_U.h:149
void setString(const std::string &s)
Definition Parser_U.h:194
std::string & getString()
Definition Parser_U.h:188
void addCst(const Constante &cst)
Definition Parser_U.h:207
void setNbVar(int nvar)
Definition Parser_U.h:174
void parseString()
Definition Parser_U.h:116
double eval()
Definition Parser_U.h:125
const Parser_U & operator=(const Parser_U &)
Definition Parser_U.cpp:62
Parser & getParser()
Definition Parser_U.h:101
void setImpulsion(double tinit, double periode)
Definition Parser_U.h:212
int getmaxVar()
Definition Parser_U.h:133
int getNbVar()
Definition Parser_U.h:141
void addVar(const char *v)
Definition Parser_U.h:183
Representation of data for the Parser class.
Definition Parser.h:39
virtual void parseString()
Definition Parser.cpp:124