File indexing completed on 2025-04-19 08:55:32
0001 #pragma once
0002
0003 #include <H5Apublic.h>
0004 #include <H5Ipublic.h>
0005
0006 namespace HighFive {
0007 namespace detail {
0008
0009 inline hid_t h5a_create2(hid_t loc_id,
0010 char const* const attr_name,
0011 hid_t type_id,
0012 hid_t space_id,
0013 hid_t acpl_id,
0014 hid_t aapl_id) {
0015 auto attr_id = H5Acreate2(loc_id, attr_name, type_id, space_id, acpl_id, aapl_id);
0016 if (attr_id < 0) {
0017 HDF5ErrMapper::ToException<AttributeException>(
0018 std::string("Unable to create the attribute \"") + attr_name + "\":");
0019 }
0020
0021 return attr_id;
0022 }
0023
0024 inline void h5a_delete(hid_t loc_id, char const* const attr_name) {
0025 if (H5Adelete(loc_id, attr_name) < 0) {
0026 HDF5ErrMapper::ToException<AttributeException>(
0027 std::string("Unable to delete attribute \"") + attr_name + "\":");
0028 }
0029 }
0030
0031 inline hid_t h5a_open(hid_t loc_id, char const* const attr_name, hid_t aapl_id) {
0032 const auto attr_id = H5Aopen(loc_id, attr_name, aapl_id);
0033 if (attr_id < 0) {
0034 HDF5ErrMapper::ToException<AttributeException>(
0035 std::string("Unable to open the attribute \"") + attr_name + "\":");
0036 }
0037
0038 return attr_id;
0039 }
0040
0041
0042 inline int h5a_get_num_attrs(hid_t loc_id) {
0043 int res = H5Aget_num_attrs(loc_id);
0044 if (res < 0) {
0045 HDF5ErrMapper::ToException<AttributeException>(
0046 std::string("Unable to count attributes in existing group or file"));
0047 }
0048
0049 return res;
0050 }
0051
0052
0053 inline void h5a_iterate2(hid_t loc_id,
0054 H5_index_t idx_type,
0055 H5_iter_order_t order,
0056 hsize_t* idx,
0057 H5A_operator2_t op,
0058 void* op_data) {
0059 if (H5Aiterate2(loc_id, idx_type, order, idx, op, op_data) < 0) {
0060 HDF5ErrMapper::ToException<AttributeException>(std::string("Failed H5Aiterate2."));
0061 }
0062 }
0063
0064 inline int h5a_exists(hid_t obj_id, char const* const attr_name) {
0065 int res = H5Aexists(obj_id, attr_name);
0066 if (res < 0) {
0067 HDF5ErrMapper::ToException<AttributeException>(
0068 std::string("Unable to check for attribute in group"));
0069 }
0070
0071 return res;
0072 }
0073
0074 inline ssize_t h5a_get_name(hid_t attr_id, size_t buf_size, char* buf) {
0075 ssize_t name_length = H5Aget_name(attr_id, buf_size, buf);
0076 if (name_length < 0) {
0077 HDF5ErrMapper::ToException<AttributeException>(
0078 std::string("Unable to get name of attribute"));
0079 }
0080
0081 return name_length;
0082 }
0083
0084
0085 inline hid_t h5a_get_space(hid_t attr_id) {
0086 hid_t attr = H5Aget_space(attr_id);
0087 if (attr < 0) {
0088 HDF5ErrMapper::ToException<AttributeException>(
0089 std::string("Unable to get dataspace of attribute"));
0090 }
0091
0092 return attr;
0093 }
0094
0095 inline hsize_t h5a_get_storage_size(hid_t attr_id) {
0096
0097
0098
0099 return H5Aget_storage_size(attr_id);
0100 }
0101
0102 inline hid_t h5a_get_type(hid_t attr_id) {
0103 hid_t type_id = H5Aget_type(attr_id);
0104 if (type_id == H5I_INVALID_HID) {
0105 HDF5ErrMapper::ToException<AttributeException>(
0106 std::string("Unable to get datatype of attribute"));
0107 }
0108
0109 return type_id;
0110 }
0111
0112 inline herr_t h5a_read(hid_t attr_id, hid_t type_id, void* buf) {
0113 herr_t err = H5Aread(attr_id, type_id, buf);
0114 if (err < 0) {
0115 HDF5ErrMapper::ToException<AttributeException>(std::string("Unable to read attribute"));
0116 }
0117
0118 return err;
0119 }
0120
0121 inline herr_t h5a_write(hid_t attr_id, hid_t type_id, void const* buf) {
0122 herr_t err = H5Awrite(attr_id, type_id, buf);
0123 if (err < 0) {
0124 HDF5ErrMapper::ToException<AttributeException>(std::string("Unable to write attribute"));
0125 }
0126
0127 return err;
0128 }
0129
0130 }
0131 }