Line | Branch | Exec | Source |
---|---|---|---|
1 | // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de> | ||
2 | // SPDX-License-Identifier: MIT | ||
3 | /*! | ||
4 | * \file | ||
5 | * \ingroup Common | ||
6 | * \copydoc GridFormat::BufferField | ||
7 | */ | ||
8 | #ifndef GRIDFORMAT_COMMON_BUFFER_FIELD_HPP_ | ||
9 | #define GRIDFORMAT_COMMON_BUFFER_FIELD_HPP_ | ||
10 | |||
11 | #include <ranges> | ||
12 | #include <utility> | ||
13 | |||
14 | #include <gridformat/common/field.hpp> | ||
15 | #include <gridformat/common/md_layout.hpp> | ||
16 | #include <gridformat/common/precision.hpp> | ||
17 | #include <gridformat/common/serialization.hpp> | ||
18 | #include <gridformat/common/exceptions.hpp> | ||
19 | #include <gridformat/common/concepts.hpp> | ||
20 | |||
21 | namespace GridFormat { | ||
22 | |||
23 | //! Field implementation around a flat buffer and corresponding layout | ||
24 | template<Concepts::Scalar T> | ||
25 | class BufferField : public Field { | ||
26 | public: | ||
27 | template<Concepts::MDRange<1> R> | ||
28 | requires(Concepts::Scalar<std::ranges::range_value_t<R>>) | ||
29 | 17917 | explicit BufferField(R&& data, MDLayout&& layout) | |
30 |
1/2✓ Branch 1 taken 8961 times.
✗ Branch 2 not taken.
|
17917 | : _serialization(layout.number_of_entries()*sizeof(T)) |
31 |
1/2✓ Branch 2 taken 8961 times.
✗ Branch 3 not taken.
|
17917 | , _md_layout{std::move(layout)}, |
32 |
2/4✓ Branch 2 taken 8961 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8961 times.
✗ Branch 6 not taken.
|
35834 | _span{_serialization.template as_span_of<T>()} { |
33 |
3/4✓ Branch 2 taken 8961 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 8960 times.
|
17917 | if (data.size() != _md_layout.number_of_entries()) |
34 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | throw SizeError("Given buffer size does not match layout"); |
35 |
2/4✓ Branch 1 taken 8960 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 8960 times.
✗ Branch 7 not taken.
|
17916 | std::ranges::move(std::move(data), _serialization.as_span_of<T>().data()); |
36 | 17919 | } | |
37 | |||
38 | std::size_t number_of_entries() const { | ||
39 | return _span.size(); | ||
40 | } | ||
41 | |||
42 | private: | ||
43 | 40784 | MDLayout _layout() const { | |
44 | 40784 | return _md_layout; | |
45 | } | ||
46 | |||
47 | 39568 | DynamicPrecision _precision() const { | |
48 | 39568 | return {Precision<T>{}}; | |
49 | } | ||
50 | |||
51 | 12213 | Serialization _serialized() const { | |
52 | 12213 | return _serialization; | |
53 | } | ||
54 | |||
55 | Serialization _serialization; | ||
56 | MDLayout _md_layout; | ||
57 | std::span<T> _span; | ||
58 | }; | ||
59 | |||
60 | template<Concepts::MDRange<1> R> | ||
61 | requires(Concepts::Scalar<std::ranges::range_value_t<R>>) | ||
62 | BufferField(R&&, MDLayout&&) -> BufferField<std::ranges::range_value_t<R>>; | ||
63 | |||
64 | } // namespace GridFormat | ||
65 | |||
66 | #endif // GRIDFORMAT_COMMON_BUFFER_FIELD_HPP_ | ||
67 |