HighFive 2.9.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
h5a_wrapper.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <H5Apublic.h>
4#include <H5Ipublic.h>
5
6namespace HighFive {
7namespace detail {
8
9inline hid_t h5a_create2(hid_t loc_id,
10 char const* const attr_name,
11 hid_t type_id,
12 hid_t space_id,
13 hid_t acpl_id,
14 hid_t aapl_id) {
15 auto attr_id = H5Acreate2(loc_id, attr_name, type_id, space_id, acpl_id, aapl_id);
16 if (attr_id < 0) {
18 std::string("Unable to create the attribute \"") + attr_name + "\":");
19 }
20
21 return attr_id;
22}
23
24inline void h5a_delete(hid_t loc_id, char const* const attr_name) {
25 if (H5Adelete(loc_id, attr_name) < 0) {
27 std::string("Unable to delete attribute \"") + attr_name + "\":");
28 }
29}
30
31inline hid_t h5a_open(hid_t loc_id, char const* const attr_name, hid_t aapl_id) {
32 const auto attr_id = H5Aopen(loc_id, attr_name, aapl_id);
33 if (attr_id < 0) {
35 std::string("Unable to open the attribute \"") + attr_name + "\":");
36 }
37
38 return attr_id;
39}
40
41
42inline int h5a_get_num_attrs(hid_t loc_id) {
43 int res = H5Aget_num_attrs(loc_id);
44 if (res < 0) {
46 std::string("Unable to count attributes in existing group or file"));
47 }
48
49 return res;
50}
51
52
53inline void h5a_iterate2(hid_t loc_id,
54 H5_index_t idx_type,
55 H5_iter_order_t order,
56 hsize_t* idx,
57 H5A_operator2_t op,
58 void* op_data) {
59 if (H5Aiterate2(loc_id, idx_type, order, idx, op, op_data) < 0) {
60 HDF5ErrMapper::ToException<AttributeException>(std::string("Failed H5Aiterate2."));
61 }
62}
63
64inline int h5a_exists(hid_t obj_id, char const* const attr_name) {
65 int res = H5Aexists(obj_id, attr_name);
66 if (res < 0) {
68 std::string("Unable to check for attribute in group"));
69 }
70
71 return res;
72}
73
74inline ssize_t h5a_get_name(hid_t attr_id, size_t buf_size, char* buf) {
75 ssize_t name_length = H5Aget_name(attr_id, buf_size, buf);
76 if (name_length < 0) {
78 std::string("Unable to get name of attribute"));
79 }
80
81 return name_length;
82}
83
84
85inline hid_t h5a_get_space(hid_t attr_id) {
86 hid_t attr = H5Aget_space(attr_id);
87 if (attr < 0) {
89 std::string("Unable to get dataspace of attribute"));
90 }
91
92 return attr;
93}
94
95inline hsize_t h5a_get_storage_size(hid_t attr_id) {
96 // Docs:
97 // Returns the amount of storage size allocated for the attribute;
98 // otherwise returns 0 (zero).
99 return H5Aget_storage_size(attr_id);
100}
101
102inline hid_t h5a_get_type(hid_t attr_id) {
103 hid_t type_id = H5Aget_type(attr_id);
104 if (type_id == H5I_INVALID_HID) {
106 std::string("Unable to get datatype of attribute"));
107 }
108
109 return type_id;
110}
111
112inline herr_t h5a_read(hid_t attr_id, hid_t type_id, void* buf) {
113 herr_t err = H5Aread(attr_id, type_id, buf);
114 if (err < 0) {
115 HDF5ErrMapper::ToException<AttributeException>(std::string("Unable to read attribute"));
116 }
117
118 return err;
119}
120
121inline herr_t h5a_write(hid_t attr_id, hid_t type_id, void const* buf) {
122 herr_t err = H5Awrite(attr_id, type_id, buf);
123 if (err < 0) {
124 HDF5ErrMapper::ToException<AttributeException>(std::string("Unable to write attribute"));
125 }
126
127 return err;
128}
129
130} // namespace detail
131} // namespace HighFive
Definition H5_definitions.hpp:22
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:43