GridFormat
0.6.0
I/O-Library for grid-like data structures
Toggle main menu visibility
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
16
#include <
gridformat/common/field.hpp
>
17
#include <gridformat/common/precision.hpp>
18
#include <gridformat/common/exceptions.hpp>
19
#include <
gridformat/encoding/concepts.hpp
>
20
21
namespace
GridFormat {
22
27
template
<std::derived_from<Field> F, Concepts::Encoder<std::ostream> Encoder>
28
class
EncodedField {
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
50
template
<
typename
F,
typename
Enc>
51
EncodedField
(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_
GridFormat::EncodedField
Wraps a field and makes it streamable using encoding.
Definition
encoded_field.hpp:28
concepts.hpp
Concepts related to data encoding.
field.hpp
Abstract interface for fields of values that is used by writers/readers to store fields.
gridformat
encoding
encoded_field.hpp
Generated by
1.18.0