21 #include <Reaktoro/Common/TraitsUtils.hpp>
22 #include <Reaktoro/Common/Matrix.hpp>
31 constexpr
auto isArray = isArrayAux<Decay<T>>::value;
36 template<
typename Scalar,
int Rows,
int Options,
int MaxRows>
37 struct isArrayAux<Eigen::
Array<Scalar, Rows, 1, Options, MaxRows, 1>> : std::true_type {};
39 template<
typename Scalar,
int Cols,
int Options,
int MaxCols>
40 struct isArrayAux<Eigen::
Array<Scalar, 1, Cols, Options, 1, MaxCols>> : std::true_type {};
42 template<
typename Scalar,
int Rows,
int Options,
int MaxRows>
43 struct isArrayAux<Eigen::Matrix<Scalar, Rows, 1, Options, MaxRows, 1>> : std::true_type {};
45 template<
typename Scalar,
int Cols,
int Options,
int MaxCols>
46 struct isArrayAux<Eigen::Matrix<Scalar, 1, Cols, Options, 1, MaxCols>> : std::true_type {};
48 template<
typename Vec,
int Size>
51 template<
typename Vec>
55 template<
typename Arg>
56 constexpr
auto length(
const Arg& x) -> std::size_t
58 if constexpr(isArray<Arg>)
63 template<
typename Arg,
typename... Args>
64 constexpr
auto length(
const Arg& x,
const Args&... xs) -> std::size_t
66 if constexpr(
sizeof...(Args) > 0)
67 return length(x) + length(xs...);
68 else return length(x);
71 template<typename
Array, typename Arg>
72 constexpr auto serialize(
Array& array, std::
size_t pos, const Arg& x) ->
void
74 using U = Decay<decltype(array[0])>;
76 if constexpr(isArray<Arg>)
78 assert(array.size() >= pos + x.size());
79 array.segment(pos, x.size()) = x.template cast<U>();
83 assert(array.size() >= pos + 1);
84 array[pos] =
static_cast<U
>(x);
88 template<
typename Array,
typename Arg,
typename... Args>
89 constexpr
auto serialize(
Array& array, std::size_t pos,
const Arg& x,
const Args&... xs) ->
void
91 serialize(array, pos, x);
92 if constexpr(
sizeof...(Args) > 0)
93 serialize(array, pos + length(x), xs...);
96 template<typename
Array, typename Arg>
97 constexpr auto deserialize(const
Array& array, std::
size_t pos, Arg& x) ->
void
99 if constexpr(isArray<Arg>)
101 assert(array.size() >= pos + x.size());
102 x = array.segment(pos, x.size());
106 assert(array.size() >= pos + 1);
111 template<
typename Array,
typename Arg,
typename... Args>
112 constexpr
auto deserialize(
const Array& array, std::size_t pos, Arg& x, Args&... xs) ->
void
114 deserialize(array, pos, x);
115 if constexpr(
sizeof...(Args) > 0)
116 deserialize(array, pos + length(x), xs...);
125 template<
typename Array,
typename... Args>
126 constexpr
static auto resize(
Array& array,
const Args&... args) ->
void
128 const auto size = detail::length(args...);
133 template<
typename Array,
typename... Args>
136 detail::serialize(array, 0, args...);
140 template<
typename Array,
typename... Args>
143 detail::deserialize(array, 0, args...);
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
std::array< T, N > Array
Convenient alias for std::array<T, N>.
Definition: Types.hpp:62
The class implementing methods to serialize/deserialize data into/from arrays.
Definition: ArraySerialization.hpp:123
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
Definition: TraitsUtils.hpp:100
Definition: ArraySerialization.hpp:34