22#ifndef LIBH5_STL_VECTOR_HPP
23#define LIBH5_STL_VECTOR_HPP
38 namespace array_interface {
52 res.parent_shape[0] = v.size();
64 H5_SPECIALIZE_FORMAT2(std::vector<std::string>, vector<string>);
69 static std::string invoke() {
return "List"; }
118 template <
typename T>
123 }
else if constexpr (std::is_same_v<T, std::string> or std::is_same_v<T, std::vector<std::string>>) {
130 for (
int i = 0; i < v.size(); ++i)
h5_write(gr, std::to_string(i), v[i]);
148 template <
typename T>
151 if (not g.
has_key(name))
throw make_runtime_error(
"Error in h5_read: Dataset/Subgroup with name ", name,
" does not exist");
156 v.resize(g2.get_all_dataset_names().size() + g2.get_all_subgroup_names().size());
157 for (
int i = 0; i < v.size(); ++i) {
h5_read(g2, std::to_string(i), v[i]); }
163 throw make_runtime_error(
"Error in h5_read: Reading a vector from an array of rank ", ds_info.rank(),
" is not allowed");
164 v.resize(ds_info.lengths[0]);
166 }
else if constexpr (std::is_same_v<T, std::string> or std::is_same_v<T, std::vector<std::string>>) {
173 throw make_runtime_error(
"Error in h5_read: HDF5 datatype not supported for reading into a std::vector");
185 void h5_write_attribute(
object obj, std::string
const &name, std::vector<std::vector<std::string>>
const &v);
194 void h5_read_attribute(
object obj, std::string
const &name, std::vector<std::vector<std::string>> &v);
203 void h5_write_attribute(
object obj, std::string
const &name, std::vector<std::string>
const &v);
212 void h5_read_attribute(
object obj, std::string
const &name, std::vector<std::string> &v);
A handle to an HDF5 group.
bool has_subgroup(std::string const &key) const
Check if a subgroup with the given key exists in the group and is accessible.
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.
bool has_key(std::string const &key) const
Check if a link with the given key exists in the group.
Provides a compound type and type traits for complex numbers.
Provides a handle to an HDF5 group and various methods to simplify the creation/opening of subgroups,...
constexpr bool is_complex_v
Boolean type trait set to true for std::complex types.
datatype hdf5_type()
Map a given C++ type to an HDF5 datatype.
void read(group g, std::string const &name, array_view v, hyperslab sl)
Read a given hyperslab from an HDF5 dataset into an array view.
dataset_info get_dataset_info(dataset ds)
Retrieve the shape and the h5::datatype from a dataset.
void write(group g, std::string const &name, array_view const &v, bool compress)
Write an array view to an HDF5 dataset.
array_view array_view_from_vector(std::vector< T > const &v)
Create an h5::array_interface::array_view for a std::vector.
T h5_read(group g, std::string const &key)
Generic implementation for reading from an HDF5 dataset/subgroup.
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) H5_REQUIRES(std
Write a scalar to an HDF5 dataset.
void h5_write_attribute(object obj, std::string const &name, T const &x) H5_REQUIRES(std
Write a scalar to an HDF5 attribute.
void from_char_buf(char_buf const &cb, std::vector< std::string > &v)
Create a vector of strings from an h5::char_buf.
char_buf to_char_buf(std::vector< std::string > const &v)
Create an h5::char_buf from a vector of strings.
std::runtime_error make_runtime_error(Ts const &...ts)
Create a std::runtime_error with an error message constructed from the given arguments.
Provides a generic interface to read/write scalars from/to HDF5.
Provides functions to read/write std::string, char* and h5::char_buf objects from/to HDF5.
Struct representing a view on an n-dimensional array/dataspace.
hyperslab slab
h5::array_interface::hyperslab specifying the selection of the view.
v_t count
Number of elements or blocks to select along each dimension.
Stores an arbitrary number of strings in a 1-dimensional std::vector<char>.
Provides some utility functions for h5.