Reaktoro
A unified framework for modeling chemically reactive systems
ReactionEquation.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2018 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 // C++ includes
21 #include <string>
22 #include <map>
23 
24 namespace Reaktoro {
25 
36 {
37 public:
40 
51  ReactionEquation(std::string equation);
52 
56  ReactionEquation(const std::map<std::string, double>& equation);
57 
59  auto empty() const -> bool;
60 
62  auto numSpecies() const -> unsigned;
63 
66  auto stoichiometry(std::string species) const -> double;
67 
69  auto equation() const -> const std::map<std::string, double>&;
70 
72  operator std::string() const;
73 
74 private:
76  std::string equation_str;
77 
79  std::map<std::string, double> equation_map;
80 };
81 
83 auto operator<<(std::ostream& out, const ReactionEquation& equation) -> std::ostream&;
84 
86 inline auto begin(const Reaktoro::ReactionEquation& equation) -> decltype(equation.equation().begin())
87 {
88  return equation.equation().begin();
89 }
90 
92 inline auto begin(Reaktoro::ReactionEquation& equation) -> decltype(equation.equation().begin())
93 {
94  return equation.equation().begin();
95 }
96 
98 inline auto end(const Reaktoro::ReactionEquation& equation) -> decltype(equation.equation().end())
99 {
100  return equation.equation().end();
101 }
102 
104 inline auto end(Reaktoro::ReactionEquation& equation) -> decltype(equation.equation().end())
105 {
106  return equation.equation().end();
107 }
108 
109 } // namespace Reaktoro
110 
auto begin(const Reaktoro::ReactionEquation &equation) -> decltype(equation.equation().begin())
Return begin const iterator of a ReactionEquation instance.
Definition: ReactionEquation.hpp:86
ReactionEquation()
Construct a default ReactionEquation instance.
Definition: ReactionEquation.cpp:29
auto equation() const -> const std::map< std::string, double > &
Return the reaction equation as a map of species names and stoichiometries.
Definition: ReactionEquation.cpp:119
auto end(const Reaktoro::ReactionEquation &equation) -> decltype(equation.equation().end())
Return end const iterator of a ReactionEquation instance.
Definition: ReactionEquation.hpp:98
Define a type that describes the equation of a reaction.
Definition: ReactionEquation.hpp:36
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto stoichiometry(std::string species) const -> double
Return the stoichiometry of a species in the reaction equation.
Definition: ReactionEquation.cpp:113
auto numSpecies() const -> unsigned
Return the number of species in the reaction equation.
Definition: ReactionEquation.cpp:108
auto empty() const -> bool
Return true if the rection equation is empty.
Definition: ReactionEquation.cpp:103