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 const std::string type_name = "string_factor"; // use a separate variable to avoid dangling reference warnings from GCC.
34 const auto& vstring = internal_json::extract_version_for_type(metadata.other, type_name);
35 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(), /* skip_patch = */ true);
36 if (version.major != 1) {
37 throw std::runtime_error("unsupported version string '" + vstring + "'");
38 }
39
40 auto handle = ritsuko::hdf5::open_file(path / "contents.h5");
41 auto ghandle = ritsuko::hdf5::open_group(handle, type_name.c_str());
42 internal_factor::check_ordered_attribute(ghandle);
43
44 size_t num_levels = internal_factor::validate_factor_levels(ghandle, "levels", options.hdf5_buffer_size);
45 size_t num_codes = internal_factor::validate_factor_codes(ghandle, "codes", num_levels, options.hdf5_buffer_size);
46
47 internal_string::validate_names(ghandle, "names", num_codes, options.hdf5_buffer_size);
48}
49
56inline size_t height(const std::filesystem::path& path, [[maybe_unused]] const ObjectMetadata& metadata, [[maybe_unused]] Options& options) {
57 auto handle = ritsuko::hdf5::open_file(path / "contents.h5");
58 auto ghandle = handle.openGroup("string_factor");
59 auto dhandle = ghandle.openDataSet("codes");
60 return ritsuko::hdf5::get_1d_length(dhandle.getSpace(), false);
61}
62
63}
64
65}
66
67#endif
size_t height(const std::filesystem::path &path, const ObjectMetadata &metadata, Options &options)
Definition string_factor.hpp:56
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.