forked from gfrd/egfrd
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReactionRecord.hpp
More file actions
126 lines (110 loc) · 3.47 KB
/
ReactionRecord.hpp
File metadata and controls
126 lines (110 loc) · 3.47 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef REACTION_RECORD_HPP
#define REACTION_RECORD_HPP
#include <vector>
#include "twofold_container.hpp"
#include "utils/memberwise_compare.hpp"
template<typename Tpid_, typename Trid_>
class ReactionRecord
{
public:
typedef Tpid_ particle_id_type;
typedef Trid_ reaction_rule_id_type;
typedef std::vector<particle_id_type> products_type;
typedef twofold_container<particle_id_type> reactants_type;
public:
ReactionRecord()
: reaction_rule_id_(), reactants_(), products_() {}
template<typename Tset>
ReactionRecord(reaction_rule_id_type const& rid,
Tset const& products,
particle_id_type const& p1)
: reaction_rule_id_(rid), reactants_(p1),
products_(boost::begin(products), boost::end(products)) {}
template<typename Tset>
ReactionRecord(reaction_rule_id_type const& rid,
Tset const& products,
particle_id_type const& p1, particle_id_type const& p2)
: reaction_rule_id_(rid), reactants_(p1, p2),
products_(boost::begin(products), boost::end(products)) {}
// HEADS UP: move constructor!
ReactionRecord(ReactionRecord const& that)
{
swap(const_cast<ReactionRecord&>(that));
}
reaction_rule_id_type const& reaction_rule_id() const
{
return reaction_rule_id_;
}
reactants_type const& reactants() const
{
return reactants_;
}
products_type const& products() const
{
return products_;
}
operator bool() const
{
return reactants_.size() != 0;
}
bool operator==(ReactionRecord const& rhs) const
{
return reaction_rule_id_ == rhs.reaction_rule_id() &&
memberwise_compare(reactants_, rhs.reactants_) == 0 &&
memberwise_compare(products_, rhs.products_) == 0;
}
bool operator!=(ReactionRecord const& rhs) const
{
return !operator==(rhs);
}
void swap(ReactionRecord& that)
{
std::swap(reaction_rule_id_, that.reaction_rule_id_);
reactants_.swap(that.reactants_);
products_.swap(that.products_);
}
protected:
reaction_rule_id_type reaction_rule_id_;
reactants_type reactants_;
products_type products_;
};
template<typename Tchar, typename Ttraits, typename Tpid, typename Trid>
inline std::basic_ostream<Tchar, Ttraits>&
operator<<(std::basic_ostream<Tchar, Ttraits>& out,
ReactionRecord<Tpid, Trid> const& r)
{
bool first;
out << "ReactionRecord(reaction_rule_id=" << r.reaction_rule_id() << ", ";
out << "reactants={";
typedef typename ReactionRecord<Tpid, Trid>::reactants_type reactants_type;
typedef typename ReactionRecord<Tpid, Trid>::products_type products_type;
reactants_type const& reactants(r.reactants());
for (typename boost::range_const_iterator<reactants_type>::type
i(boost::begin(reactants)), e(boost::end(reactants));
i != e; ++i)
{
if (!first)
{
out << ", ";
}
out << *i;
first = false;
}
out << "}, products={";
first = true;
products_type const& products(r.products());
for (typename boost::range_const_iterator<products_type>::type
i(boost::begin(products)), e(boost::end(products));
i != e; ++i)
{
if (!first)
{
out << ", ";
}
out << *i;
first = false;
}
out << "})";
return out;
}
#endif /* REACTION_RECORD_HPP */