File: get_name.hpp

package info (click to toggle)
r-bioc-alabaster.base 1.6.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,652 kB
  • sloc: cpp: 11,377; sh: 29; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef RITSUKO_HDF5_GET_NAME_HPP
#define RITSUKO_HDF5_GET_NAME_HPP

#include "H5Cpp.h"
#include <string>
#include <vector>

/**
 * @file get_name.hpp
 * @brief Get the name of a HDF5 object.
 */

namespace ritsuko {

namespace hdf5 {

/**
 * Get the name of a HDF5 object from its handle, usually for printing informative error messages.
 * @tparam Handle_ Type of HDF5 handle, usually a `Group`, `DataSet` or `Attribute`.
 * @param handle Handle to a HDF5 object.
 * @return Name of the HDF5 object inside the file.
 */
template<class Handle_>
std::string get_name(const Handle_& handle) {
    if constexpr(std::is_same<Handle_, H5::Attribute>::value) {
        std::string name;
        handle.getName(name);
        return name;
    } else {
        size_t len = H5Iget_name(handle.getId(), NULL, 0);
        std::vector<char> buffer(len + 1);
        H5Iget_name(handle.getId(), buffer.data(), buffer.size());
        return std::string(buffer.begin(), buffer.begin() + len);
    }
}

}

}

#endif