8#include <unordered_set>
64 std::function<double(
double,
double)>
op;
77 type = MathNodeType::NodeType_Operator;
94 [[nodiscard]]
double Evaluate()
const override {
96 assert(
left !=
nullptr &&
right !=
nullptr);
125 Function(
const std::string& val,
const std::function<
double(
double)>& fun)
127 val, [fun](double a, [[maybe_unused]] double b) {
return fun(a); }, OperatorPriority::OPClassFunction) {
129 type = MathNodeType::NodeType_Functional;
139 Function(
const std::string& val,
const std::function<
double(
double,
double)>& fun)
142 type = MathNodeType::NodeType_Functional;
143 std::cerr <<
"This can't be parsed yet!!!!!!" << std::endl;
162 {
"sqrt", std::make_shared<Function>(
"sqrt", [](
double a) {
return sqrt(a); }) },
163 {
"log", std::make_shared<Function>(
"log", [](
double a) {
return log(a); }) },
164 {
"sin", std::make_shared<Function>(
"sin", [](
double a) {
return sin(a); }) },
165 {
"cos", std::make_shared<Function>(
"cos", [](
double a) {
return cos(a); }) },
std::shared_ptr< Operator > GenerateOperator(OperatorType type)
OperatorPriority
Definition: Operator.h:15
@ OPClassLine
Definition: Operator.h:17
@ OPClassUnknown
Definition: Operator.h:16
@ OPClassPow
Definition: Operator.h:19
@ OPClassFunction
Definition: Operator.h:21
@ OPClassParentheses
Definition: Operator.h:20
@ OPClassDot
Definition: Operator.h:18
OperatorType
Definition: Operator.h:27
@ TYPE_POWER
Definition: Operator.h:32
@ TYPE_MULTIPLICATION
Definition: Operator.h:30
@ TYPE_DIVISION
Definition: Operator.h:31
@ TYPE_SUBTRACTION
Definition: Operator.h:29
@ TYPE_ADDITION
Definition: Operator.h:28
@ TYPE_PARENTHESES_CLOSE
Definition: Operator.h:34
@ TYPE_PARENTHESES_OPEN
Definition: Operator.h:33
const std::map< std::string, std::shared_ptr< Function > > DefaultFunctions
Definition: Operator.h:161
OperatorValue
Definition: Operator.h:40
@ VALUE_ADDITION
l + r
Definition: Operator.h:42
@ VALUE_POWER
l^r
Definition: Operator.h:50
@ VALUE_PARENTHESES_CLOSE
)
Definition: Operator.h:54
@ VALUE_MULTIPLICATION
l * r
Definition: Operator.h:46
@ VALUE_PARENTHESES_OPEN
(
Definition: Operator.h:52
@ VALUE_DIVISION
Definition: Operator.h:48
@ VALUE_SUBTRACTION
l - r
Definition: Operator.h:44
bool isFunction(const std::string &in)
Definition: Operator.h:118
double Evaluate() const override
Definition: Operator.h:146
Function(const std::string &val, const std::function< double(double, double)> &fun)
Definition: Operator.h:139
Function(const std::string &val, const std::function< double(double)> &fun)
Definition: Operator.h:125
Definition: MathNode.h:43
std::shared_ptr< MathNode > left
next node on left side
Definition: MathNode.h:54
MathNodeType type
node type representation
Definition: MathNode.h:50
std::shared_ptr< MathNode > right
next node on right side
Definition: MathNode.h:56
NodeConnectionType connectionType
type of connection allowed for this node
Definition: MathNode.h:52
Definition: Operator.h:61
std::function< double(double, double)> op
Operator implementation, this will be evaluated during Evaluate calls.
Definition: Operator.h:64
OperatorPriority priority
Operator priority, used to create AST.
Definition: Operator.h:66
double Evaluate() const override
Definition: Operator.h:94
Operator(const Operator &other)
Definition: Operator.h:84
Operator(const std::string &name, std::function< double(double, double)> fun, OperatorPriority operatorPriority)
Definition: Operator.h:73