|
27 | 27 | #include "openPMD/auxiliary/JSON_internal.hpp" |
28 | 28 | #include "openPMD/auxiliary/Variant.hpp" |
29 | 29 | #include <H5Ppublic.h> |
| 30 | +#include <nlohmann/json.hpp> |
30 | 31 | #include <optional> |
31 | 32 | #include <sstream> |
32 | 33 | #include <stdexcept> |
@@ -600,6 +601,65 @@ namespace |
600 | 601 | } |
601 | 602 | throw id_error(); |
602 | 603 | }(); |
| 604 | + byID.flags = [&]() -> unsigned int { |
| 605 | + if (!json_accessor(filter_config).contains("flags")) |
| 606 | + { |
| 607 | + return 0; |
| 608 | + } |
| 609 | + auto const &flag_config = json_accessor(filter_config["flags"]); |
| 610 | + using pair_t = std::pair<std::string, unsigned int>; |
| 611 | + std::array<pair_t, 2> filter_types{ |
| 612 | + pair_t{"optional", H5Z_FLAG_OPTIONAL}, |
| 613 | + pair_t{"mandatory", H5Z_FLAG_MANDATORY}}; |
| 614 | + auto flag_error = [&]() { |
| 615 | + std::stringstream error; |
| 616 | + error |
| 617 | + << "Must be either of unsigned integer type or one of:"; |
| 618 | + for (auto const &pair : filter_types) |
| 619 | + { |
| 620 | + error << " '" << pair.first << "'"; |
| 621 | + } |
| 622 | + error << "."; |
| 623 | + return error::BackendConfigSchema( |
| 624 | + {"hdf5", "dataset", "permanent_filters", "flags"}, |
| 625 | + error.str()); |
| 626 | + }; |
| 627 | + if (flag_config.is_number_integer()) |
| 628 | + { |
| 629 | + return flag_config.template get<unsigned int>(); |
| 630 | + } |
| 631 | + auto maybe_string = json::asLowerCaseStringDynamic(flag_config); |
| 632 | + if (!maybe_string.has_value()) |
| 633 | + { |
| 634 | + throw flag_error(); |
| 635 | + } |
| 636 | + for (auto const &[key, res_type] : filter_types) |
| 637 | + { |
| 638 | + if (*maybe_string == key) |
| 639 | + { |
| 640 | + return res_type; |
| 641 | + } |
| 642 | + } |
| 643 | + throw flag_error(); |
| 644 | + }(); |
| 645 | + if (json_accessor(filter_config).contains("c_values")) |
| 646 | + { |
| 647 | + auto const &c_values_config = |
| 648 | + json_accessor(filter_config["c_values"]); |
| 649 | + try |
| 650 | + { |
| 651 | + |
| 652 | + byID.c_values = |
| 653 | + c_values_config |
| 654 | + .template get<std::vector<unsigned int>>(); |
| 655 | + } |
| 656 | + catch (nlohmann::json::type_error const &) |
| 657 | + { |
| 658 | + throw error::BackendConfigSchema( |
| 659 | + {"hdf5", "dataset", "permanent_filters", "c_values"}, |
| 660 | + "Must be an array of unsigned integers."); |
| 661 | + } |
| 662 | + } |
603 | 663 | return byID; |
604 | 664 | } |
605 | 665 | break; |
|
0 commit comments