-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreaction.h
More file actions
77 lines (61 loc) · 2.33 KB
/
reaction.h
File metadata and controls
77 lines (61 loc) · 2.33 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
//
// Created by jskad on 10-06-2024.
//
#ifndef STOCHASTIC_SIMULATION_REACTION_H
#define STOCHASTIC_SIMULATION_REACTION_H
#endif //STOCHASTIC_SIMULATION_REACTION_H
#include "string"
#include "vector"
#include <iostream>
#include <ranges>
#include <algorithm>
namespace stochastic {
// Requirement 1
class PartialReaction{
public:
PartialReaction(std::vector<std::string> inputs, double rate) : inputs(std::move(inputs)), rate(rate) {}
std::vector<std::string> inputs;
double rate;
};
class Reaction{
public:
Reaction(PartialReaction _partial, std::vector<std::string> _products) : inputs(std::move(_partial.inputs)), products(std::move(_products)), rate(_partial.rate) {}
const std::vector<std::string> inputs;
const std::vector<std::string> products;
const double rate;
double delay;
friend std::ostream& operator<<(std::ostream& os, const Reaction& r); //Give << access to our privates *wink wink*
};
// Overload +, >> and >>=
inline std::vector<std::string> operator+(const std::string& left, const std::string& right) {
return {left, right};
}
inline std::vector<std::string> operator+(std::vector<std::string> left, const std::string& right) {
left.push_back(right);
return left;
}
inline PartialReaction operator>>(const std::vector<std::string>& inputs, double rate) {
return {inputs, rate};
}
inline PartialReaction operator>>(const std::string& input, double rate) {
return {std::vector<std::string>{input}, rate};
}
inline Reaction operator>>=(const PartialReaction& partial, const std::vector<std::string>& products) {
return {partial, products};
}
inline Reaction operator>>=(const PartialReaction& partial, const std::string& product) {
return {partial, std::vector<std::string>{product}};
}
inline std::ostream& operator<<(std::ostream& os, const Reaction& r) {
for (size_t i = 0; i < r.inputs.size(); ++i) {
os << r.inputs[i];
if (i != r.inputs.size() - 1) os << " + ";
}
os << " -[" << r.rate << "]-> ";
for (size_t i = 0; i < r.products.size(); ++i) {
os << r.products[i];
if (i != r.products.size() - 1) os << " + ";
}
return os;
}
}