HighFive 2.7.1
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
H5Path_traits_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#pragma once
10
11#include <H5Ipublic.h>
12
13#include "H5Utils.hpp"
14#include "H5Path_traits.hpp"
15
16namespace HighFive {
17
18template <typename Derivate>
20 static_assert(std::is_same<Derivate, Group>::value || std::is_same<Derivate, DataSet>::value ||
21 std::is_same<Derivate, Attribute>::value,
22 "PathTraits can only be applied to Group, DataSet and Attribute");
23 const auto& obj = static_cast<const Derivate&>(*this);
24 if (!obj.isValid()) {
25 return;
26 }
27 const hid_t file_id = H5Iget_file_id(obj.getId());
28 if (file_id < 0) {
29 HDF5ErrMapper::ToException<PropertyException>("getFile(): Could not obtain file of object");
30 }
31 _file_obj.reset(new File(file_id));
32}
33
34template <typename Derivate>
35inline std::string PathTraits<Derivate>::getPath() const {
36 return details::get_name([this](char* buffer, size_t length) {
37 return H5Iget_name(static_cast<const Derivate*>(this)->getId(), buffer, length);
38 });
39}
40
41template <typename Derivate>
42inline File& PathTraits<Derivate>::getFile() const noexcept {
43 return *_file_obj;
44}
45
46} // namespace HighFive
File class.
Definition H5File.hpp:24
PathTraits()
Definition H5Path_traits_misc.hpp:19
File & getFile() const noexcept
Return a reference to the File object this object belongs.
Definition H5Path_traits_misc.hpp:42
std::string getPath() const
return the path to the current object
Definition H5Path_traits_misc.hpp:35
Definition H5_definitions.hpp:15
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:42