NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
stringfunchandler.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2019 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 STRINGFUNCHANDLER_HPP
21#define STRINGFUNCHANDLER_HPP
22
23#include <string>
24#include <map>
26#include "stringvarfactory.hpp"
27
28class StringView;
29
30namespace NumeRe
31{
38 {
39 private:
40 std::map<std::string,StringFuncHandle> m_mStringFuncs;
41
42 std::string addMaskedStrings(const std::string& sString);
43 void evalFunction(std::string& sLine, const std::string& sFuncName, StringFuncHandle);
47 size_t argumentParser(StringView, s_vect&, bool& bLogicalOnly);
53
54 std::vector<s_vect> callFunction(StringFuncHandle, s_vect&, s_vect&, s_vect&, n_vect&, n_vect&, d_vect&, size_t);
55 std::vector<s_vect> callFunctionParallel(StringFuncHandle, s_vect&, s_vect&, s_vect&, n_vect&, n_vect&, d_vect&, size_t);
56 std::vector<s_vect> callMultiFunction(StringFuncHandle, s_vect&, s_vect&, s_vect&, n_vect&, n_vect&, d_vect&, size_t);
57 std::vector<s_vect> callMultiFunctionParallel(StringFuncHandle, s_vect&, s_vect&, s_vect&, n_vect&, n_vect&, d_vect&, size_t);
58
59 protected:
60 std::string applySpecialStringFuncs(std::string sLine);
61 std::string applyStringFuncs(std::string sLine);
62 void declareStringFuncs(const std::map<std::string,StringFuncHandle>& mStringFuncs);
63 size_t findNextFunction(const std::string& sFunc, StringView sLine, size_t nStartPos, size_t& nEndPosition, bool searchForMethods = false);
64 StringView getFunctionArgumentList(const std::string& sFunc, StringView sLine, size_t nStartPosition, size_t nEndPosition);
65 std::string printValue(const mu::value_type& value);
66 size_t getStringFuncMapSize() const
67 {
68 return m_mStringFuncs.size();
69 }
70 virtual StringResult eval(std::string& sLine, std::string sCache, bool bParseNumericals = true) = 0;
71
72 public:
73 virtual ~StringFuncHandler() {}
74 virtual bool isStringExpression(const std::string& sExpression) = 0;
75
76 };
77}
78
79#endif // STRINGFUNCHANDLER_HPP
80
This class provides the complete function evaluation logic to the StringParser class.
std::string applyStringFuncs(std::string sLine)
This member function searches for an occurence of a known string function in the passed command line ...
std::string applySpecialStringFuncs(std::string sLine)
This member function applies special string functions in the expression, which cannot be implemented ...
size_t findNextFunction(const std::string &sFunc, StringView sLine, size_t nStartPos, size_t &nEndPosition, bool searchForMethods=false)
Finds the position of the next function occurence in the passed string including the position of the ...
virtual bool isStringExpression(const std::string &sExpression)=0
virtual StringResult eval(std::string &sLine, std::string sCache, bool bParseNumericals=true)=0
std::vector< s_vect > callMultiFunction(StringFuncHandle, s_vect &, s_vect &, s_vect &, n_vect &, n_vect &, d_vect &, size_t)
Calls the selected string function accepting multiple values as first argument using the passed strin...
void evalFunction(std::string &sLine, const std::string &sFuncName, StringFuncHandle)
This member function evaluates the passed call sequence to the string function.
StringView getFunctionArgumentList(const std::string &sFunc, StringView sLine, size_t nStartPosition, size_t nEndPosition)
Returns the contents of the argument parentheses of the function starting at nStartPosition.
std::vector< s_vect > callFunctionParallel(StringFuncHandle, s_vect &, s_vect &, s_vect &, n_vect &, n_vect &, d_vect &, size_t)
Calls the selected string function using the passed string function arguments parallel using OpenMP.
std::string addMaskedStrings(const std::string &sString)
This member function adds escape characters into the passed string and transforms the newstring chara...
void declareStringFuncs(const std::map< std::string, StringFuncHandle > &mStringFuncs)
This member function is used to fill the internal map of declared string functions with the data of t...
size_t argumentParser(StringView, n_vect &)
This member function is the string function argument parser for numerical arguments.
std::vector< s_vect > callFunction(StringFuncHandle, s_vect &, s_vect &, s_vect &, n_vect &, n_vect &, d_vect &, size_t)
Calls the selected string function using the passed string function arguments sequentially.
std::map< std::string, StringFuncHandle > m_mStringFuncs
std::vector< s_vect > callMultiFunctionParallel(StringFuncHandle, s_vect &, s_vect &, s_vect &, n_vect &, n_vect &, d_vect &, size_t)
Calls the selected string function accepting multiple values as first argument using the passed strin...
std::string printValue(const mu::value_type &value)
Prints a value to a string respecting possible integer optimizations.
This class handles the creation and deletion of string vector variables.
This class is an extension to the std::vector<std::string> to provide the vector-like functionalities...
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
std::vector< long long int > n_vect
Simple abbreviation.
std::vector< mu::value_type > d_vect
Simple abbreviation.
This structure defines the internal string function signature. It contains the pointer to the actual ...
This structure contains all possible return values of the central string parser in single combined st...