Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
ElementList.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/Element.hpp>
23 
24 namespace Reaktoro {
25 
28 {
29 public:
32 
34  ElementList(std::initializer_list<Element> elements);
35 
37  ElementList(const Vec<Element>& elements);
38 
40  auto append(const Element& element) -> void;
41 
43  auto data() const -> const Vec<Element>&;
44 
46  auto empty() const -> bool;
47 
49  auto size() const -> Index;
50 
52  auto operator[](Index i) const -> const Element&;
53 
55  auto find(const String& symbol) const -> Index;
56 
58  auto findWithSymbol(const String& symbol) const -> Index;
59 
61  auto findWithName(const String& name) const -> Index;
62 
64  auto index(const String& symbol) const -> Index;
65 
67  auto indexWithSymbol(const String& symbol) const -> Index;
68 
70  auto indexWithName(const String& name) const -> Index;
71 
73  auto get(const String& symbol) const -> const Element&;
74 
76  auto getWithSymbol(const String& symbol) const -> const Element&;
77 
79  auto getWithName(const String& name) const -> const Element&;
80 
82  auto withSymbols(const StringList& symbols) const -> ElementList;
83 
85  auto withNames(const StringList& names) const -> ElementList;
86 
88  auto withTag(const String& tag) const -> ElementList;
89 
91  auto withoutTag(const String& tag) const -> ElementList;
92 
94  auto withTags(const StringList& tags) const -> ElementList;
95 
97  auto withoutTags(const StringList& tags) const -> ElementList;
98 
100  operator Vec<Element>&();
101 
103  operator Vec<Element>const&() const;
104 
105 private:
107  Vec<Element> m_elements;
108 
109 public:
111  template<typename InputIterator>
112  ElementList(InputIterator begin, InputIterator end) : m_elements(begin, end) {}
113 
115  auto begin() const { return m_elements.begin(); }
116 
118  auto begin() { return m_elements.begin(); }
119 
121  auto end() const { return m_elements.end(); }
122 
124  auto end() { return m_elements.end(); }
125 
127  auto push_back(const Element& elements) -> void { append(elements); }
128 
130  template<typename Iterator, typename InputIterator>
131  auto insert(Iterator pos, InputIterator begin, InputIterator end) -> void { m_elements.insert(pos, begin, end); }
132 
135 };
136 
138 auto operator+(const ElementList& a, const ElementList& b) -> ElementList;
139 
140 } // namespace Reaktoro
A type used as a collection of elements.
Definition: ElementList.hpp:28
auto push_back(const Element &elements) -> void
Append a new Element at the back of the container (for STL compatibility reasons).
Definition: ElementList.hpp:127
auto withoutTag(const String &tag) const -> ElementList
Return all elements without a given tag.
auto getWithName(const String &name) const -> const Element &
Return the element with given name.
auto findWithName(const String &name) const -> Index
Return the index of the first element with given unique name or the number of elements if not found.
auto data() const -> const Vec< Element > &
Return the internal collection of Element objects.
auto index(const String &symbol) const -> Index
Return the index of the first element with given symbol or throw a runtime error if not found.
auto withTags(const StringList &tags) const -> ElementList
Return all elements with given tags.
auto empty() const -> bool
Return true if there are no elements in the collection.
auto withTag(const String &tag) const -> ElementList
Return all elements with a given tag.
ElementList(std::initializer_list< Element > elements)
Construct an ElementList object with given elements.
auto find(const String &symbol) const -> Index
Return the index of the first element with given symbol or the number of elements if not found.
auto findWithSymbol(const String &symbol) const -> Index
Return the index of the first element with given symbol or the number of elements if not found.
auto indexWithName(const String &name) const -> Index
Return the index of the first element with given unique name or throw a runtime error if not found.
auto end()
Return end iterator of this ElementList instance (for STL compatibility reasons).
Definition: ElementList.hpp:124
auto withoutTags(const StringList &tags) const -> ElementList
Return all elements without given tags.
auto withNames(const StringList &names) const -> ElementList
Return all elements with given names.
auto indexWithSymbol(const String &symbol) const -> Index
Return the index of the first element with given symbol or throw a runtime error if not found.
ElementList(const Vec< Element > &elements)
Construct an ElementList object with given elements.
auto append(const Element &element) -> void
Append a new element to the list of elements.
auto get(const String &symbol) const -> const Element &
Return the element with given symbol.
auto getWithSymbol(const String &symbol) const -> const Element &
Return the element with given symbol.
ElementList()
Construct a default ElementList object.
auto insert(Iterator pos, InputIterator begin, InputIterator end) -> void
Insert a container of Element objects into this ElementList instance (for STL compatibility reasons).
Definition: ElementList.hpp:131
auto begin() const
Return begin const iterator of this ElementList instance (for STL compatibility reasons).
Definition: ElementList.hpp:115
auto begin()
Return begin iterator of this ElementList instance (for STL compatibility reasons).
Definition: ElementList.hpp:118
auto withSymbols(const StringList &symbols) const -> ElementList
Return all elements with given symbols.
auto end() const
Return end const iterator of this ElementList instance (for STL compatibility reasons).
Definition: ElementList.hpp:121
auto size() const -> Index
Return the number of elements in the collection.
A type used to define a element and its attributes.
Definition: Element.hpp:28
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