GridFormat 0.2.1
I/O-Library for grid-like data structures
Loading...
Searching...
No Matches
encoded_field.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2// SPDX-License-Identifier: MIT
8#ifndef GRIDFORMAT_ENCODING_ENCODED_FIELD_HPP_
9#define GRIDFORMAT_ENCODING_ENCODED_FIELD_HPP_
10
11#include <utility>
12#include <ostream>
13#include <concepts>
14#include <type_traits>
15
17#include <gridformat/common/precision.hpp>
18#include <gridformat/common/exceptions.hpp>
20
21namespace GridFormat {
22
27template<std::derived_from<Field> F, Concepts::Encoder<std::ostream> Encoder>
29 public:
30 template<std::convertible_to<const F&> _F>
31 requires(std::is_lvalue_reference_v<_F>)
32 EncodedField(_F&& field, Encoder enc)
33 : _field(field)
34 , _encoder(std::move(enc))
35 {}
36
37 friend std::ostream& operator<<(std::ostream& s, const EncodedField& field) {
38 auto encoded = field._encoder(s);
39 field._field.visit_field_values([&] <typename T> (std::span<const T> data) {
40 encoded.write(data);
41 });
42 return s;
43 }
44
45 private:
46 const F& _field;
47 Encoder _encoder;
48};
49
50template<typename F, typename Enc>
51EncodedField(F&&, Enc&&) -> EncodedField<std::remove_cvref_t<F>, std::remove_cvref_t<Enc>>;
52
53} // namespace GridFormat
54
55#endif // GRIDFORMAT_ENCODING_ENCODED_FIELD_HPP_
Wraps a field and makes it streamable using encoding.
Definition: encoded_field.hpp:28
Concepts related to data encoding.