ritsuko
Helper utilities for ArtifactDB C++ code
Loading...
Searching...
No Matches
get_name.hpp
Go to the documentation of this file.
1#ifndef RITSUKO_HDF5_GET_NAME_HPP
2#define RITSUKO_HDF5_GET_NAME_HPP
3
4#include <string>
5#include <vector>
6#include <type_traits>
7
8#include "H5Cpp.h"
9#include "sanisizer/sanisizer.hpp"
10
11#include "../utils.hpp"
12
18namespace ritsuko {
19
20namespace hdf5 {
21
28template<class Object_>
29std::string get_name(const Object_& obj) {
30 if constexpr(std::is_same<Object_, H5::Attribute>::value) {
31 std::string name;
32 obj.getName(name);
33 return name;
34 } else {
35 static_assert(std::is_base_of<H5::H5Object, Object_>::value);
36 const auto len = H5Iget_name(obj.getId(), NULL, 0);
37 std::vector<char> buffer(sanisizer::sum<typename std::vector<char>::size_type>(len, 1));
38 H5Iget_name(obj.getId(), buffer.data(), sanisizer::cast<std::size_t>(buffer.size()));
39 return std::string(buffer.begin(), buffer.begin() + len);
40 }
41}
42
43}
44
45}
46
47#endif
std::string get_name(const Object_ &obj)
Definition get_name.hpp:29
Helper functions for ArtifactDB parsing and validation.
Definition Pointer.hpp:21