HighFive 2.9.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
H5Reference_misc.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c), 2020, EPFL - Blue Brain Project
3 *
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 *
8 */
9
10#pragma once
11
12#include <string>
13#include <H5Ppublic.h>
14
15#include "H5Utils.hpp"
16
17#include "../H5Object.hpp"
18
19#include "h5r_wrapper.hpp"
20
21namespace HighFive {
22
23inline Reference::Reference(const Object& location, const Object& object)
24 : parent_id(location.getId()) {
25 obj_name = details::get_name([&](char* buffer, size_t length) {
26 return detail::h5i_get_name(object.getId(), buffer, length);
27 });
28}
29
30inline void Reference::create_ref(hobj_ref_t* refptr) const {
31 detail::h5r_create(refptr, parent_id, obj_name.c_str(), H5R_OBJECT, -1);
32}
33
34inline ObjectType Reference::getType(const Object& location) const {
35 return get_ref(location).getType();
36}
37
38template <typename T>
39inline T Reference::dereference(const Object& location) const {
40 static_assert(std::is_same<DataSet, T>::value || std::is_same<Group, T>::value,
41 "We can only (de)reference HighFive::Group or HighFive:DataSet");
42 auto obj = get_ref(location);
43 if (obj.getType() != T::type) {
44 HDF5ErrMapper::ToException<ReferenceException>("Trying to dereference the wrong type");
45 }
46#if defined __GNUC__ && __GNUC__ < 9
47 return std::move(obj);
48#else
49 return obj;
50#endif
51}
52
53inline Object Reference::get_ref(const Object& location) const {
54#if (H5Rdereference_vers == 2)
55 hid_t res = detail::h5r_dereference(location.getId(), H5P_DEFAULT, H5R_OBJECT, &href);
56#else
57 hid_t res = detail::h5r_dereference(location.getId(), H5R_OBJECT, &href);
58#endif
59 return Object(res);
60}
61
62} // namespace HighFive
Definition H5Object.hpp:54
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:69
ObjectType getType() const
Gets the fundamental type of the object (dataset, group, etc)
Definition H5Object_misc.hpp:92
T dereference(const Object &location) const
Retrieve the Object being referenced by the Reference.
Definition H5Reference_misc.hpp:39
Reference()=default
Create an empty Reference to be initialized later.
ObjectType getType(const Object &location) const
Get only the type of the referenced Object.
Definition H5Reference_misc.hpp:34
void create_ref(hobj_ref_t *refptr) const
Create the low-level reference and store it at refptr.
Definition H5Reference_misc.hpp:30
Definition H5_definitions.hpp:22
ObjectType
Enum of the types of objects (H5O api)
Definition H5Object.hpp:24
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:43