NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
muParserState.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2022 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20#ifndef MUPARSERSTATE_HPP
21#define MUPARSERSTATE_HPP
22
23#include <vector>
24#include <string>
25#include <utility>
26#include "muParserDef.h"
27#include "muParserBytecode.h"
28
29class StringView;
30
31namespace mu
32{
39 {
40 enum
41 {
42 NO_FLAG = 0x0,
44 IS_TABLE_METHOD = 0x2
45 };
46
47 std::string sAccessEquation; // Passed to parser_getIndices -> returns the indices for the current access
48 std::string sVectorName; // target of the created vector -> use SetVectorVar
49 std::string sCacheName; // needed for reading the data -> create a vector var
50 int flags;
51 };
52
53
59 {
61 {
66 };
67
69 std::string m_mafunc;
70 std::string m_targetVect;
71 std::vector<int> m_componentDefs;
72
81 void create(const std::string& sTargetVect)
82 {
84 m_targetVect = sTargetVect;
85 }
86
96 void create(const std::string& sTargetVect, const std::string& sMaFunc)
97 {
99 m_targetVect = sTargetVect;
100 m_mafunc = sMaFunc;
101 }
102
112 void create(const std::string& sTargetVect, const std::vector<int>& vCompDefs)
113 {
115 m_targetVect = sTargetVect;
116 m_componentDefs = vCompDefs;
117 }
118
119 void clear()
120 {
122 m_mafunc.clear();
123 m_targetVect.clear();
124 m_componentDefs.clear();
125 }
126 };
127
128
134 struct State
135 {
137 std::string m_expr;
143
145
146 void clear()
147 {
149 m_expr.clear();
150 m_valid = 1;
151 m_numResults = 0;
152 m_stackBuffer.clear();
153 m_usedVar.clear();
155 }
156 };
157
158
164 struct Cache
165 {
166 std::vector<CachedDataAccess> m_accesses;
167 std::string m_expr;
168 std::string m_target;
170
171 void clear()
172 {
173 m_accesses.clear();
174 m_expr.clear();
175 m_target.clear();
176 m_enabled = true;
177 }
178
179 Cache() : m_enabled(true) {}
180 };
181
182
189 {
190 std::vector<mu::value_type*> m_targets;
191
192 void create(StringView sTargets, const varmap_type& usedVars);
193 void assign(const valbuf_type& buffer, int nResults);
194
195 void clear()
196 {
197 m_targets.clear();
198 }
199
200 bool isValid() const
201 {
202 return m_targets.size();
203 }
204 };
205
206
213 {
214 std::vector<State> m_states;
217
218 LineStateStack() : m_states(std::vector<State>(1)) {}
219
220 void clear()
221 {
222 m_states.clear();
223 m_cache.clear();
224 m_target.clear();
225 }
226 };
227
228
235 {
236 std::vector<LineStateStack> m_stacks;
237
238 State& operator()(size_t i, size_t j)
239 {
240 if (i < m_stacks.size() && j < m_stacks[i].m_states.size())
241 return m_stacks[i].m_states[j];
242
243 return m_stacks.back().m_states.back();
244 }
245
247 {
248 if (i < m_stacks.size())
249 return m_stacks[i];
250
251 return m_stacks.back();
252 }
253
254 void resize(size_t s)
255 {
256 m_stacks.resize(s);
257 }
258
259 void clear()
260 {
261 m_stacks.clear();
262 }
263
264 size_t size() const
265 {
266 return m_stacks.size();
267 }
268 };
269}
270
271#endif // MUPARSERSTATE_HPP
272
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
Bytecode implementation of the Math Parser.
void clear()
Delete the bytecode.
Definition of the parser bytecode class.
This file contains standard definitions used by the parser.
Namespace for mathematical applications.
Definition: muParser.cpp:53
std::vector< value_type > valbuf_type
Type used for storing an array of values.
Definition: muParserDef.h:282
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
Definition: muParserDef.h:273
Describes the cache of a single expression. Might contain multiple cached data accesses.
std::string m_target
std::string m_expr
std::vector< CachedDataAccess > m_accesses
Describes an already evaluated data access, which can be reconstructed from the current parser state.
std::string sAccessEquation
This structure defines the overall expression target, if it is composed out of a temporary vector lik...
std::vector< mu::value_type * > m_targets
void create(StringView sTargets, const varmap_type &usedVars)
Create a expression target made up from multiple variables.
void assign(const valbuf_type &buffer, int nResults)
Assign the calculated values to the target vector components.
This is the parser state stack for a whole command line. Might contain multiple single states and cac...
std::vector< State > m_states
ExpressionTarget m_target
Defines a single parser state, which contains all necessary information for evaluating a single expre...
VectorEvaluation m_vectEval
ParserByteCode m_byteCode
varmap_type m_usedVar
std::string m_expr
valbuf_type m_stackBuffer
This is a stack of all parser line state stacks. Can be used to gather a bunch of already parsed comm...
std::vector< LineStateStack > m_stacks
size_t size() const
LineStateStack & operator[](size_t i)
void resize(size_t s)
State & operator()(size_t i, size_t j)
This structure contains the necessary data to resolve all preevaluated vectors.
std::string m_targetVect
void create(const std::string &sTargetVect)
Create a standard vector pre- evaluation.
void create(const std::string &sTargetVect, const std::string &sMaFunc)
Create a multi-argument function pre- evaluation for vector arguments.
void create(const std::string &sTargetVect, const std::vector< int > &vCompDefs)
Create a vector expansion pre- evaluation.
std::vector< int > m_componentDefs