ritsuko
Helper utilities for ArtifactDB C++ code
Loading...
Searching...
No Matches
miscellaneous.hpp
Go to the documentation of this file.
1#ifndef RITSUKO_MISCELLANEOUS_HPP
2#define RITSUKO_MISCELLANEOUS_HPP
3
4#include <string>
5#include "H5Cpp.h"
6
7#include "open.hpp"
8#include "load_attribute.hpp"
9#include "is_utf8_string.hpp"
10#include "get_1d_length.hpp"
11
17namespace ritsuko {
18
19namespace hdf5 {
20
29template<class H5Object_>
30inline H5::Attribute open_scalar_attribute(const H5Object_& handle, const char* name) {
31 auto attr = open_attribute(handle, name);
32 if (!is_scalar(attr)) {
33 throw std::runtime_error("expected '" + std::string(name) + "' attribute to be a scalar");
34 }
35 return attr;
36}
37
48template<class H5Object_>
49std::string open_and_load_scalar_string_attribute(const H5Object_& handle, const char* name, bool utf8 = true) {
50 auto attr = open_scalar_attribute(handle, name);
51
52 if (utf8) {
53 if (!is_utf8_string(attr)) {
54 throw std::runtime_error("expected '" + std::string(name) + "' attribute to be a string with a UTF-8 compatible encoding");
55 }
56 } else {
57 if (attr.getTypeClass() != H5T_STRING) {
58 throw std::runtime_error("expected '" + std::string(name) + "' attribute to be a string");
59 }
60 }
61
63}
64
65}
66
67}
68
69#endif
Get the length of a 1-dimensional HDF5 dataset.
Check if a string datatype uses a UTF-8 encoding.
Load HDF5 attributes.
bool is_utf8_string(const H5::StrType &stype)
Definition is_utf8_string.hpp:27
H5::Attribute open_attribute(const Object_ &handle, const char *name)
Definition open.hpp:88
bool is_scalar(const H5::DataSpace &space)
Definition get_1d_length.hpp:70
H5::Attribute open_scalar_attribute(const H5Object_ &handle, const char *name)
Definition miscellaneous.hpp:30
std::string open_and_load_scalar_string_attribute(const H5Object_ &handle, const char *name, bool utf8=true)
Definition miscellaneous.hpp:49
std::string load_scalar_string_attribute(const H5::Attribute &attr)
Definition load_attribute.hpp:27
Assorted helper functions for parsing and validation.
Definition choose_missing_placeholder.hpp:15
Convenience functions to safely open HDF5 handles.