NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
muParserState.cpp
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#include "muParserState.hpp"
20#include "../utils/tools.hpp"
21#include "../io/logger.hpp"
22
23
24namespace mu
25{
35 void ExpressionTarget::create(StringView sTargets, const varmap_type& usedVars)
36 {
37 if (m_targets.size())
38 m_targets.clear();
39
40 while (sTargets.length())
41 {
42 StringView sExpr = getNextViewedArgument(sTargets);
43 //g_logger.debug("Using " + sExpr.to_string());
44
45 for (const auto& iter : usedVars)
46 {
47 if (sExpr == iter.first)
48 {
49 m_targets.push_back(iter.second);
50 break;
51 }
52 }
53 }
54 }
55
56
66 void ExpressionTarget::assign(const valbuf_type& buffer, int nResults)
67 {
68 //g_logger.debug("Using target. Size = " + toString(m_targets.size()));
69 // Assign the results to the target variables
70 // and consider also singletons
71 for (size_t i = 0; i < m_targets.size(); i++)
72 *m_targets[i] = buffer[nResults == 1 ? 0 : std::min((int)i, nResults-1)];
73 }
74}
75
76
size_t length() const
This member function simply returns the length of the viewed section.
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
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
#define min(a, b)
Definition: resampler.cpp:34
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.
StringView getNextViewedArgument(StringView &sView)
Definition: tools.cpp:2327