1#ifndef CHIHAYA_CONSTANT_ARRAY_HPP
2#define CHIHAYA_CONSTANT_ARRAY_HPP
10#include "ritsuko/ritsuko.hpp"
11#include "ritsuko/hdf5/hdf5.hpp"
23namespace constant_array {
37 auto dhandle = ritsuko::hdf5::open_dataset(handle,
"dimensions");
38 size_t size = ritsuko::hdf5::get_1d_length(dhandle,
false);
40 throw std::runtime_error(
"'dimensions' should have non-zero length");
43 if (version.lt(1, 1, 0)) {
44 if (dhandle.getTypeClass() != H5T_INTEGER) {
45 throw std::runtime_error(
"'dimensions' should be integer");
47 std::vector<int> dims_tmp(size);
48 dhandle.read(dims_tmp.data(), H5::PredType::NATIVE_INT);
49 for (
auto d : dims_tmp) {
51 throw std::runtime_error(
"'dimensions' should contain non-negative values");
57 if (ritsuko::hdf5::exceeds_integer_limit(dhandle, 64,
false)) {
58 throw std::runtime_error(
"datatype of 'dimensions' should fit inside a 64-bit unsigned integer");
60 std::vector<uint64_t> dims(size);
61 dhandle.read(dims.data(), H5::PredType::NATIVE_UINT64);
67 auto vhandle = ritsuko::hdf5::open_dataset(handle,
"value");
68 if (!ritsuko::hdf5::is_scalar(vhandle)) {
69 throw std::runtime_error(
"'value' should be a scalar");
73 if (version.lt(1, 1, 0)) {
74 output.
type = internal_type::translate_type_0_0(vhandle.getTypeClass());
76 auto type = ritsuko::hdf5::open_and_load_scalar_string_attribute(vhandle,
"type");
77 output.
type = internal_type::translate_type_1_1(type);
78 internal_type::check_type_1_1(vhandle, output.
type);
81 if (!options.details_only) {
82 internal_misc::validate_missing_placeholder(vhandle, version);
85 if (vhandle.getTypeClass() == H5T_STRING) {
86 ritsuko::hdf5::validate_scalar_string_dataset(vhandle);
89 }
catch (std::exception& e) {
90 throw std::runtime_error(
"failed to validate 'value'; " + std::string(e.what()));
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: constant_array.hpp:33
Namespace for all chihaya functions.
Definition: binary_arithmetic.hpp:22
Details about an array.
Definition: utils_public.hpp:36
std::vector< size_t > dimensions
Definition: utils_public.hpp:56
ArrayType type
Definition: utils_public.hpp:50
Validation options.
Definition: utils_public.hpp:66