-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreactant_t.h
More file actions
107 lines (84 loc) · 2.73 KB
/
reactant_t.h
File metadata and controls
107 lines (84 loc) · 2.73 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <utility>
#include "rule_t.h"
#include "tempRule_t.h"
#ifndef EXAM_REACTANT_T_H
#define EXAM_REACTANT_T_H
class reactant_t {
private:
std::string name{};
int amount{};
public:
[[nodiscard]] const std::string& getName() const {
return name;
}
[[nodiscard]] int getAmount() const {
return amount;
}
void setAmount(int newAmount) {
reactant_t::amount = newAmount;
}
public:
reactant_t(std::string name, int amount) : name(std::move(name)), amount(amount) {}
reactant_t(const reactant_t& other) {
name = other.name;
amount = other.amount;
}
reactant_t& operator=(const reactant_t& other) {
if (this != &other) {
name = other.name;
amount = other.amount;
}
return *this;
}
~reactant_t() = default;
friend tempRule_t<reactant_t>& operator+(const reactant_t& lhs, const reactant_t& rhs) {
auto rule = new tempRule_t<reactant_t>;
rule->input = {lhs, rhs};
return *rule;
}
friend tempRule_t<reactant_t>& operator+(const reactant_t& lhs, tempRule_t<reactant_t>& rhs) {
rhs.input.emplace_back(lhs);
return rhs;
}
friend tempRule_t<reactant_t>& operator+(tempRule_t<reactant_t>& lhs, const reactant_t& rhs) {
lhs.input.emplace_back(rhs);
return lhs;
}
friend tempRule_t<reactant_t>& operator>>=(const reactant_t& lhs, const reactant_t& rhs) {
auto rule = new tempRule_t<reactant_t>;
rule->input = {lhs};
rule->output = {rhs};
return *rule;
}
friend tempRule_t<reactant_t>& operator>>=(tempRule_t<reactant_t>& lhs, const reactant_t& rhs) {
lhs.output = {rhs};
return lhs;
}
friend tempRule_t<reactant_t>& operator>>=(const reactant_t& lhs, tempRule_t<reactant_t>& rhs) {
auto rule = new tempRule_t<reactant_t>;
rule->input = {lhs};
rule->output = rhs.input;
delete &rhs;
return *rule;
}
friend tempRule_t<reactant_t>& operator>>=(tempRule_t<reactant_t>& lhs, tempRule_t<reactant_t>& rhs) {
auto rule = new tempRule_t<reactant_t>;
rule->input = lhs.input;
rule->output = rhs.input;
delete &lhs;
delete &rhs;
return *rule;
}
friend tempRule_t<reactant_t>& operator*(int scalar, const reactant_t& rhs) {
auto rule = new tempRule_t<reactant_t>;
for (int i = 0; i < scalar; ++i) {
rule->input.push_back(rhs);
}
return *rule;
}
std::string toDigraphElement() {
auto s = "\t" + name + "[label=\"" + name + "\", shape=\"box\", style=\"filled\", fillcolor=\"cyan\"];\n";
return s;
}
};
#endif //EXAM_REACTANT_T_H