Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
Element.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/StringList.hpp>
22 #include <Reaktoro/Common/Types.hpp>
23 
24 namespace Reaktoro {
25 
27 class Element
28 {
29 public:
31  struct Attribs
32  {
36 
41  double molar_mass = 0.0;
42 
46 
50  };
51 
54 
56  explicit Element(String symbol);
57 
59  explicit Element(const Attribs& attribs);
60 
62  auto clone() const -> Element;
63 
65  auto withSymbol(String symbol) const -> Element;
66 
68  auto withMolarMass(double value) const -> Element;
69 
71  auto withName(String name) const -> Element;
72 
74  auto withTags(const StringList& tags) const -> Element;
75 
77  auto symbol() const -> String;
78 
80  auto molarMass() const -> double;
81 
83  auto name() const -> String;
84 
86  auto tags() const -> const Strings&;
87 
88 private:
89  struct Impl;
90 
91  SharedPtr<Impl> pimpl;
92 };
93 
95 auto operator<(const Element& lhs, const Element& rhs) -> bool;
96 
98 auto operator==(const Element& lhs, const Element& rhs) -> bool;
99 
100 } // namespace Reaktoro
101 
102 // Custom specialization of std::hash for Reaktoro::Element
103 namespace std {
104 
105 template<>
106 struct hash<Reaktoro::Element>
107 {
108  std::size_t operator()(const Reaktoro::Element& e) const noexcept
109  {
110  return std::hash<std::string>{}(e.symbol());
111  }
112 };
113 
114 } // namespace std
A type used to define a element and its attributes.
Definition: Element.hpp:28
Element(const Attribs &attribs)
Construct an Element object with given attributes.
Element(String symbol)
Construct an Element object by looking up to the periodic table with given symbol.
auto molarMass() const -> double
Return the molar mass of the element (in kg/mol).
auto clone() const -> Element
Return a deep copy of this Element object.
auto withTags(const StringList &tags) const -> Element
Return a duplicate of this Element object with replaced tags attribute.
auto withSymbol(String symbol) const -> Element
Return a duplicate of this Element object with replaced symbol attribute.
Element()
Construct a default Element object.
auto withMolarMass(double value) const -> Element
Return a duplicate of this Element object with replaced molar mass attribute (in kg/mol).
auto name() const -> String
Return the name of the element (e.g., "Hydrogen", "Oxygen").
auto tags() const -> const Strings &
Return the tags of the element.
auto withName(String name) const -> Element
Return a duplicate of this Element object with replaced name attribute.
auto symbol() const -> String
Return the symbol of the element (e.g., "H", "O", "C", "Na").
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::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
The attributes of an Element object.
Definition: Element.hpp:32
String symbol
The symbol of the element (e.g., "H", "O", "C", "Na").
Definition: Element.hpp:35
double molar_mass
The molar mass of the element (in kg/mol).
Definition: Element.hpp:41
String name
The name of the element (e.g., "Hydrogen", "Oxygen").
Definition: Element.hpp:45
Strings tags
The tags of the element.
Definition: Element.hpp:49