HighFive 2.9.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) {
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) {
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
77inline haddr_t h5d_get_offset(hid_t dset_id) {
78 uint64_t addr = H5Dget_offset(dset_id);
79 if (addr == HADDR_UNDEF) {
80 HDF5ErrMapper::ToException<DataSetException>("Cannot get offset of DataSet.");
81 }
82 return addr;
83}
84
85
86inline herr_t h5d_set_extent(hid_t dset_id, const hsize_t size[]) {
87 herr_t err = H5Dset_extent(dset_id, size);
88 if (H5Dset_extent(dset_id, size) < 0) {
89 HDF5ErrMapper::ToException<DataSetException>("Could not resize dataset.");
90 }
91
92 return err;
93}
94
95inline hid_t h5d_create2(hid_t loc_id,
96 const char* name,
97 hid_t type_id,
98 hid_t space_id,
99 hid_t lcpl_id,
100 hid_t dcpl_id,
101 hid_t dapl_id) {
102 hid_t dataset_id = H5Dcreate2(loc_id, name, type_id, space_id, lcpl_id, dcpl_id, dapl_id);
103
104 if (dataset_id == H5I_INVALID_HID) {
106 std::string("Failed to create the dataset \"") + name + "\":");
107 }
108
109 return dataset_id;
110}
111
112inline hid_t h5d_open2(hid_t loc_id, const char* name, hid_t dapl_id) {
113 hid_t dataset_id = H5Dopen2(loc_id, name, dapl_id);
114
115 if (dataset_id == H5I_INVALID_HID) {
116 HDF5ErrMapper::ToException<DataSetException>(std::string("Unable to open the dataset \"") +
117 name + "\":");
118 }
119
120 return dataset_id;
121}
122
123
124} // namespace detail
125} // namespace HighFive
Definition H5_definitions.hpp:22
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:43