-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwoOp.hpp
84 lines (66 loc) · 1.82 KB
/
TwoOp.hpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// Copyright © 2017 Lennart Oymanns. All rights reserved.
//
#ifndef TwoOp_hpp
#define TwoOp_hpp
#include <algorithm>
#include <list>
#include "Node.hpp"
#include "NumberRepr.hpp"
namespace Equation {
class TwoOp : public Node {
public:
TwoOp(NodePtr node, const std::string &operator1) {
op1.push_back(node);
o1 = operator1;
}
TwoOp(const TwoOp &o) {
o1 = o.o1;
for (const auto &e : o.op1) {
op1.push_back(e->clone());
}
}
explicit TwoOp(const std::string &operator1) { o1 = operator1; }
~TwoOp() {}
virtual void Eval(NodePtr *base, std::shared_ptr<State> state,
bool numeric = false);
void AddOp1(NodePtr node) { op1.push_back(node); }
virtual NumberRepr Operation1(NumberRepr base, NumberRepr n) = 0;
virtual NumberRepr NeutralElement() = 0;
virtual void writeTreeToStream(std::ostream &s, const std::string &name);
virtual bool IsNumber() const {
bool number = true;
for (auto &e : op1) {
if (e->IsNumber() == false) {
number = false;
}
}
return number;
}
virtual bool equals(NodePtr n) const {
if (Type() != n->Type()) {
return false;
}
auto un = std::static_pointer_cast<TwoOp>(n);
if (op1.size() != un->op1.size()) {
return false;
}
bool num =
std::is_permutation(op1.begin(), op1.end(), un->op1.begin(),
[](const NodePtr &item1, const NodePtr &item2) {
return (item1->equals(item2));
});
// bool num = op1 == un->op1;
if (!num) {
return false;
}
return true;
}
const std::list<NodePtr> &Data() const { return op1; }
std::list<NodePtr> &Data() { return op1; }
protected:
std::list<NodePtr> op1;
std::string o1;
};
} // namespace Equation
#endif /* TwoOp_hpp */