HighFive 3.2.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
h5d_wrapper.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <H5Dpublic.h>
4#include <H5Ipublic.h>
5
6namespace HighFive {
7namespace detail {
8
9
10#if !H5_VERSION_GE(1, 12, 0)
11inline herr_t h5d_vlen_reclaim(hid_t type_id, hid_t space_id, hid_t dxpl_id, void* buf) {
12 herr_t err = H5Dvlen_reclaim(type_id, space_id, dxpl_id, buf);
13 if (err < 0) {
14 throw DataSetException("Failed to reclaim HDF5 internal memory");
15 }
16
17 return err;
18}
19#endif
20
21inline hsize_t h5d_get_storage_size(hid_t dset_id) {
22 // Docs:
23 // H5Dget_storage_size() does not differentiate between 0 (zero), the
24 // value returned for the storage size of a dataset with no stored values,
25 // and 0 (zero), the value returned to indicate an error.
26 return H5Dget_storage_size(dset_id);
27}
28
29inline hid_t h5d_get_space(hid_t dset_id) {
30 hid_t dset = H5Dget_space(dset_id);
31 if (dset == H5I_INVALID_HID) {
32 HDF5ErrMapper::ToException<DataSetException>(
33 std::string("Unable to get dataspace of the dataset"));
34 }
35
36 return dset;
37}
38
39inline hid_t h5d_get_type(hid_t dset_id) {
40 hid_t type_id = H5Dget_type(dset_id);
41 if (type_id == H5I_INVALID_HID) {
42 HDF5ErrMapper::ToException<DataSetException>(
43 std::string("Unable to get datatype of the dataset"));
44 }
45
46 return type_id;
47}
48
49inline herr_t h5d_read(hid_t dset_id,
50 hid_t mem_type_id,
51 hid_t mem_space_id,
52 hid_t file_space_id,
53 hid_t dxpl_id,
54 void* buf) {
55 herr_t err = H5Dread(dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf);
56 if (err < 0) {
57 HDF5ErrMapper::ToException<DataSetException>(std::string("Unable to read the dataset"));
58 }
59
60 return err;
61}
62
63inline herr_t h5d_write(hid_t dset_id,
64 hid_t mem_type_id,
65 hid_t mem_space_id,
66 hid_t file_space_id,
67 hid_t dxpl_id,
68 const void* buf) {
69 herr_t err = H5Dwrite(dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf);
70 if (err < 0) {
71 HDF5ErrMapper::ToException<DataSetException>(std::string("Unable to write the dataset"));
72 }
73
74 return err;
75}
76
77#if H5_VERSION_GE(1, 10, 0)
78inline herr_t h5d_flush(hid_t dset_id) {
79 herr_t err = H5Dflush(dset_id);
80 if (err < 0) {
81 HDF5ErrMapper::ToException<DataSetException>("Unable to flush the dataset.");
82 }
83
84 return err;
85}
86#endif
87
88#if H5_VERSION_GE(1, 10, 2)
89inline herr_t h5d_refresh(hid_t dset_id) {
90 herr_t err = H5Drefresh(dset_id);
91 if (err < 0) {
92 HDF5ErrMapper::ToException<DataSetException>("Unable to refresh the dataset.");
93 }
94
95 return err;
96}
97#endif
98
99inline haddr_t h5d_get_offset(hid_t dset_id) {
100 uint64_t addr = H5Dget_offset(dset_id);
101 if (addr == HADDR_UNDEF) {
102 HDF5ErrMapper::ToException<DataSetException>("Cannot get offset of DataSet.");
103 }
104 return addr;
105}
106
107
108inline herr_t h5d_set_extent(hid_t dset_id, const hsize_t size[]) {
109 herr_t err = H5Dset_extent(dset_id, size);
110 if (err < 0) {
111 HDF5ErrMapper::ToException<DataSetException>("Could not resize dataset.");
112 }
113
114 return err;
115}
116
117inline hid_t h5d_create2(hid_t loc_id,
118 const char* name,
119 hid_t type_id,
120 hid_t space_id,
121 hid_t lcpl_id,
122 hid_t dcpl_id,
123 hid_t dapl_id) {
124 hid_t dataset_id = H5Dcreate2(loc_id, name, type_id, space_id, lcpl_id, dcpl_id, dapl_id);
125
126 if (dataset_id == H5I_INVALID_HID) {
127 HDF5ErrMapper::ToException<DataSetException>(
128 std::string("Failed to create the dataset \"") + name + "\":");
129 }
130
131 return dataset_id;
132}
133
134inline hid_t h5d_open2(hid_t loc_id, const char* name, hid_t dapl_id) {
135 hid_t dataset_id = H5Dopen2(loc_id, name, dapl_id);
136
137 if (dataset_id == H5I_INVALID_HID) {
138 HDF5ErrMapper::ToException<DataSetException>(std::string("Unable to open the dataset \"") +
139 name + "\":");
140 }
141
142 return dataset_id;
143}
144
145
146} // namespace detail
147} // namespace HighFive
Definition assert_compatible_spaces.hpp:15