File indexing completed on 2025-04-19 08:55:33
0001 #pragma once
0002
0003 #include <H5Dpublic.h>
0004 #include <H5Ipublic.h>
0005
0006 namespace HighFive {
0007 namespace detail {
0008
0009
0010 #if !H5_VERSION_GE(1, 12, 0)
0011 inline herr_t h5d_vlen_reclaim(hid_t type_id, hid_t space_id, hid_t dxpl_id, void* buf) {
0012 herr_t err = H5Dvlen_reclaim(type_id, space_id, dxpl_id, buf);
0013 if (err < 0) {
0014 throw DataSetException("Failed to reclaim HDF5 internal memory");
0015 }
0016
0017 return err;
0018 }
0019 #endif
0020
0021 inline hsize_t h5d_get_storage_size(hid_t dset_id) {
0022
0023
0024
0025
0026 return H5Dget_storage_size(dset_id);
0027 }
0028
0029 inline hid_t h5d_get_space(hid_t dset_id) {
0030 hid_t dset = H5Dget_space(dset_id);
0031 if (dset == H5I_INVALID_HID) {
0032 HDF5ErrMapper::ToException<DataSetException>(
0033 std::string("Unable to get dataspace of the dataset"));
0034 }
0035
0036 return dset;
0037 }
0038
0039 inline hid_t h5d_get_type(hid_t dset_id) {
0040 hid_t type_id = H5Dget_type(dset_id);
0041 if (type_id == H5I_INVALID_HID) {
0042 HDF5ErrMapper::ToException<DataSetException>(
0043 std::string("Unable to get datatype of the dataset"));
0044 }
0045
0046 return type_id;
0047 }
0048
0049 inline herr_t h5d_read(hid_t dset_id,
0050 hid_t mem_type_id,
0051 hid_t mem_space_id,
0052 hid_t file_space_id,
0053 hid_t dxpl_id,
0054 void* buf) {
0055 herr_t err = H5Dread(dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf);
0056 if (err < 0) {
0057 HDF5ErrMapper::ToException<DataSetException>(std::string("Unable to read the dataset"));
0058 }
0059
0060 return err;
0061 }
0062
0063 inline herr_t h5d_write(hid_t dset_id,
0064 hid_t mem_type_id,
0065 hid_t mem_space_id,
0066 hid_t file_space_id,
0067 hid_t dxpl_id,
0068 const void* buf) {
0069 herr_t err = H5Dwrite(dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf);
0070 if (err < 0) {
0071 HDF5ErrMapper::ToException<DataSetException>(std::string("Unable to write the dataset"));
0072 }
0073
0074 return err;
0075 }
0076
0077 inline haddr_t h5d_get_offset(hid_t dset_id) {
0078 uint64_t addr = H5Dget_offset(dset_id);
0079 if (addr == HADDR_UNDEF) {
0080 HDF5ErrMapper::ToException<DataSetException>("Cannot get offset of DataSet.");
0081 }
0082 return addr;
0083 }
0084
0085
0086 inline herr_t h5d_set_extent(hid_t dset_id, const hsize_t size[]) {
0087 herr_t err = H5Dset_extent(dset_id, size);
0088 if (H5Dset_extent(dset_id, size) < 0) {
0089 HDF5ErrMapper::ToException<DataSetException>("Could not resize dataset.");
0090 }
0091
0092 return err;
0093 }
0094
0095 inline hid_t h5d_create2(hid_t loc_id,
0096 const char* name,
0097 hid_t type_id,
0098 hid_t space_id,
0099 hid_t lcpl_id,
0100 hid_t dcpl_id,
0101 hid_t dapl_id) {
0102 hid_t dataset_id = H5Dcreate2(loc_id, name, type_id, space_id, lcpl_id, dcpl_id, dapl_id);
0103
0104 if (dataset_id == H5I_INVALID_HID) {
0105 HDF5ErrMapper::ToException<DataSetException>(
0106 std::string("Failed to create the dataset \"") + name + "\":");
0107 }
0108
0109 return dataset_id;
0110 }
0111
0112 inline hid_t h5d_open2(hid_t loc_id, const char* name, hid_t dapl_id) {
0113 hid_t dataset_id = H5Dopen2(loc_id, name, dapl_id);
0114
0115 if (dataset_id == H5I_INVALID_HID) {
0116 HDF5ErrMapper::ToException<DataSetException>(std::string("Unable to open the dataset \"") +
0117 name + "\":");
0118 }
0119
0120 return dataset_id;
0121 }
0122
0123
0124 }
0125 }