chihaya
Validating delayed array operations in HDF5
Loading...
Searching...
No Matches
custom_array.hpp
Go to the documentation of this file.
1#ifndef CHIHAYA_CUSTOM_ARRAY_HPP
2#define CHIHAYA_CUSTOM_ARRAY_HPP
3
4#include "H5Cpp.h"
5#include "ritsuko/ritsuko.hpp"
6
7#include <vector>
8#include <stdexcept>
9#include <exception>
10#include <cstdint>
11#include <algorithm>
12
13#include "utils_public.hpp"
14#include "utils_type.hpp"
15#include "utils_misc.hpp"
16#include "utils_dimensions.hpp"
17
24namespace chihaya {
25
29inline ArrayDetails validate_minimal_array(const H5::Group& group, const ritsuko::Version& version, [[maybe_unused]] const Options& options) {
30 ArrayDetails output;
31
32 try {
33 auto dhandle = group.openDataSet("dimensions");
34 auto dspace = dhandle.getSpace();
35 if (dspace.getSimpleExtentNdims() != 1) {
36 throw std::runtime_error("expected a 1-dimensional dataset");
37 }
38 hsize_t len;
39 dspace.getSimpleExtentDims(&len);
40
41 if (version.lt(1, 1, 0)) {
42 output.dimensions = load_non_negative_integer_vector_0_99<std::size_t>(dhandle, len);
43 } else {
44 if (ritsuko::hdf5::exceeds_integer_limit(dhandle, 64, false)) {
45 throw std::runtime_error("datatype should fit in a 64-bit unsigned integer");
46 }
47 output.dimensions = load_dimensions_from_uint64_contents<std::size_t>(dhandle, len);
48 }
49 } catch (...) {
50 std::throw_with_nested(std::runtime_error("failed to validate 'dimensions'"));
51 }
52
53 try {
54 auto type = read_scalar_string_dataset(group.openDataSet("type"));
55 if (type == "BOOLEAN") {
56 output.type = BOOLEAN;
57 } else if (type == "INTEGER") {
58 output.type = INTEGER;
59 } else if (type == "FLOAT") {
60 output.type = FLOAT;
61 } else if (type == "STRING") {
62 output.type = STRING;
63 } else {
64 throw std::runtime_error("unknown type '" + type + "'");
65 }
66 } catch (...) {
67 std::throw_with_nested(std::runtime_error("failed to validate 'type'"));
68 }
69
70 return output;
71}
88inline ArrayDetails validate_custom_array(const H5::Group& group, const ritsuko::Version& version, const Options& options) {
89 return validate_minimal_array(group, version, options);
90}
91
92}
93
94#endif
Namespace for all chihaya functions.
Definition binary_arithmetic.hpp:21
ArrayDetails validate_custom_array(const H5::Group &group, const ritsuko::Version &version, const Options &options)
Definition custom_array.hpp:88
Details about an array.
Definition utils_public.hpp:38
Options for validate().
Definition utils_public.hpp:79
Various public utilities.