-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_parser.h
More file actions
54 lines (42 loc) · 1.11 KB
/
function_parser.h
File metadata and controls
54 lines (42 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <memory>
namespace functions {
struct evaluation_t {
public:
virtual double eval(double x) const = 0;
};
struct binary_operation : evaluation_t {
binary_operation(std::shared_ptr<evaluation_t>&& left, std::shared_ptr<evaluation_t>&& right);
virtual ~binary_operation() = default;
double eval(double x) const override;
private:
virtual double calc(double x, double y) const = 0;
std::shared_ptr<evaluation_t> left;
std::shared_ptr<evaluation_t> right;
};
namespace operations {
struct constant : evaluation_t {
constant() = default;
constant(double x);
double eval(double v) const override;
private:
double x{};
};
struct variable : evaluation_t {
private:
double eval(double x) const override;
};
struct add : binary_operation {
using binary_operation::binary_operation;
~add() override = default;
private:
double calc(double x, double y) const override;
};
struct sub : binary_operation {
using binary_operation::binary_operation;
~sub() override = default;
private:
double calc(double x, double y) const override;
};
} // namespace operations
} // namespace functions