Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
ReactionList.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright © 2014-2024 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // Reaktoro includes
21 #include <Reaktoro/Common/Types.hpp>
22 #include <Reaktoro/Core/Reaction.hpp>
23 #include <Reaktoro/Core/SpeciesList.hpp>
24 
25 namespace Reaktoro {
26 
29 {
30 public:
33 
35  ReactionList(std::initializer_list<Reaction> reactions);
36 
38  ReactionList(const Vec<Reaction>& reactions);
39 
41  auto append(const Reaction& reaction) -> void;
42 
44  auto data() const -> const Vec<Reaction>&;
45 
47  auto empty() const -> bool;
48 
50  auto size() const -> Index;
51 
53  auto operator[](Index i) const -> const Reaction&;
54 
56  auto operator[](Index i) -> Reaction&;
57 
59  auto find(const String& name) const -> Index;
60 
62  auto findWithName(const String& name) const -> Index;
63 
65  auto index(const String& name) const -> Index;
66 
68  auto indexWithName(const String& name) const -> Index;
69 
71  auto get(const String& name) const -> const Reaction&;
72 
74  auto getWithName(const String& name) const -> const Reaction&;
75 
77  auto withNames(const StringList& names) const -> ReactionList;
78 
80  operator Vec<Reaction>&();
81 
83  operator Vec<Reaction>const&() const;
84 
85 private:
87  Vec<Reaction> m_reactions;
88 
89 public:
91  template<typename InputIterator>
92  ReactionList(InputIterator begin, InputIterator end) : m_reactions(begin, end) {}
93 
95  auto begin() const { return m_reactions.begin(); }
96 
98  auto begin() { return m_reactions.begin(); }
99 
101  auto end() const { return m_reactions.end(); }
102 
104  auto end() { return m_reactions.end(); }
105 
107  auto push_back(const Reaction& species) -> void { append(species); }
108 
110  template<typename Iterator, typename InputIterator>
111  auto insert(Iterator pos, InputIterator begin, InputIterator end) -> void { m_reactions.insert(pos, begin, end); }
112 
115 };
116 
118 auto operator+(const ReactionList& a, const ReactionList& b) -> ReactionList;
119 
120 } // namespace Reaktoro
A type used as a collection of reactions.
Definition: ReactionList.hpp:29
auto find(const String &name) const -> Index
Return the index of the reaction with given unique name or the number of reactions if not found.
auto findWithName(const String &name) const -> Index
Return the index of the reaction with given unique name or the number of reactions if not found.
auto withNames(const StringList &names) const -> ReactionList
Return all reactions with given names.
auto empty() const -> bool
Return true if there are no reactions in the collection.
auto indexWithName(const String &name) const -> Index
Return the index of the reaction with given unique name or throw a runtime error if not found.
auto getWithName(const String &name) const -> const Reaction &
Return the reaction with a given name.
auto end()
Return end iterator of this ReactionList instance (for STL compatibility reasons).
Definition: ReactionList.hpp:104
ReactionList()
Construct a default ReactionList object.
auto push_back(const Reaction &species) -> void
Append a new Reaction at the back of the container (for STL compatibility reasons).
Definition: ReactionList.hpp:107
ReactionList(const Vec< Reaction > &reactions)
Construct an ReactionList object with given reactions.
auto get(const String &name) const -> const Reaction &
Return the reaction with a given name.
auto append(const Reaction &reaction) -> void
Append a new reaction to the list of reaction.
auto insert(Iterator pos, InputIterator begin, InputIterator end) -> void
Insert a container of Reaction objects into this ReactionList instance (for STL compatibility reasons...
Definition: ReactionList.hpp:111
auto begin() const
Return begin const iterator of this ReactionList instance (for STL compatibility reasons).
Definition: ReactionList.hpp:95
auto begin()
Return begin iterator of this ReactionList instance (for STL compatibility reasons).
Definition: ReactionList.hpp:98
auto end() const
Return end const iterator of this ReactionList instance (for STL compatibility reasons).
Definition: ReactionList.hpp:101
auto size() const -> Index
Return the number of reactions in the collection.
auto index(const String &name) const -> Index
Return the index of the reaction with given unique name or throw a runtime error if not found.
auto data() const -> const Vec< Reaction > &
Return the internal collection of Reaction objects.
ReactionList(std::initializer_list< Reaction > reactions)
Construct an ReactionList object with given reactions.
A class to represent a reaction and its attributes.
Definition: Reaction.hpp:42
A class for representing a list of strings with special constructors.
Definition: StringList.hpp:28
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
std::vector< T > Vec
Convenient alias for std::vector<T>.
Definition: Types.hpp:66
std::string String
Convenient alias for std::string.
Definition: Types.hpp:52
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
auto operator+(const typename Derived::Scalar &scalar, const Eigen::MatrixBase< Derived > &mat) -> decltype((scalar+mat.array()).matrix())
Return the component-wise division of two matrices.
Definition: Matrix.hpp:774