NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
stringdatastructures.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 STRINGDATASTRUCTURES_HPP
20#define STRINGDATASTRUCTURES_HPP
21
22#include <string>
23#include <vector>
24
25#include "../ParserLib/muParserDef.h"
26#include "../utils/stringtools.hpp"
27#include "../structures.hpp"
28
29class Settings;
30
31
32
39{
40 private:
41 std::string m_data;
42
43 public:
48 { }
49
57 StringArg(const std::string& sStr) : m_data(sStr)
58 { }
59
66 StringArg(const StringArg& sStr) : m_data(sStr.m_data)
67 { }
68
78 {
79 m_data = sStr.m_data;
80 return *this;
81 }
82
91 StringArg& operator=(const std::string& sStr)
92 {
93 m_data = sStr;
94 return *this;
95 }
96
104 bool is_string() const
105 {
106 return m_data.length() && m_data.front() == '"';
107 }
108
116 {
117 if (is_string())
118 return StringView(m_data, 1, m_data.length()-2);
119
120 return StringView(m_data);
121 }
122
130 std::string& getRef()
131 {
132 return m_data;
133 }
134};
135
136
145class StringVector : public std::vector<std::string>
146{
147 private:
148 const std::string m_sDUMMY;
149
151 static std::string makeLocalString(const std::string& sStr);
152 StringView getVectorized(size_t i) const;
154 bool getBooleanVectorized(size_t i) const;
155 void assign(const StringVector& sVect);
156 void assign(const std::vector<bool>& vect);
157 StringVector operator+(const std::string& sLiteral) const;
158 StringVector& operator+=(const std::string& sLiteral);
159
160 public:
161 StringVector();
162 StringVector(const std::string& sStr);
163 StringVector(const char* sStr);
164 StringVector(bool val);
165 StringVector(const std::vector<std::string>& vect);
166 StringVector(const StringVector& vect);
167 StringVector(const std::vector<bool>& vect);
168 StringVector(size_t n, const std::string& sStr = std::string());
169 StringVector(StringVector&& vect) = default;
170 static StringVector empty_string();
171 static StringVector convert_internal(const std::string& sInternal);
172 static StringVector convert_literal(const std::string& sLiteral);
173 StringVector& operator=(const StringVector& sVect);
175 StringVector& operator=(const std::vector<bool>& vect);
176 void push_back(const std::string& sStr);
177 void push_back(const char* sStr);
178 void push_back(const mu::value_type& vVal);
179 void push_back(size_t nVal);
180 void push_back(int nVal);
181 void push_back(long long int nVal);
182 void push_back(bool nVal);
183 void push_generic(const std::string& sStr);
184 bool is_string(size_t i) const;
185 void convert_to_string(size_t i, size_t minChars = 0);
186 StringView operator[](size_t i) const;
187 StringArg getArg(size_t i) const;
188 std::string getMasked(size_t i) const;
189 std::string& getRef(size_t i);
190 std::vector<bool> operator==(const StringVector& sVect) const;
191 std::vector<bool> operator!=(const StringVector& sVect) const;
192 std::vector<bool> operator<(const StringVector& sVect) const;
193 std::vector<bool> operator<=(const StringVector& sVect) const;
194 std::vector<bool> operator>(const StringVector& sVect) const;
195 std::vector<bool> operator>=(const StringVector& sVect) const;
196 std::vector<bool> and_f(const StringVector& sVect) const;
197 std::vector<bool> or_f(const StringVector& sVect) const;
198 std::vector<bool> xor_f(const StringVector& sVect) const;
199 StringVector operator+(const StringVector& sVect) const;
200 StringVector& operator+=(const StringVector& sVect);
201 StringVector& evalIfElse(const StringVector& sLogicals, const StringVector& sIfBranch, const StringVector& sElseBranch);
202};
203
204
210{
212 int m_val;
213
214 StringStackItem(StringView sView, int val = -1) : m_data(sView), m_val(val) {}
215};
216
217
222
226typedef std::vector<long long int> n_vect;
227
231typedef std::vector<mu::value_type> d_vect;
232
233
240{
243 long long int nArg1, nArg2;
246 const Settings* opt;
247
248 StringFuncArgs() : nArg1(INT_MIN), nArg2(INT_MIN), dArg1(0.0), opt(nullptr) {}
249};
250
251
257
258
265{
267
270
273
276
279
284
287
294
299
300
309{
311 {
312 bTakesMultiArguments = false;
314 fHandle = nullptr;
315 }
316
317 StringFuncHandle(FunctionSignatureType _fType, StringFunc _fHandle, bool _bTakesMultiArguments) : fType(_fType), fHandle(_fHandle), bTakesMultiArguments(_bTakesMultiArguments) {}
318
322};
323
324
331{
333 {
334 bOnlyLogicals = false;
335 }
336
337 StringResult(s_vect& _vResult, std::vector<bool>& _vNoStringVal, bool _bOnlyLogicals) : vResult(_vResult), vNoStringVal(_vNoStringVal), bOnlyLogicals(_bOnlyLogicals) {}
338
339 StringResult(const std::string& sRet, bool _bOnlyLogicals = false) : StringResult()
340 {
341 vResult.push_generic(sRet);
342 vNoStringVal.push_back(sRet.find('"') == std::string::npos);
343 bOnlyLogicals = _bOnlyLogicals;
344 }
345
346 StringResult(const std::string& sRet, mu::value_type* vals, int nvals) : StringResult()
347 {
348 bOnlyLogicals = true;
349 vResult.push_generic(sRet);
350 vNoStringVal.resize(nvals, true);
351 vNumericalValues.assign(vals, vals+nvals);
352 }
353
355 std::vector<bool> vNoStringVal;
356 std::vector<mu::value_type> vNumericalValues;
358};
359
360
366{
369 PEEK = 2,
373
374
381{
382 std::string lower;
383 std::string upper;
384
385 // Constructor fills the fields with the corresponding
386 // character codes (eg \x94 is a Hex value for (char)148)
387 Umlauts() : lower("äüöß\x84\x94\x81"), upper("ÄÖÜ\x8E\x99\x9A") {}
388};
389
390#endif // STRINGDATASTRUCTURES_HPP
391
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
Simply container to provide the data for a StringView instance usable by all the string functions.
StringArg(const StringArg &sStr)
Copy a StringArg instance.
StringArg()
Default constructor.
StringView view() const
Get a view to the contained string.
StringArg & operator=(const StringArg &sStr)
StringArg assignment operator overload.
bool is_string() const
Determine, whether the contained string represents a string literal.
std::string & getRef()
Get a reference to the contained string.
StringArg(const std::string &sStr)
Construct a StringArg instance from a std::string instance.
std::string m_data
StringArg & operator=(const std::string &sStr)
StringArg assignment operator overload for a std::string instance.
This class is an extension to the std::vector<std::string> to provide the vector-like functionalities...
StringVector & operator=(const StringVector &sVect)
Assignment operator overload for a StringVector instance.
StringView operator[](size_t i) const
Return a view to the i-th element.
StringVector & operator=(StringVector &&sVect)=default
void push_back(const std::string &sStr)
Append a string to the end of this vector. Will be stored as local string.
std::string & getRef(size_t i)
Return a reference to the i-th element in this string.
std::vector< bool > operator!=(const StringVector &sVect) const
Inequality operator overload.
std::string getMasked(size_t i) const
Return the contained string with the internal quotation marks as escaped variants.
std::vector< bool > operator<(const StringVector &sVect) const
Less-than operator overload.
StringVector(StringVector &&vect)=default
StringVector()
Default constructor.
std::vector< bool > operator==(const StringVector &sVect) const
Equality operator overload.
void convert_to_string(size_t i, size_t minChars=0)
Convert the i-th element to a string.
const std::string m_sDUMMY
static StringVector convert_internal(const std::string &sInternal)
Static member function to create a StringVector instance from an internal string.
static StringVector empty_string()
Static member function to create a StringVector with one component with zero length.
void push_generic(const std::string &sStr)
Append a generic string value to the end of this vector. Depending on the existence of surrounding qu...
mu::value_type getNumericalVectorized(size_t i) const
Get either the i-th element or the 1st element converted as numerical value, if this vector has only ...
std::vector< bool > xor_f(const StringVector &sVect) const
This member function represents an XOR operator.
std::vector< bool > operator>=(const StringVector &sVect) const
Greater-equal operator overload.
bool is_string(size_t i) const
Check whether the i-th element represents a string or a numeric value.
static StringView makePureString(StringView sStr)
Static member function to convert the contained string into a pur C++ string.
std::vector< bool > operator<=(const StringVector &sVect) const
Lesser-equal operator overload.
std::vector< bool > or_f(const StringVector &sVect) const
This member function represents an OR operator.
StringVector & operator+=(const std::string &sLiteral)
Append a string literal to this StringVector instance.
StringVector operator+(const std::string &sLiteral) const
Concatenate a StringVector and a string literal.
std::vector< bool > and_f(const StringVector &sVect) const
This member function represents an AND operator.
std::vector< bool > operator>(const StringVector &sVect) const
Greater-than operator overload.
StringVector & evalIfElse(const StringVector &sLogicals, const StringVector &sIfBranch, const StringVector &sElseBranch)
Assign the results of an if-else construct to this StringVector instance.
bool getBooleanVectorized(size_t i) const
Get either the i-th element or the 1st element converted as boolean, if this vector has only one comp...
StringView getVectorized(size_t i) const
Get either the i-th element or the 1st element, if this vector has only one component (and is a singl...
StringArg getArg(size_t i) const
Create a StringArg instance from the i-th or the 1st element, if this vector is a singleton.
void assign(const StringVector &sVect)
Assign another StringVector instance.
static StringVector convert_literal(const std::string &sLiteral)
Static member function to create a StringVector instance from a string literal.
static std::string makeLocalString(const std::string &sStr)
Static member function to convert the string literal to an internal string for this class.
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
StringVector(* StringFunc)(StringFuncArgs &)
Defines the pointer to an arbitrary string function as StringFunc.
std::vector< long long int > n_vect
Simple abbreviation.
FunctionSignatureType
This enumeration contains all possible string function signature types (as they are called from the u...
@ STR_STR_VALOPT
@ STR_STR_VALOPT_VALOPT
@ PARSER_STRING_INT_INT_STRING
@ STR_STROPT_VALOPT
@ STR_VAL_VALOPT
@ PARSER_STRING_STRING_STRING_INT_INT
@ STR_STR_STR_VALOPT_VALOPT
@ STR_VAL_VALOPT_STROPT
@ PARSER_STRING_STRING_INT_INT
@ PARSER_STRING_INT_INT
@ PARSER_STRING_DOUBLE
@ STR_STR_STROPT
StringVector s_vect
Simple abbreviation.
StringParserFlags
Defines the possible flags, which the user might pass to the string parser.
@ KEEP_MASKED_QUOTES
@ KEEP_MASKED_CONTROL_CHARS
std::vector< mu::value_type > d_vect
Simple abbreviation.
This structure combines all string function's arguments into a single structure to align all string f...
const Settings * opt
This structure defines the internal string function signature. It contains the pointer to the actual ...
StringFuncHandle(FunctionSignatureType _fType, StringFunc _fHandle, bool _bTakesMultiArguments)
FunctionSignatureType fType
This structure contains all possible return values of the central string parser in single combined st...
StringResult(s_vect &_vResult, std::vector< bool > &_vNoStringVal, bool _bOnlyLogicals)
std::vector< bool > vNoStringVal
std::vector< mu::value_type > vNumericalValues
StringResult(const std::string &sRet, mu::value_type *vals, int nvals)
StringResult(const std::string &sRet, bool _bOnlyLogicals=false)
A simple container for a single item in the string expression RPN stack.
StringStackItem(StringView sView, int val=-1)
Structure containing the german umlauts. The lower field will contain lower case umlauts,...
std::string upper
std::string lower