|
10 | 10 | #pragma once |
11 | 11 |
|
12 | 12 | #include "bits/H5Inspector_decl.hpp" |
13 | | -#include "H5Exception.hpp" |
| 13 | +#include "bits/inspector_stl_span_misc.hpp" |
14 | 14 |
|
15 | 15 | #include <span> |
16 | 16 |
|
17 | 17 | namespace HighFive { |
18 | 18 | namespace details { |
19 | 19 |
|
20 | 20 | template <class T, std::size_t Extent> |
21 | | -struct inspector<std::span<T, Extent>> { |
22 | | - using type = std::span<T, Extent>; |
23 | | - using value_type = unqualified_t<T>; |
24 | | - using base_type = typename inspector<value_type>::base_type; |
25 | | - using hdf5_type = typename inspector<value_type>::hdf5_type; |
26 | | - |
27 | | - static constexpr size_t ndim = 1; |
28 | | - static constexpr size_t min_ndim = ndim + inspector<value_type>::min_ndim; |
29 | | - static constexpr size_t max_ndim = ndim + inspector<value_type>::max_ndim; |
30 | | - |
31 | | - static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value && |
32 | | - inspector<value_type>::is_trivially_nestable; |
33 | | - static constexpr bool is_trivially_nestable = false; |
34 | | - |
35 | | - |
36 | | - static size_t getRank(const type& val) { |
37 | | - if (!val.empty()) { |
38 | | - return ndim + inspector<value_type>::getRank(val[0]); |
39 | | - } else { |
40 | | - return min_ndim; |
41 | | - } |
42 | | - } |
43 | | - |
44 | | - static std::vector<size_t> getDimensions(const type& val) { |
45 | | - auto rank = getRank(val); |
46 | | - std::vector<size_t> sizes(rank, 1ul); |
47 | | - sizes[0] = val.size(); |
48 | | - if (!val.empty()) { |
49 | | - auto s = inspector<value_type>::getDimensions(val[0]); |
50 | | - assert(s.size() + ndim == sizes.size()); |
51 | | - for (size_t i = 0; i < s.size(); ++i) { |
52 | | - sizes[i + ndim] = s[i]; |
53 | | - } |
54 | | - } |
55 | | - return sizes; |
56 | | - } |
57 | | - |
58 | | - static void prepare(type& val, const std::vector<size_t>& expected_dims) { |
59 | | - auto actual_dims = getDimensions(val); |
60 | | - if (actual_dims.size() != expected_dims.size()) { |
61 | | - throw DataSpaceException("Mismatching rank."); |
62 | | - } |
63 | | - |
64 | | - for (size_t i = 0; i < actual_dims.size(); ++i) { |
65 | | - if (actual_dims[i] != expected_dims[i]) { |
66 | | - throw DataSpaceException("Mismatching dimensions."); |
67 | | - } |
68 | | - } |
69 | | - } |
70 | | - |
71 | | - static hdf5_type* data(type& val) { |
72 | | - return val.empty() ? nullptr : inspector<value_type>::data(val[0]); |
73 | | - } |
74 | | - |
75 | | - static const hdf5_type* data(const type& val) { |
76 | | - return val.empty() ? nullptr : inspector<value_type>::data(val[0]); |
77 | | - } |
78 | | - |
79 | | - template <class It> |
80 | | - static void serialize(const type& val, const std::vector<size_t>& dims, It m) { |
81 | | - if (!val.empty()) { |
82 | | - auto subdims = std::vector<size_t>(dims.begin() + ndim, dims.end()); |
83 | | - size_t subsize = compute_total_size(subdims); |
84 | | - for (const auto& e: val) { |
85 | | - inspector<value_type>::serialize(e, subdims, m); |
86 | | - m += subsize; |
87 | | - } |
88 | | - } |
89 | | - } |
90 | | - |
91 | | - template <class It> |
92 | | - static void unserialize(const It& vec_align, const std::vector<size_t>& dims, type& val) { |
93 | | - std::vector<size_t> subdims(dims.begin() + ndim, dims.end()); |
94 | | - size_t subsize = compute_total_size(subdims); |
95 | | - for (size_t i = 0; i < dims[0]; ++i) { |
96 | | - inspector<value_type>::unserialize(vec_align + i * subsize, subdims, val[i]); |
97 | | - } |
98 | | - } |
| 21 | +struct inspector<std::span<T, Extent>>: public inspector_stl_span<std::span<T, Extent>> { |
| 22 | + private: |
| 23 | + using super = inspector_stl_span<std::span<T, Extent>>; |
| 24 | + |
| 25 | + public: |
| 26 | + using type = typename super::type; |
| 27 | + using value_type = typename super::value_type; |
| 28 | + using base_type = typename super::base_type; |
| 29 | + using hdf5_type = typename super::hdf5_type; |
99 | 30 | }; |
100 | 31 |
|
101 | 32 | } // namespace details |
|
0 commit comments