HighFive 2.9.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 <H5Spublic.h>
4namespace HighFive {
5namespace detail {
6
7inline hid_t h5s_create_simple(int rank, const hsize_t dims[], const hsize_t maxdims[]) {
8 hid_t space_id = H5Screate_simple(rank, dims, maxdims);
9 if (space_id == H5I_INVALID_HID) {
10 throw DataSpaceException("Unable to create simple dataspace");
11 }
12
13 return space_id;
14}
15
16inline hid_t h5s_create(H5S_class_t type) {
17 hid_t space_id = H5Screate(type);
18
19 if (space_id == H5I_INVALID_HID) {
20 throw DataSpaceException("Unable to create dataspace");
21 }
22
23 return space_id;
24}
25
26inline hid_t h5s_copy(hid_t space_id) {
27 hid_t copy_id = H5Scopy(space_id);
28
29 if (copy_id < 0) {
30 throw DataSpaceException("Unable to copy dataspace");
31 }
32
33 return copy_id;
34}
35
36inline herr_t h5s_select_none(hid_t spaceid) {
37 herr_t err = H5Sselect_none(spaceid);
38 if (err < 0) {
39 HDF5ErrMapper::ToException<DataSpaceException>("Unable to select None space");
40 }
41 return err;
42}
43
44inline herr_t h5s_select_hyperslab(hid_t space_id,
45 H5S_seloper_t op,
46 const hsize_t start[],
47 const hsize_t stride[],
48 const hsize_t count[],
49 const hsize_t block[]) {
50 herr_t err = H5Sselect_hyperslab(space_id, op, start, stride, count, block);
51 if (err < 0) {
52 HDF5ErrMapper::ToException<DataSpaceException>("Unable to select hyperslab");
53 }
54 return err;
55}
56
57inline hssize_t h5s_get_select_npoints(hid_t spaceid) {
58 hssize_t n_points = H5Sget_select_npoints(spaceid);
59 if (n_points < 0) {
61 "Unable to get number of points in selection");
62 }
63 return n_points;
64}
65
66inline herr_t h5s_select_elements(hid_t space_id,
67 H5S_seloper_t op,
68 size_t num_elem,
69 const hsize_t* coord) {
70 herr_t err = H5Sselect_elements(space_id, op, num_elem, coord);
71 if (err < 0) {
72 HDF5ErrMapper::ToException<DataSpaceException>("Unable to select elements");
73 }
74 return err;
75}
76
77inline int h5s_get_simple_extent_ndims(hid_t space_id) {
78 int ndim = H5Sget_simple_extent_ndims(space_id);
79 if (ndim < 0) {
81 "Unable to get number of dimensions of dataspace");
82 }
83 return ndim;
84}
85
86inline herr_t h5s_get_simple_extent_dims(hid_t space_id, hsize_t dims[], hsize_t maxdims[]) {
87 herr_t err = H5Sget_simple_extent_dims(space_id, dims, maxdims);
88 if (err < 0) {
89 HDF5ErrMapper::ToException<DataSetException>("Unable to get dimensions of dataspace");
90 }
91 return err;
92}
93
94inline hssize_t h5s_get_simple_extent_npoints(hid_t space_id) {
95 hssize_t nelements = H5Sget_simple_extent_npoints(space_id);
96 if (nelements < 0) {
98 "Unable to get number of elements in dataspace");
99 }
100
101 return nelements;
102}
103
104inline H5S_class_t h5s_get_simple_extent_type(hid_t space_id) {
105 H5S_class_t cls = H5Sget_simple_extent_type(space_id);
106 if (cls == H5S_NO_CLASS) {
107 HDF5ErrMapper::ToException<DataSpaceException>("Unable to get class of simple dataspace.");
108 }
109
110 return cls;
111}
112
113
114} // namespace detail
115} // namespace HighFive
Definition H5_definitions.hpp:22
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:43