takane
Validators for ArtifactDB file formats
Loading...
Searching...
No Matches
string_factor.hpp
Go to the documentation of this file.
1#ifndef TAKANE_STRING_FACTOR_HPP
2#define TAKANE_STRING_FACTOR_HPP
3
4#include <string>
5#include <stdexcept>
6#include <filesystem>
7
8#include "ritsuko/hdf5/hdf5.hpp"
9
10#include "utils_public.hpp"
11#include "utils_string.hpp"
12#include "utils_factor.hpp"
13
19namespace takane {
20
25namespace string_factor {
26
32inline void validate(const std::filesystem::path& path, const ObjectMetadata& metadata, Options& options) {
33 auto vstring = internal_json::extract_version_for_type(metadata.other, "string_factor");
34 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(), /* skip_patch = */ true);
35 if (version.major != 1) {
36 throw std::runtime_error("unsupported version string '" + vstring + "'");
37 }
38
39 auto handle = ritsuko::hdf5::open_file(path / "contents.h5");
40 auto ghandle = ritsuko::hdf5::open_group(handle, "string_factor");
41 internal_factor::check_ordered_attribute(ghandle);
42
43 size_t num_levels = internal_factor::validate_factor_levels(ghandle, "levels", options.hdf5_buffer_size);
44 size_t num_codes = internal_factor::validate_factor_codes(ghandle, "codes", num_levels, options.hdf5_buffer_size);
45
46 internal_string::validate_names(ghandle, "names", num_codes, options.hdf5_buffer_size);
47}
48
55inline size_t height(const std::filesystem::path& path, [[maybe_unused]] const ObjectMetadata& metadata, [[maybe_unused]] Options& options) {
56 auto handle = ritsuko::hdf5::open_file(path / "contents.h5");
57 auto ghandle = handle.openGroup("string_factor");
58 auto dhandle = ghandle.openDataSet("codes");
59 return ritsuko::hdf5::get_1d_length(dhandle.getSpace(), false);
60}
61
62}
63
64}
65
66#endif
size_t height(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition string_factor.hpp:55
void validate(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition string_factor.hpp:32
takane validation functions.
Definition _derived_from.hpp:15
Object metadata, including the type and other fields.
Definition utils_public.hpp:26
std::unordered_map< std::string, std::shared_ptr< millijson::Base > > other
Definition utils_public.hpp:35
Validation options.
Definition utils_public.hpp:94
hsize_t hdf5_buffer_size
Definition utils_public.hpp:103
Exported utilities.