File indexing completed on 2025-04-19 08:55:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #pragma once
0011
0012 #include <string>
0013 #include <H5Ppublic.h>
0014
0015 #include "H5Utils.hpp"
0016
0017 #include "../H5Object.hpp"
0018
0019 #include "h5r_wrapper.hpp"
0020
0021 namespace HighFive {
0022
0023 inline Reference::Reference(const Object& location, const Object& object)
0024 : parent_id(location.getId()) {
0025 obj_name = details::get_name([&](char* buffer, size_t length) {
0026 return detail::h5i_get_name(object.getId(), buffer, length);
0027 });
0028 }
0029
0030 inline void Reference::create_ref(hobj_ref_t* refptr) const {
0031 detail::h5r_create(refptr, parent_id, obj_name.c_str(), H5R_OBJECT, -1);
0032 }
0033
0034 inline ObjectType Reference::getType(const Object& location) const {
0035 return get_ref(location).getType();
0036 }
0037
0038 template <typename T>
0039 inline T Reference::dereference(const Object& location) const {
0040 static_assert(std::is_same<DataSet, T>::value || std::is_same<Group, T>::value,
0041 "We can only (de)reference HighFive::Group or HighFive:DataSet");
0042 auto obj = get_ref(location);
0043 if (obj.getType() != T::type) {
0044 HDF5ErrMapper::ToException<ReferenceException>("Trying to dereference the wrong type");
0045 }
0046 #if defined __GNUC__ && __GNUC__ < 9
0047 return std::move(obj);
0048 #else
0049 return obj;
0050 #endif
0051 }
0052
0053 inline Object Reference::get_ref(const Object& location) const {
0054 #if (H5Rdereference_vers == 2)
0055 hid_t res = detail::h5r_dereference(location.getId(), H5P_DEFAULT, H5R_OBJECT, &href);
0056 #else
0057 hid_t res = detail::h5r_dereference(location.getId(), H5R_OBJECT, &href);
0058 #endif
0059 return Object(res);
0060 }
0061
0062 }