NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
stringparser.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#ifndef STRINGPARSER_HPP
20#define STRINGPARSER_HPP
21
22#include <string>
23#include <map>
25#include "stringvarfactory.hpp"
26#include "stringlogicparser.hpp"
27#include "stringfunchandler.hpp"
28#include "../ParserLib/muParser.h"
29#include "../settings.hpp"
30#include "../datamanagement/memorymanager.hpp"
31
32namespace NumeRe
33{
41 {
42 private:
43 std::map<std::string, int> m_mStringParams;
47
48 std::string getDataForString(std::string sLine, size_t n_pos);
49 std::string parseStringsInIndices(std::string sIndexExpression);
50 void replaceDataOccurence(std::string& sLine, const std::string& sOccurence);
51 std::string numToString(const std::string& sLine);
52 int storeStringResults(StringResult& strRes, std::string sObject);
53 std::string createStringOutput(StringResult& strRes, std::string& sLine, int parserFlags, bool bSilent);
54 std::string createTerminalOutput(StringResult& strRes, int parserFlags);
55 std::vector<StringStackItem> createStack(StringView sExpr) const;
56 StringVector evaluateStack(const std::vector<StringStackItem>& rpnStack, size_t from, size_t to);
58 std::vector<bool> applyElementaryStringOperations(std::vector<std::string>& vFinal, bool& bReturningLogicals);
59 void storeStringToDataObjects(StringResult& strRes, std::string& sObject, size_t& nCurrentComponent, size_t nStrings);
60 void storeStringToStringObject(const std::vector<std::string>& vFinal, std::string& sObject, size_t& nCurrentComponent, size_t nStrings);
61 int decodeStringParams(std::string& sLine);
62 bool isSimpleString(const std::string& sLine);
63 bool isToken(const char* sToken, const std::string& sLine, size_t pos);
64 std::string maskControlCharacters(std::string sString);
65 virtual StringResult eval(std::string& sLine, std::string sCache, bool bParseNumericals = true) override;
66
67 public:
69 {
72 };
73
74 StringParser(mu::Parser& parser, MemoryManager& data, Settings& option);
75 virtual ~StringParser() {}
76 StringParserRetVal evalAndFormat(std::string& sLine, std::string& sCache, bool bSilent = false, bool bCheckAssertions = false);
77 virtual bool isStringExpression(const std::string& sExpression) override;
78 };
79}
80
81
82#endif // STRINGPARSER_HPP
83
This class represents the central memory managing instance. It will handle all tables and clusters,...
This class provides the complete function evaluation logic to the StringParser class.
This class handles all logical operations on string expressions.
This class is the central string expression parser. It is designed as being a singleton with a persis...
StringResult createAndEvaluateStack(StringView sExpr)
Create a stack from the expression and evaluate it.
bool isToken(const char *sToken, const std::string &sLine, size_t pos)
Determines, whether the passed token can be found at the passed position.
std::string getDataForString(std::string sLine, size_t n_pos)
This member function returns the contents of the data objects and expands them as a list.
std::string maskControlCharacters(std::string sString)
This member function masks the line break and the tabulator control characters for storing the proces...
MemoryManager & _data
bool isSimpleString(const std::string &sLine)
This member function determines, whether the passed string is simple, i.e. it is a string literal wit...
virtual bool isStringExpression(const std::string &sExpression) override
Returns true, if the passed expression is an expression containing strings, string variables or strin...
std::vector< bool > applyElementaryStringOperations(std::vector< std::string > &vFinal, bool &bReturningLogicals)
This member function applies some elementary string operations like concatenation to the string expre...
void storeStringToStringObject(const std::vector< std::string > &vFinal, std::string &sObject, size_t &nCurrentComponent, size_t nStrings)
This member function is a helper for StringParser::storeStringResults(). It will store the strings in...
std::string numToString(const std::string &sLine)
This member function implements the so-called value-to-string parser (called via #VAR in code).
std::map< std::string, int > m_mStringParams
std::string parseStringsInIndices(std::string sIndexExpression)
Parses the string expressions in index expressions so that they may used as numerical index expressio...
mu::Parser & _parser
std::string createTerminalOutput(StringResult &strRes, int parserFlags)
This private member function creates the output specialized for the terminal.
void replaceDataOccurence(std::string &sLine, const std::string &sOccurence)
Replaces all occurences of the passed data access occurence in the passed string.
std::vector< StringStackItem > createStack(StringView sExpr) const
This member function creates a stack from the passed expression, which may then be evaluated more eas...
virtual StringResult eval(std::string &sLine, std::string sCache, bool bParseNumericals=true) override
This public member function provides the string parser core functionality and is the function,...
StringVector evaluateStack(const std::vector< StringStackItem > &rpnStack, size_t from, size_t to)
Evaluate the created RPN stack between the selected start and end points.
int storeStringResults(StringResult &strRes, std::string sObject)
This member function stores the processed and calculated string results in their desired targets.
void storeStringToDataObjects(StringResult &strRes, std::string &sObject, size_t &nCurrentComponent, size_t nStrings)
This member function is a helper for StringParser::storeStringResults(). It will store the strings in...
StringParserRetVal evalAndFormat(std::string &sLine, std::string &sCache, bool bSilent=false, bool bCheckAssertions=false)
This public member function evaluates the passed string expression and formats the results for the co...
StringParser(mu::Parser &parser, MemoryManager &data, Settings &option)
String parser constructor.
std::string createStringOutput(StringResult &strRes, std::string &sLine, int parserFlags, bool bSilent)
This member function converts the processed string parser results into an output string,...
int decodeStringParams(std::string &sLine)
This member function finds and decodes all passed string expression parameters and removes them from ...
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
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...
Mathematical expressions parser.
Definition: muParser.h:51
This structure contains all possible return values of the central string parser in single combined st...