22#ifndef LIBH5_STL_MAP_HPP
23#define LIBH5_STL_MAP_HPP
42 template <
typename keyT,
typename valueT>
44 static std::string invoke() {
return "Dict"; }
56 template <
typename keyT,
typename valueT>
57 void h5_write(
group g, std::string
const &name, std::map<keyT, valueT>
const &m) {
63 if constexpr (std::is_same_v<keyT, std::string>) {
65 for (
auto const &[key, val] : m)
h5_write(gr, key, val);
69 for (
auto const &[key, val] : m) {
70 auto element_gr = gr.create_group(std::to_string(idx));
87 template <
typename keyT,
typename valueT>
88 void h5_read(
group g, std::string
const &name, std::map<keyT, valueT> &m) {
94 for (
auto const &x : gr.get_all_subgroup_dataset_names()) {
96 if constexpr (std::is_same_v<keyT, std::string>) {
99 m.emplace(x, std::move(val));
102 auto element_gr = gr.open_group(x);
104 h5_read(element_gr,
"key", key);
105 h5_read(element_gr,
"val", val);
106 m.emplace(std::move(key), std::move(val));
A handle to an HDF5 group.
group create_group(std::string const &key, bool delete_if_exists=true) const
Create a subgroup with the given key in the group.
group open_group(std::string const &key) const
Open a subgroup with the given key in the group.
Provides a handle to an HDF5 group and various methods to simplify the creation/opening of subgroups,...
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.