Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
ChemicalFormula.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 
23 namespace Reaktoro {
24 
27 {
28 public:
31 
34  ChemicalFormula(const char* formula);
35 
39 
45 
47  auto str() const -> const String&;
48 
50  auto elements() const -> const Pairs<String, double>&;
51 
53  auto symbols() const -> Strings;
54 
56  auto coefficients() const -> Vec<double>;
57 
59  auto coefficient(const String& symbol) const -> double;
60 
62  auto charge() const -> double;
63 
67  auto molarMass() const -> double;
68 
75  auto equivalent(const ChemicalFormula& other) const -> bool;
76 
78  static auto equivalent(const ChemicalFormula& f1, const ChemicalFormula& f2) -> bool;
79 
81  operator String() const;
82 
84  operator Pairs<String, double>() const;
85 
86 private:
87  struct Impl;
88 
89  SharedPtr<Impl> pimpl;
90 };
91 
93 auto operator<<(std::ostream& out, const ChemicalFormula& formula) -> std::ostream&;
94 
96 auto operator<(const ChemicalFormula& lhs, const ChemicalFormula& rhs) -> bool;
97 
99 auto operator==(const ChemicalFormula& lhs, const ChemicalFormula& rhs) -> bool;
100 
101 } // namespace Reaktoro
A type used to represent the chemical formula of a chemical species.
Definition: ChemicalFormula.hpp:27
ChemicalFormula(const char *formula)
Construct a ChemicalFormula object with given formula.
auto molarMass() const -> double
Return the molar mass of the chemical formula (in kg/mol).
auto symbols() const -> Strings
Return the element symbols in the chemical formula.
auto equivalent(const ChemicalFormula &other) const -> bool
Return true if another chemical formula is equivalent to this one.
auto elements() const -> const Pairs< String, double > &
Return the element symbols and their coefficients in the chemical formula.
ChemicalFormula(String formula)
Construct a ChemicalFormula object with given formula.
ChemicalFormula(String formula, Pairs< String, double > symbols, double charge)
Construct a ChemicalFormula object with given formula, element symbols, and charge.
ChemicalFormula()
Construct a default ChemicalFormula object.
auto str() const -> const String &
Return the chemical formula of the substance as a string.
auto charge() const -> double
Return the electric charge of the chemical formula.
auto coefficients() const -> Vec< double >
Return the coefficients of the elements in the chemical formula.
auto coefficient(const String &symbol) const -> double
Return the coefficient of an element symbol in the chemical formula.
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
Vec< Pair< T, U > > Pairs
Convenient alias for std::vector<std::pair<T, U>>.
Definition: Types.hpp:90
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::vector< std::string > Strings
Convenient alias for std::vector<String>.
Definition: Types.hpp:55
std::shared_ptr< T > SharedPtr
Convenient alias for std::shared_ptr<T>.
Definition: Types.hpp:106