ritsuko
Helper utilities for ArtifactDB C++ code
Loading...
Searching...
No Matches
get_1d_length.hpp
Go to the documentation of this file.
1#ifndef RITSUKO_HDF5_GET_1D_LENGTH_HPP
2#define RITSUKO_HDF5_GET_1D_LENGTH_HPP
3
4#include "H5Cpp.h"
5#include <stdexcept>
6
12namespace ritsuko {
13
14namespace hdf5 {
15
25inline hsize_t get_1d_length(const H5::DataSpace& space, bool allow_scalar) {
26 int ndims = space.getSimpleExtentNdims();
27 if (ndims == 0) {
28 if (!allow_scalar) {
29 throw std::runtime_error("expected a 1-dimensional dataset, got a scalar instead");
30 }
31 return 0;
32 }
33 if (ndims != 1) {
34 throw std::runtime_error("expected a 1-dimensional dataset, got " + std::to_string(ndims) + " dimensions instead");
35 }
36
37 hsize_t dims;
38 space.getSimpleExtentDims(&dims);
39 return dims;
40}
41
50inline hsize_t get_1d_length(const H5::DataSet& handle, bool allow_scalar) {
51 return get_1d_length(handle.getSpace(), allow_scalar);
52}
53
62inline hsize_t get_1d_length(const H5::Attribute& handle, bool allow_scalar) {
63 return get_1d_length(handle.getSpace(), allow_scalar);
64}
65
70inline bool is_scalar(const H5::DataSpace& space) {
71 return space.getSimpleExtentNdims() == 0;
72}
73
79inline bool is_scalar(const H5::DataSet& handle) {
80 return is_scalar(handle.getSpace());
81}
82
88inline bool is_scalar(const H5::Attribute& handle) {
89 return is_scalar(handle.getSpace());
90}
91
92}
93
94}
95
96#endif
bool is_scalar(const H5::DataSpace &space)
Definition get_1d_length.hpp:70
hsize_t get_1d_length(const H5::DataSpace &space, bool allow_scalar)
Definition get_1d_length.hpp:25
Assorted helper functions for parsing and validation.
Definition choose_missing_placeholder.hpp:15