HighFive 2.10.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
h5s_wrapper.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <H5Ipublic.h>
4#include <H5Spublic.h>
5namespace HighFive {
6namespace detail {
7
8inline hid_t h5s_create_simple(int rank, const hsize_t dims[], const hsize_t maxdims[]) {
9 hid_t space_id = H5Screate_simple(rank, dims, maxdims);
10 if (space_id == H5I_INVALID_HID) {
11 throw DataSpaceException("Unable to create simple dataspace");
12 }
13
14 return space_id;
15}
16
17inline hid_t h5s_create(H5S_class_t type) {
18 hid_t space_id = H5Screate(type);
19
20 if (space_id == H5I_INVALID_HID) {
21 throw DataSpaceException("Unable to create dataspace");
22 }
23
24 return space_id;
25}
26
27inline hid_t h5s_copy(hid_t space_id) {
28 hid_t copy_id = H5Scopy(space_id);
29
30 if (copy_id < 0) {
31 throw DataSpaceException("Unable to copy dataspace");
32 }
33
34 return copy_id;
35}
36
37inline herr_t h5s_select_none(hid_t spaceid) {
38 herr_t err = H5Sselect_none(spaceid);
39 if (err < 0) {
40 HDF5ErrMapper::ToException<DataSpaceException>("Unable to select None space");
41 }
42 return err;
43}
44
45inline herr_t h5s_select_hyperslab(hid_t space_id,
46 H5S_seloper_t op,
47 const hsize_t start[],
48 const hsize_t stride[],
49 const hsize_t count[],
50 const hsize_t block[]) {
51 herr_t err = H5Sselect_hyperslab(space_id, op, start, stride, count, block);
52 if (err < 0) {
53 HDF5ErrMapper::ToException<DataSpaceException>("Unable to select hyperslab");
54 }
55 return err;
56}
57
58inline hssize_t h5s_get_select_npoints(hid_t spaceid) {
59 hssize_t n_points = H5Sget_select_npoints(spaceid);
60 if (n_points < 0) {
62 "Unable to get number of points in selection");
63 }
64 return n_points;
65}
66
67inline herr_t h5s_select_elements(hid_t space_id,
68 H5S_seloper_t op,
69 size_t num_elem,
70 const hsize_t* coord) {
71 herr_t err = H5Sselect_elements(space_id, op, num_elem, coord);
72 if (err < 0) {
73 HDF5ErrMapper::ToException<DataSpaceException>("Unable to select elements");
74 }
75 return err;
76}
77
78inline int h5s_get_simple_extent_ndims(hid_t space_id) {
79 int ndim = H5Sget_simple_extent_ndims(space_id);
80 if (ndim < 0) {
82 "Unable to get number of dimensions of dataspace");
83 }
84 return ndim;
85}
86
87inline herr_t h5s_get_simple_extent_dims(hid_t space_id, hsize_t dims[], hsize_t maxdims[]) {
88 herr_t err = H5Sget_simple_extent_dims(space_id, dims, maxdims);
89 if (err < 0) {
90 HDF5ErrMapper::ToException<DataSetException>("Unable to get dimensions of dataspace");
91 }
92 return err;
93}
94
95inline hssize_t h5s_get_simple_extent_npoints(hid_t space_id) {
96 hssize_t nelements = H5Sget_simple_extent_npoints(space_id);
97 if (nelements < 0) {
99 "Unable to get number of elements in dataspace");
100 }
101
102 return nelements;
103}
104
105inline H5S_class_t h5s_get_simple_extent_type(hid_t space_id) {
106 H5S_class_t cls = H5Sget_simple_extent_type(space_id);
107 if (cls == H5S_NO_CLASS) {
108 HDF5ErrMapper::ToException<DataSpaceException>("Unable to get class of simple dataspace.");
109 }
110
111 return cls;
112}
113
114inline H5S_sel_type h5s_get_select_type(hid_t space_id) {
115 H5S_sel_type type = H5Sget_select_type(space_id);
116 if (type < 0) {
117 HDF5ErrMapper::ToException<DataSpaceException>("Unable to get type of selection.");
118 }
119
120 return type;
121}
122
123#if H5_VERSION_GE(1, 10, 6)
124inline hid_t h5s_combine_select(hid_t space1_id, H5S_seloper_t op, hid_t space2_id) {
125 auto space_id = H5Scombine_select(space1_id, op, space2_id);
126 if (space_id == H5I_INVALID_HID) {
127 HDF5ErrMapper::ToException<DataSpaceException>("Unable to combine two selections.");
128 }
129
130 return space_id;
131}
132#endif
133
134
135} // namespace detail
136} // namespace HighFive
Definition H5_definitions.hpp:22
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:43