22#ifndef LIBH5_STL_VARIANT_HPP
23#define LIBH5_STL_VARIANT_HPP
43 template <
typename... T>
45 static std::string invoke() =
delete;
58 template <
typename... Ts>
59 void h5_write(
group g, std::string
const &name, std::variant<Ts...>
const &v) {
60 std::visit([&](
auto const &x) {
h5_write(g, name, x); }, v);
74 template <
typename T,
typename... Ts>
75 void h5_read(
group g, std::string
const &name, std::variant<T, Ts...> &v) {
78 auto try_read = [&]<
typename U>(std::type_identity<U>) {
83 if ((
try_read(std::type_identity<T>{}) || ... ||
try_read(std::type_identity<Ts>{})))
return;
84 throw std::runtime_error(
"Error in h5_read for std::variant: stored HDF5 datatype matches no variant alternative (allowed: "
98 template <
typename... Ts>
113 template <
typename T,
typename... Ts>
116 auto try_read = [&]<
typename U>(std::type_identity<U>) {
121 if ((
try_read(std::type_identity<T>{}) || ... ||
try_read(std::type_identity<Ts>{})))
return;
122 throw std::runtime_error(
"Error in h5_read_attribute for std::variant: stored HDF5 datatype matches no variant alternative (allowed: "
A handle to an HDF5 group.
dataset open_dataset(std::string const &key) const
Open a dataset with the given key in the group.
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.
object dataset
Type alias for an HDF5 dataset.
bool hdf5_type_equal(datatype dt1, datatype dt2)
Check if two HDF5 datatypes are equal.
datatype get_hdf5_attribute_type(object obj, std::string const &name)
Get the HDF5 type of a named attribute attached to a given h5::object.
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.
std::string get_name_of_h5_type(datatype dt)
Get the name of an h5::datatype (for error messages).
T h5_read(group g, std::string const &key)
Generic implementation for reading from an HDF5 dataset/subgroup.
bool try_read(group g, std::string const &key, T &x)
Check if an HDF5 dataset/subgroup with the given key exists in the given parent group before performi...
T h5_read_attribute(object obj, std::string const &name)
Generic implementation for reading an HDF5 attribute.
void h5_write(group g, std::string const &name, T const &x)
Write a scalar to an HDF5 dataset.
void h5_write_attribute(object, std::string const &, std::string const &)
Write a std::string to an HDF5 attribute.
Provides functions to read/write std::string, char* and h5::char_buf objects from/to HDF5.