Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
ArrayStream.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/ArraySerialization.hpp>
22 
23 namespace Reaktoro {
24 
26 template<typename T>
28 {
29 public:
32 
34  ArrayStream() = default;
35 
37  template<typename... Args>
38  ArrayStream(const Args&... args)
39  {
40  ArraySerialization::resize(array, args...);
41  ArraySerialization::serialize(array, args...);
42  }
43 
45  template<typename... Args>
46  auto from(const Args&... args)
47  {
48  ArraySerialization::resize(array, args...);
49  ArraySerialization::serialize(array, args...);
50  }
51 
53  template<typename... Args>
54  auto to(Args&... args) const
55  {
56  ArraySerialization::deserialize(array, args...);
57  }
58 
59  auto data() const -> const ArrayType&
60  {
61  return array;
62  }
63 
64  operator const ArrayType&() const
65  {
66  return array;
67  }
68 
69 private:
71  ArrayType array;
72 };
73 
74 } // namespace Reaktoro
The class used to serialize/deserialize data using array.
Definition: ArrayStream.hpp:28
ArrayStream(const Args &... args)
Construct an ArrayStream object with given list of scalars and/or arrays.
Definition: ArrayStream.hpp:38
auto from(const Args &... args)
Initialize this ArrayStream object with given list of scalars and/or arrays.
Definition: ArrayStream.hpp:46
auto to(Args &... args) const
Transfer this ArrayStream object data to given list of scalars and/or arrays.
Definition: ArrayStream.hpp:54
ArrayX< Decay< T > > ArrayType
The array type used to store data.
Definition: ArrayStream.hpp:31
ArrayStream()=default
Construct a default ArrayStream object.
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
Eigen::Array< T, -1, 1, 0, -1, 1 > ArrayX
Convenient alias to Eigen type.
Definition: Matrix.hpp:46
constexpr static auto serialize(Array &array, const Args &... args) -> void
Copy the data in args into array.
Definition: ArraySerialization.hpp:134
constexpr static auto resize(Array &array, const Args &... args) -> void
Resize array so that it can store the data in args.
Definition: ArraySerialization.hpp:126
constexpr static auto deserialize(const Array &array, Args &... args) -> void
Copy the data in array to args.
Definition: ArraySerialization.hpp:141