1#ifndef CHIHAYA_UNARY_COMPARISON_HPP
2#define CHIHAYA_UNARY_COMPARISON_HPP
5#include "ritsuko/ritsuko.hpp"
6#include "ritsuko/hdf5/hdf5.hpp"
11#include "utils_comparison.hpp"
12#include "utils_unary.hpp"
13#include "utils_misc.hpp"
14#include "utils_type.hpp"
27namespace unary_comparison {
38 auto seed_details = internal_misc::load_seed_details(handle,
"seed", version, options);
41 auto method = internal_unary::load_method(handle);
42 if (!internal_comparison::is_valid_operation(method)) {
43 throw std::runtime_error(
"unrecognized operation in 'method' (got '" + method +
"')");
46 auto side = internal_unary::load_side(handle);
47 if (side !=
"left" && side !=
"right") {
48 throw std::runtime_error(
"'side' should be either 'left' or 'right' (got '" + side +
"')");
52 auto vhandle = ritsuko::hdf5::open_dataset(handle,
"value");
54 if (version.lt(1, 1, 0)) {
55 if ((seed_details.type == STRING) != (vhandle.getTypeClass() == H5T_STRING)) {
56 throw std::runtime_error(
"both or neither of 'seed' and 'value' should contain strings");
59 auto type = ritsuko::hdf5::open_and_load_scalar_string_attribute(vhandle,
"type");
60 auto tt = internal_type::translate_type_1_1(type);
61 if ((tt == STRING) != (seed_details.type == STRING)) {
62 throw std::runtime_error(
"both or neither of 'seed' and 'value' should contain strings");
64 internal_type::check_type_1_1(vhandle, tt);
67 internal_misc::validate_missing_placeholder(vhandle, version);
69 size_t ndims = vhandle.getSpace().getSimpleExtentNdims();
71 if (vhandle.getTypeClass() == H5T_STRING) {
72 ritsuko::hdf5::validate_scalar_string_dataset(vhandle);
75 }
else if (ndims == 1) {
77 vhandle.getSpace().getSimpleExtentDims(&extent);
78 internal_unary::check_along(handle, version, seed_details.dimensions, extent);
79 if (vhandle.getTypeClass() == H5T_STRING) {
80 ritsuko::hdf5::validate_1d_string_dataset(vhandle, extent, 1000000);
84 throw std::runtime_error(
"dataset should be scalar or 1-dimensional");
87 }
catch (std::exception& e) {
88 throw std::runtime_error(
"failed to validate 'value'; " + std::string(e.what()));
92 seed_details.type = BOOLEAN;
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: unary_comparison.hpp:37
Namespace for all chihaya functions.
Definition: binary_arithmetic.hpp:22
Details about an array.
Definition: utils_public.hpp:36
Validation options.
Definition: utils_public.hpp:66
bool details_only
Definition: utils_public.hpp:71
Various public utilities.