22#ifndef LIBH5_STL_VARIANT_HPP
23#define LIBH5_STL_VARIANT_HPP
42 template <
typename... T>
44 static std::string invoke() =
delete;
57 template <
typename... Ts>
58 void h5_write(
group g, std::string
const &name, std::variant<Ts...>
const &v) {
59 std::visit([&](
auto const &x) {
h5_write(g, name, x); }, v);
65 template <
typename VT,
typename U,
typename... Ts>
66 void h5_read_variant_helper(VT &v,
datatype dt, group g, std::string
const &name) {
72 if constexpr (
sizeof...(Ts) > 0)
73 h5_read_variant_helper<VT, Ts...>(v, dt, g, name);
75 throw std::runtime_error(
"Error in h5_read_variant_helper: Type stored in the variant has no corresponding HDF5 datatype");
91 template <
typename... Ts>
92 void h5_read(
group g, std::string
const &name, std::variant<Ts...> &v) {
97 detail::h5_read_variant_helper<std::variant<Ts...>, Ts...>(v, dt, g, name);
A handle to an HDF5 group.
dataset open_dataset(std::string const &key) const
Open a dataset with the given key in the group.
A generic handle for HDF5 objects.
Provides a generic interface for reading/writing data from/to various HDF5 objects.
Provides a handle to an HDF5 group and various methods to simplify the creation/opening of subgroups,...
object datatype
Type alias for an HDF5 datatype.
bool hdf5_type_equal(datatype dt1, datatype dt2)
Check if two HDF5 datatypes are equal.
datatype hdf5_type()
Map a given C++ type to an HDF5 datatype.
datatype get_hdf5_type(dataset ds)
Get the HDF5 type stored in a given h5::dataset.
T h5_read(group g, std::string const &key)
Generic implementation for reading from an HDF5 dataset/subgroup.
void h5_write(group g, std::string const &name, T const &x) H5_REQUIRES(std
Write a scalar to an HDF5 dataset.
Provides functions to read/write std::string, char* and h5::char_buf objects from/to HDF5.