File indexing completed on 2025-04-19 08:55:33
0001 #pragma once
0002
0003 #include <H5Lpublic.h>
0004
0005 namespace HighFive {
0006 namespace detail {
0007
0008 inline herr_t h5l_create_external(const char* file_name,
0009 const char* obj_name,
0010 hid_t link_loc_id,
0011 const char* link_name,
0012 hid_t lcpl_id,
0013 hid_t lapl_id) {
0014 herr_t err = H5Lcreate_external(file_name, obj_name, link_loc_id, link_name, lcpl_id, lapl_id);
0015 if (err < 0) {
0016 HDF5ErrMapper::ToException<GroupException>(std::string("Unable to create external link: "));
0017 }
0018
0019 return err;
0020 }
0021
0022 inline herr_t h5l_create_soft(const char* link_target,
0023 hid_t link_loc_id,
0024 const char* link_name,
0025 hid_t lcpl_id,
0026 hid_t lapl_id) {
0027 herr_t err = H5Lcreate_soft(link_target, link_loc_id, link_name, lcpl_id, lapl_id);
0028 if (err < 0) {
0029 HDF5ErrMapper::ToException<GroupException>(std::string("Unable to create soft link: "));
0030 }
0031
0032 return err;
0033 }
0034
0035 inline herr_t h5l_create_hard(hid_t cur_loc,
0036 const char* cur_name,
0037 hid_t dst_loc,
0038 const char* dst_name,
0039 hid_t lcpl_id,
0040 hid_t lapl_id) {
0041 herr_t err = H5Lcreate_hard(cur_loc, cur_name, dst_loc, dst_name, lcpl_id, lapl_id);
0042 if (err < 0) {
0043 HDF5ErrMapper::ToException<GroupException>(std::string("Unable to create hard link: "));
0044 }
0045
0046 return err;
0047 }
0048
0049 inline herr_t h5l_get_info(hid_t loc_id, const char* name, H5L_info_t* linfo, hid_t lapl_id) {
0050 herr_t err = H5Lget_info(loc_id, name, linfo, lapl_id);
0051 if (err < 0) {
0052 HDF5ErrMapper::ToException<GroupException>(std::string("Unable to obtain info for link "));
0053 }
0054
0055 return err;
0056 }
0057
0058 inline herr_t h5l_delete(hid_t loc_id, const char* name, hid_t lapl_id) {
0059 herr_t err = H5Ldelete(loc_id, name, lapl_id);
0060 if (err < 0) {
0061 HDF5ErrMapper::ToException<GroupException>(std::string("Invalid name for unlink() "));
0062 }
0063
0064 return err;
0065 }
0066
0067 inline htri_t h5l_exists(hid_t loc_id, const char* name, hid_t lapl_id) {
0068 htri_t tri = H5Lexists(loc_id, name, lapl_id);
0069 if (tri < 0) {
0070 HDF5ErrMapper::ToException<GroupException>("Invalid link for exist()");
0071 }
0072
0073 return tri;
0074 }
0075
0076 namespace nothrow {
0077
0078 inline htri_t h5l_exists(hid_t loc_id, const char* name, hid_t lapl_id) {
0079 return H5Lexists(loc_id, name, lapl_id);
0080 }
0081
0082 }
0083
0084 inline herr_t h5l_iterate(hid_t grp_id,
0085 H5_index_t idx_type,
0086 H5_iter_order_t order,
0087 hsize_t* idx,
0088 H5L_iterate_t op,
0089 void* op_data) {
0090 herr_t err = H5Literate(grp_id, idx_type, order, idx, op, op_data);
0091 if (err < 0) {
0092 HDF5ErrMapper::ToException<GroupException>(std::string("Unable to list objects in group"));
0093 }
0094 return err;
0095 }
0096
0097 inline herr_t h5l_move(hid_t src_loc,
0098 const char* src_name,
0099 hid_t dst_loc,
0100 const char* dst_name,
0101 hid_t lcpl_id,
0102 hid_t lapl_id) {
0103 herr_t err = H5Lmove(src_loc, src_name, dst_loc, dst_name, lcpl_id, lapl_id);
0104
0105 if (err < 0) {
0106 HDF5ErrMapper::ToException<GroupException>(std::string("Unable to move link to \"") +
0107 dst_name + "\":");
0108 }
0109 return err;
0110 }
0111
0112 inline ssize_t h5l_get_name_by_idx(hid_t loc_id,
0113 const char* group_name,
0114 H5_index_t idx_type,
0115 H5_iter_order_t order,
0116 hsize_t n,
0117 char* name,
0118 size_t size,
0119 hid_t lapl_id) {
0120 ssize_t n_chars =
0121 H5Lget_name_by_idx(loc_id, group_name, idx_type, order, n, name, size, lapl_id);
0122
0123 if (n_chars < 0) {
0124 HDF5ErrMapper::ToException<GroupException>(
0125 std::string("Unable to obtain link name from index."));
0126 }
0127
0128 return n_chars;
0129 }
0130
0131 }
0132 }