chihaya
Validating delayed array operations in HDF5
Loading...
Searching...
No Matches
constant_array.hpp
Go to the documentation of this file.
1#ifndef CHIHAYA_CONSTANT_ARRAY_HPP
2#define CHIHAYA_CONSTANT_ARRAY_HPP
3
9#include "H5Cpp.h"
10#include "ritsuko/ritsuko.hpp"
11
12#include <vector>
13#include <stdexcept>
14#include <exception>
15#include <string>
16#include <cstdint>
17#include <cstddef>
18
19#include "utils_public.hpp"
20#include "utils_type.hpp"
21#include "utils_misc.hpp"
22#include "utils_dimensions.hpp"
23
24namespace chihaya {
25
38inline ArrayDetails validate_constant_array(const H5::Group& group, const ritsuko::Version& version, [[maybe_unused]] const Options& options) {
39 ArrayDetails output;
40
41 try {
42 auto dhandle = group.openDataSet("dimensions");
43 auto dspace = dhandle.getSpace();
44 if (dspace.getSimpleExtentNdims() != 1) {
45 throw std::runtime_error("'dimensions' dataset should be 1-dimensional");
46 }
47 hsize_t size;
48 dspace.getSimpleExtentDims(&size);
49 if (size == 0) {
50 throw std::runtime_error("'dimensions' dataset should have non-zero length");
51 }
52
53 if (version.lt(1, 1, 0)) {
54 output.dimensions = load_non_negative_integer_vector_0_99<std::size_t>(dhandle, size);
55 } else {
56 if (ritsuko::hdf5::exceeds_integer_limit(dhandle, 64, false)) {
57 throw std::runtime_error("datatype should fit inside a 64-bit unsigned integer");
58 }
59 output.dimensions = load_dimensions_from_uint64_contents<std::size_t>(dhandle, size);
60 }
61 } catch (...) {
62 std::throw_with_nested(std::runtime_error("failed to validate 'dimensions'"));
63 }
64
65 try {
66 auto vhandle = group.openDataSet("value");
67 if (vhandle.getSpace().getSimpleExtentNdims() != 0) {
68 throw std::runtime_error("'value' dataset should be a scalar");
69 }
70
71 if (version.lt(1, 1, 0)) {
72 output.type = translate_type_0_99(vhandle.getTypeClass());
73 } else {
74 try {
75 auto thandle = vhandle.openAttribute("type");
76 auto type = read_scalar_string_attribute(thandle);
77 output.type = translate_type_1_1(type);
78 if (!options.details_only) {
79 check_type_1_1(vhandle, output.type);
80 }
81 } catch (...) {
82 std::throw_with_nested(std::runtime_error("failed to validate the 'type' attribute"));
83 }
84 }
85
86 if (!options.details_only) {
87 validate_missing_placeholder(vhandle, version);
88 if (vhandle.getTypeClass() == H5T_STRING) {
89 ritsuko::hdf5::validate_scalar_string(vhandle);
90 }
91 }
92 } catch (...) {
93 std::throw_with_nested(std::runtime_error("failed to validate 'value'"));
94 }
95
96 return output;
97}
98
99}
100
101#endif
Namespace for all chihaya functions.
Definition binary_arithmetic.hpp:21
ArrayDetails validate_constant_array(const H5::Group &group, const ritsuko::Version &version, const Options &options)
Definition constant_array.hpp:38
Details about an array.
Definition utils_public.hpp:38
std::vector< std::size_t > dimensions
Definition utils_public.hpp:58
ArrayType type
Definition utils_public.hpp:52
Options for validate().
Definition utils_public.hpp:79
Various public utilities.