philsupertramp/game-math
Loading...
Searching...
No Matches
Classes | Enumerations | Functions | Variables
Operator.h File Reference
#include "MathNode.h"
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <memory>
#include <unordered_set>

Go to the source code of this file.

Classes

class  Operator
 
class  Function
 

Enumerations

enum  OperatorPriority {
  OPClassUnknown = 0 , OPClassLine = 1 , OPClassDot = 2 , OPClassPow = 3 ,
  OPClassParentheses = 4 , OPClassFunction = 5
}
 
enum  OperatorType {
  TYPE_ADDITION = 0 , TYPE_SUBTRACTION = 1 , TYPE_MULTIPLICATION = 2 , TYPE_DIVISION = 3 ,
  TYPE_POWER = 4 , TYPE_PARENTHESES_OPEN = 5 , TYPE_PARENTHESES_CLOSE = 6
}
 
enum  OperatorValue : char {
  VALUE_ADDITION = '+' , VALUE_SUBTRACTION = '-' , VALUE_MULTIPLICATION = '*' , VALUE_DIVISION = '/' ,
  VALUE_POWER = '^' , VALUE_PARENTHESES_OPEN = '(' , VALUE_PARENTHESES_CLOSE = ')'
}
 

Functions

std::shared_ptr< OperatorGenerateOperator (OperatorType type)
 
bool isFunction (const std::string &in)
 

Variables

const std::map< std::string, std::shared_ptr< Function > > DefaultFunctions
 

Enumeration Type Documentation

◆ OperatorPriority

Priority definition for AST generation, used in shunting-yard algorithm, the Equation class builds nodes using a stack based on priorities

Enumerator
OPClassUnknown 
OPClassLine 
OPClassDot 
OPClassPow 
OPClassParentheses 
OPClassFunction 

◆ OperatorType

Representation of operator type used in factories

Enumerator
TYPE_ADDITION 
TYPE_SUBTRACTION 
TYPE_MULTIPLICATION 
TYPE_DIVISION 
TYPE_POWER 
TYPE_PARENTHESES_OPEN 
TYPE_PARENTHESES_CLOSE 

◆ OperatorValue

enum OperatorValue : char

representation of operator value in char

Enumerator
VALUE_ADDITION 

l + r

VALUE_SUBTRACTION 

l - r

VALUE_MULTIPLICATION 

l * r

VALUE_DIVISION 
VALUE_POWER 

l^r

VALUE_PARENTHESES_OPEN 

(

VALUE_PARENTHESES_CLOSE 

)

Function Documentation

◆ GenerateOperator()

std::shared_ptr< Operator > GenerateOperator ( OperatorType  type)

Operator factory, returns shared_ptr to operator with given type

Parameters
type
Returns
Examples
symb/TestSymbolic.cpp.

◆ isFunction()

bool isFunction ( const std::string &  in)

Helper function to test if string is function representation

Parameters
in
Returns

Variable Documentation

◆ DefaultFunctions

const std::map<std::string, std::shared_ptr<Function> > DefaultFunctions
Initial value:
= {
{ "sqrt", std::make_shared<Function>("sqrt", [](double a) { return sqrt(a); }) },
{ "log", std::make_shared<Function>("log", [](double a) { return log(a); }) },
{ "sin", std::make_shared<Function>("sin", [](double a) { return sin(a); }) },
{ "cos", std::make_shared<Function>("cos", [](double a) { return cos(a); }) },
}

Default functions for parser