Expression Templates Library (ETL)
deserializer.hpp
1 //=======================================================================
2 // Copyright (c) 2014-2023 Baptiste Wicht
3 // Distributed under the terms of the MIT License.
4 // (See accompanying file LICENSE or copy at
5 // http://opensource.org/licenses/MIT)
6 //=======================================================================
7 
8 #pragma once
9 
10 namespace etl {
11 
15 template <typename Stream>
16 struct deserializer {
17  using stream_t = Stream;
18  using char_t = typename stream_t::char_type;
19 
21 
27  template <typename... Args>
28  explicit deserializer(Args&&... args) : stream(std::forward<Args>(args)...) {}
29 
35  template <typename T>
36  deserializer& operator>>(T& value) {
37  if constexpr (std::is_arithmetic_v<T>) {
38  stream.read(reinterpret_cast<char_t*>(&value), sizeof(T));
39  } else {
40  deserialize(*this, value);
41  }
42 
43  return *this;
44  }
45 };
46 
47 } //end of namespace etl
A deserializer for ETL expressions.
Definition: deserializer.hpp:16
deserializer & operator>>(T &value)
Reads a value of the given type from the stream.
Definition: deserializer.hpp:36
Stream stream_t
The type of stream to use.
Definition: deserializer.hpp:17
Root namespace for the ETL library.
Definition: adapter.hpp:15
void deserialize(deserializer< Stream > &is, dyn_matrix_impl< T, SO, D > &matrix)
Deserialize the given matrix using the given serializer.
Definition: dyn.hpp:704
stream_t stream
The stream.
Definition: deserializer.hpp:20
deserializer(Args &&... args)
Construct the deserializer by forwarding the arguments to the stream.
Definition: deserializer.hpp:28
typename stream_t::char_type char_t
The char type of the stream.
Definition: deserializer.hpp:18