23 #ifndef PSSMATHPARSER_H
24 #define PSSMATHPARSER_H
31 #include <unordered_map>
49 namespace PssMathParser {
59 OperatorInDoubleOutDouble,
61 OperatorInDoubleDoubleOutDouble,
62 OperatorInDoubleIntOutDouble,
68 ArgumentGeneratedFromOneArg,
69 ArgumentGeneratedFromTwoArg
90 Entity(
const string &a_name,
94 const Entity *getEntity()
const;
117 double (*a_ddOperator)(
const double) =
nullptr,
118 double (*a_dddOperator)(
const double,
const double) =
nullptr,
119 double (*a_ddiOperator)(
const double,
const int) =
nullptr);
121 double dddOperator(
double a_arg1,
double a_arg2)
const;
122 double ddOperator(
double a_arg1)
const;
123 uint16_t precedence()
const;
126 double (*m_ddOperator)(
const double);
127 double (*m_dddOperator)(
const double,
const double);
128 double (*m_ddiOperator)(
const double,
const int);
141 double a_dvalue = 0);
143 void setDoubleValue(
const double a_dvalue);
144 double getDoubleValue()
const;
145 void setIntValue(
const int a_ivalue);
171 double generateDoubleValue()
const;
172 const string &getName()
const;
195 virtual const string expression()
const = 0;
196 virtual void setExpression(
const string &a_expression) = 0;
197 virtual void setMath(
const string &a_expression) = 0;
198 virtual const string reversePolish()
const = 0;
199 virtual bool setArgumentMap(
const string &a_reversePolish) = 0;
200 virtual bool setArgumentMap() = 0;
201 virtual bool expressionToReversePolish() = 0;
202 virtual const string mathToString()
const = 0;
203 virtual const string mathToStringFull()
const = 0;
204 virtual void setVariableDouble(
const string &a_name,
205 const double a_value) = 0;
206 virtual bool expandMathExpression() = 0;
207 virtual double calculateExpression() = 0;
208 virtual void setMathPrintPrecision(
const uint16_t &mathPrintPrecision) = 0;
209 virtual uint16_t getMathPrintPrecision()
const = 0;
210 virtual uint16_t getVariableSize()
const = 0;
211 virtual void clear() = 0;
232 static double add(
const double a_arg1,
const double a_arg2);
233 static double subtract(
const double a_arg1,
const double a_arg2);
234 static double multiply(
const double a_arg1,
const double a_arg2);
235 static double divide(
const double a_arg1,
const double a_arg2);
236 static bool isNumber(
const string &a_str);
237 static bool isSpecialCharacter(
const char &a_char);
238 static bool isSpecialNoParenthesis(
const char &a_char);
239 static double convertStringToDouble(
const string &a_str);
240 static double getResultdddOperator(
243 const string &a_operatorKey);
245 const string expression()
const;
246 void setExpression(
const string &a_expression);
248 void setMath(
const string &a_expression);
250 const string reversePolish()
const;
251 bool setArgumentMap(
const string &a_reversePolish);
252 bool setArgumentMap();
254 bool expressionToReversePolish();
256 double calculateExpression();
258 uint32_t reversePolishErrorNum();
259 const string reversePolishErrorString();
261 uint32_t expressionErrorNum();
262 const string expressionErrorString();
264 const string mathToString()
const;
265 const string mathToStringFull()
const;
267 bool expandMathExpression();
271 void setMathPrintPrecision(
const uint16_t &mathPrintPrecision);
272 uint16_t getMathPrintPrecision()
const;
274 void setVariableDouble(
const string &a_name,
const double a_value);
276 uint16_t getVariableSize()
const;
279 size_t operatorMapSize();
280 bool hasOperatorMap(
const string &a_operatorName)
const;
281 bool hasConstantMap(
const string &a_constantName)
const;
282 bool hasArgumentMap(
const string &a_argumentName)
const;
283 bool hasGeneratorMap(
const string &a_generatorName)
const;
284 bool isOperator(
const string a_entityName)
const;
285 bool isArgument(
const string a_entityName)
const;
286 bool isGenerator(
const string a_entityName)
const;
287 bool isOperatorOneArg(
const string a_entityName)
const;
288 bool isOperatorTwoArg(
const string a_entityName)
const;
289 bool generateArgArgOp(
const string &a_key1,
290 const string &a_key2,
291 const string &a_key3);
292 bool generateArgOp(
const string &a_key1,
293 const string &a_key2);
294 double getArgumentDoubleValue(
const string &a_key)
const;
295 double getConstantDoubleValue(
const string &a_key)
const;
296 const Argument *getConstant(
const string &a_key)
const;
297 const Operator *getOperator(
const string &a_key)
const;
298 Generator *getGenerator(
const string &a_key);
299 const Argument *getArgument(
const string &a_key)
const;
300 uint16_t getEntitySize(
EntityType a_entityType)
const;
301 EntityType entityType(
const string &a_key)
const;
302 void setDoubleValueToArgument(
const string &a_key,
const double a_value);
303 const string createNewUserConstantName()
const;
304 bool pushToReversePolish(
const string &a_str,
const char &a_char);
305 void appendToReversePolishString(
const string &a_str);
322 #endif // PSSMATHPARSER_H
uint32_t m_reversePolishError
Definition: pssmathparser.h:307
uint32_t m_expressionError
Definition: pssmathparser.h:309
EntityType m_type
Definition: pssmathparser.h:99
The export point of this library.
Definition: pssmathparser.h:187
static unordered_map< string, Operator > operatorMap
Available operators in a map.
Definition: pssmathparser.h:229
const Argument * m_arg2
Definition: pssmathparser.h:177
const Operator * m_op
Definition: pssmathparser.h:175
string m_reversePolish
Definition: pssmathparser.h:312
Argument * m_myArg
Definition: pssmathparser.h:178
const Argument * m_arg1
Definition: pssmathparser.h:176
Derived from Entity, used for intermediate steps of calcualtion.
Definition: pssmathparser.h:162
Derived from Entity, used for storing pointers to math functions.
Definition: pssmathparser.h:111
vector< Generator > m_generatorVec
Definition: pssmathparser.h:315
string m_reversePolishErrorString
Definition: pssmathparser.h:308
OperatorPrecedence
Enum defines precedence of operators.
Definition: pssmathparser.h:75
static unordered_map< string, Argument > constantMap
Available constants in a map.
Definition: pssmathparser.h:230
vector< string > m_RPstack
Definition: pssmathparser.h:317
string m_name
Definition: pssmathparser.h:98
Global headers for the PssMathParser.
int m_ivalue
Definition: pssmathparser.h:149
Base class for math expression entities.
Definition: pssmathparser.h:87
EntityType
Enum defines all the types of functions for the operator.
Definition: pssmathparser.h:56
uint16_t m_mathPrintPrecision
Definition: pssmathparser.h:313
string m_expression
Definition: pssmathparser.h:311
double m_dvalue
Definition: pssmathparser.h:148
Derived from Entity, used for all that is not Operator.
Definition: pssmathparser.h:136
string m_expressionErrorString
Definition: pssmathparser.h:310
OperatorPrecedence m_precedence
Definition: pssmathparser.h:125
static vector< char > specialChars
Special characters found in the infix notation.
Definition: pssmathparser.h:228
unordered_map< string, Argument > m_argumentMap
Definition: pssmathparser.h:314
Main functionality of this library.
Definition: pssmathparser.h:221
vector< string > m_math
Definition: pssmathparser.h:316