Reaktoro  v2.13.0
A unified framework for modeling chemically reactive systems
Database.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/ElementList.hpp>
23 #include <Reaktoro/Core/Reaction.hpp>
24 #include <Reaktoro/Core/SpeciesList.hpp>
25 
26 namespace Reaktoro {
27 
31 class Database
32 {
33 public:
37  static auto fromFile(String const& path) -> Database;
38 
42  static auto fromEmbeddedFile(String const& path) -> Database;
43 
46  static auto fromContents(String const& text) -> Database;
47 
50  static auto fromStringYAML(String const& text) -> Database;
51 
54  static auto fromStringJSON(String const& text) -> Database;
55 
58  static auto fromStream(std::istream& stream) -> Database;
59 
61  static auto local(String const& path) -> Database;
62 
64  static auto embedded(String const& path) -> Database;
65 
68 
70  Database(Database const& other);
71 
74 
76  explicit Database(Vec<Species> const& species);
77 
80 
82  auto operator=(Database other) -> Database&;
83 
85  auto clear() -> void;
86 
90  auto addElement(Element const& element) -> void;
91 
95  auto addSpecies(Species const& species) -> void;
96 
98  auto addSpecies(Vec<Species> const& species) -> void;
99 
101  auto attachData(Any const& data) -> void;
102 
104  auto extend(Database const& other) -> void;
105 
107  auto extendWithDatabase(Database const& other) -> void;
108 
112  auto extendWithFile(String const& path) -> void;
113 
115  auto elements() const -> ElementList const&;
116 
118  auto species() const -> SpeciesList const&;
119 
122 
125  auto element(String const& symbol) const -> Element const&;
126 
129  auto species(String const& name) const -> Species const&;
130 
133  auto reaction(String const& equation) const -> Reaction;
134 
136  auto attachedData() const -> Any const&;
137 
138 private:
139  struct Impl;
140 
141  Ptr<Impl> pimpl;
142 };
143 
144 } // namespace Reaktoro
The class used to store and retrieve data of chemical species.
Definition: Database.hpp:32
auto element(String const &symbol) const -> Element const &
Return an element with given symbol in the database.
auto reaction(String const &equation) const -> Reaction
Construct a reaction with given equation.
static auto fromContents(String const &text) -> Database
Return a Database object constructed with given database text contents.
static auto embedded(String const &path) -> Database
Return a Database object constructed with a given embedded file.
auto extendWithFile(String const &path) -> void
Extend this database with elements, species and other contents from another database.
~Database()
Destroy this Database object.
Database(Vec< Element > const &elements, Vec< Species > const &species)
Construct a Database object with given elements and species.
auto addSpecies(Vec< Species > const &species) -> void
Add a list of species in the database.
auto clear() -> void
Remove all species and elements from the database.
auto addSpecies(Species const &species) -> void
Add a species in the database.
auto addElement(Element const &element) -> void
Add an element in the database.
Database()
Construct a default Database object.
static auto fromStringYAML(String const &text) -> Database
Return a Database object constructed with given database text in YAML format.
static auto fromEmbeddedFile(String const &path) -> Database
Return a Database object constructed with a given embedded file.
auto speciesWithAggregateState(AggregateState option) const -> SpeciesList
Return all species in the database with given aggregate state.
auto extendWithDatabase(Database const &other) -> void
Extend this database with elements, species and other contents from another database.
auto species() const -> SpeciesList const &
Return all species in the database.
static auto fromStream(std::istream &stream) -> Database
Return a Database object constructed with given input stream containing the database text contents.
auto extend(Database const &other) -> void
Extend this database with elements, species and other contents from another database.
Database(Vec< Species > const &species)
Construct a Database object with given species (elements extracted from them).
static auto fromStringJSON(String const &text) -> Database
Return a Database object constructed with given database text in JSON format.
static auto local(String const &path) -> Database
Return a Database object constructed with a given local file.
auto operator=(Database other) -> Database &
Assign another Database object to this.
auto attachedData() const -> Any const &
Return the attached data to this database whose type is known at runtime only.
Database(Database const &other)
Construct a copy of a Database object.
auto elements() const -> ElementList const &
Return all elements in the database.
static auto fromFile(String const &path) -> Database
Return a Database object constructed with a given local file.
auto attachData(Any const &data) -> void
Attach data to this database whose type is known at runtime only.
A type used as a collection of elements.
Definition: ElementList.hpp:28
A type used to define a element and its attributes.
Definition: Element.hpp:28
A class to represent a reaction and its attributes.
Definition: Reaction.hpp:42
A type used as a collection of species.
Definition: SpeciesList.hpp:29
A type used to represent a chemical species and its attributes.
Definition: Species.hpp:35
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
AggregateState
The aggregate states of substances according to IUPAC.
Definition: AggregateState.hpp:32
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::unique_ptr< T > Ptr
Convenient alias for std::unique_ptr<T>.
Definition: Types.hpp:102
std::any Any
Convenient alias for std::any.
Definition: Types.hpp:125