ritsuko
Helper utilities for ArtifactDB C++ code
Loading...
Searching...
No Matches
Pointer.hpp
Go to the documentation of this file.
1#ifndef RITSUKO_HDF5_VLS_define_pointer_datatype_HPP
2#define RITSUKO_HDF5_VLS_define_pointer_datatype_HPP
3
4#include "H5Cpp.h"
5
6#include <stdexcept>
7#include <string>
8
10#include "../exceeds_limit.hpp"
11
17namespace ritsuko {
18
19namespace hdf5 {
20
21namespace vls {
22
32template<typename Offset_, typename Length_>
33struct Pointer {
38 Offset_ offset;
39
48 Length_ length;
49};
50
59template<typename Offset_, typename Length_>
61 typedef Pointer<Offset_, Length_> tmp;
62 H5::CompType pointer_type(sizeof(tmp));
63 pointer_type.insertMember("offset", HOFFSET(tmp, offset), as_numeric_datatype<Offset_>());
64 pointer_type.insertMember("length", HOFFSET(tmp, length), as_numeric_datatype<Length_>());
65 return pointer_type;
66}
67
85inline void validate_pointer_datatype(const H5::CompType& type, size_t offset_precision, size_t length_precision) {
86 if (type.getNmembers() != 2) {
87 throw std::runtime_error("expected VLS compound datatype to have two members");
88 }
89
90 if (type.getMemberName(0) != "offset") {
91 throw std::runtime_error("first member of a VLS compound datatype should be named 'offset'");
92 }
93 if (type.getMemberClass(0) != H5T_INTEGER) {
94 throw std::runtime_error("first member of a VLS compound datatype should have integer type");
95 }
96 auto offset_type = type.getMemberIntType(0);
97 if (exceeds_integer_limit(offset_type, offset_precision, false)) {
98 throw std::runtime_error("first member of a VLS compound datatype should not exceed a " + std::to_string(offset_precision) + "-bit unsigned integer");
99 }
100
101 if (type.getMemberName(1) != "length") {
102 throw std::runtime_error("second member of a VLS compound datatype should be named 'length'");
103 }
104 if (type.getMemberClass(0) != H5T_INTEGER) {
105 throw std::runtime_error("second member of a VLS compound datatype should have integer type");
106 }
107 auto length_type = type.getMemberIntType(1);
108 if (exceeds_integer_limit(length_type, length_precision, false)) {
109 throw std::runtime_error("second member of a VLS compound datatype should not exceed a " + std::to_string(length_precision) + "-bit unsigned integer");
110 }
111}
112
113}
114
115}
116
117}
118
119#endif
Choose a HDF5 datatype.
Check for larger-than-expected types in HDF5 datasets.
void validate_pointer_datatype(const H5::CompType &type, size_t offset_precision, size_t length_precision)
Definition Pointer.hpp:85
H5::CompType define_pointer_datatype()
Definition Pointer.hpp:60
const H5::PredType & as_numeric_datatype()
Definition as_numeric_datatype.hpp:26
bool exceeds_integer_limit(const H5::IntType &itype, size_t precision, bool is_signed)
Definition exceeds_limit.hpp:27
Assorted helper functions for parsing and validation.
Definition choose_missing_placeholder.hpp:15
Pointer into the VLS heap.
Definition Pointer.hpp:33
Offset_ offset
Definition Pointer.hpp:38
Length_ length
Definition Pointer.hpp:48