HighFive  2.3.1
HighFive - Header-only C++ HDF5 interface
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 
16 namespace HighFive{
17 
18 template <typename Derivate>
20  static_assert(std::is_same<Derivate, Group>::value
21  || std::is_same<Derivate, DataSet>::value
22  || std::is_same<Derivate, Attribute>::value,
23  "PathTraits can only be applied to Group, DataSet and Attribute");
24  const auto& obj = static_cast<const Derivate&>(*this);
25  if(!obj.isValid()) {
26  return;
27  }
28  const hid_t file_id = H5Iget_file_id(obj.getId());
29  if (file_id < 0) {
30  HDF5ErrMapper::ToException<PropertyException>(
31  "getFile(): Could not obtain file of object");
32  }
33  _file_obj.reset(new File(file_id));
34 }
35 
36 template <typename Derivate>
37 inline std::string PathTraits<Derivate>::getPath() const {
38  return details::get_name([this](char* buffer, hsize_t length) {
39  return H5Iget_name(static_cast<const Derivate*>(this)->getId(), buffer, static_cast<size_t>(length));
40  });
41 }
42 
43 template <typename Derivate>
44 inline File& PathTraits<Derivate>::getFile() const noexcept {
45  return *_file_obj;
46 }
47 
48 } // namespace HighFive
File class.
Definition: H5File.hpp:26
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:44
std::string getPath() const
return the path to the current object
Definition: H5Path_traits_misc.hpp:37
Definition: H5_definitions.hpp:15