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 <string>
15#include <cstdint>
16#include <cstddef>
17
18#include "utils_public.hpp"
19#include "utils_type.hpp"
20#include "utils_misc.hpp"
21#include "utils_dimensions.hpp"
22
23namespace chihaya {
24
33inline ArrayDetails validate_constant_array(const H5::Group& group, const ritsuko::Version& version, [[maybe_unused]] const Options& options) {
34 ArrayDetails output;
35
36 try {
37 auto dhandle = group.openDataSet("dimensions");
38 auto dspace = dhandle.getSpace();
39 if (dspace.getSimpleExtentNdims() != 1) {
40 throw std::runtime_error("'dimensions' dataset should be 1-dimensional");
41 }
42 hsize_t size;
43 dspace.getSimpleExtentDims(&size);
44 if (size == 0) {
45 throw std::runtime_error("'dimensions' dataset should have non-zero length");
46 }
47
48 if (version.lt(1, 1, 0)) {
49 output.dimensions = load_non_negative_integer_vector_0_99<std::size_t>(dhandle, size);
50 } else {
51 if (ritsuko::hdf5::exceeds_integer_limit(dhandle, 64, false)) {
52 throw std::runtime_error("datatype should fit inside a 64-bit unsigned integer");
53 }
54 output.dimensions = load_dimensions_from_uint64_contents<std::size_t>(dhandle, size);
55 }
56 } catch (...) {
57 std::throw_with_nested(std::runtime_error("failed to validate 'dimensions'"));
58 }
59
60 try {
61 auto vhandle = group.openDataSet("value");
62 if (vhandle.getSpace().getSimpleExtentNdims() != 0) {
63 throw std::runtime_error("'value' dataset should be a scalar");
64 }
65
66 if (version.lt(1, 1, 0)) {
67 output.type = translate_type_0_99(vhandle.getTypeClass());
68 } else {
69 try {
70 auto thandle = vhandle.openAttribute("type");
71 auto type = read_scalar_string_attribute(thandle);
72 output.type = translate_type_1_1(type);
73 if (!options.details_only) {
74 check_type_1_1(vhandle, output.type);
75 }
76 } catch (...) {
77 std::throw_with_nested(std::runtime_error("failed to validate the 'type' attribute"));
78 }
79 }
80
81 if (!options.details_only) {
82 validate_missing_placeholder(vhandle, version);
83 if (vhandle.getTypeClass() == H5T_STRING) {
84 ritsuko::hdf5::validate_scalar_string(vhandle);
85 }
86 }
87 } catch (...) {
88 std::throw_with_nested(std::runtime_error("failed to validate 'value'"));
89 }
90
91 return output;
92}
93
94}
95
96#endif
Namespace for all chihaya functions.
Definition binary_arithmetic.hpp:20
ArrayDetails validate_constant_array(const H5::Group &group, const ritsuko::Version &version, const Options &options)
Definition constant_array.hpp:33
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.