diff --git a/src/hdf5_interface.h b/src/hdf5_interface.h index 00d0c51227..121b2c6c79 100644 --- a/src/hdf5_interface.h +++ b/src/hdf5_interface.h @@ -193,7 +193,20 @@ void read_attribute(hid_t obj_id, const char* name, xt::xarray& arr) arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape); } -template +// specialization for std::string +template<> inline void +read_attribute(hid_t obj_id, const char* name, std::string& str) +{ + // Create buffer to read data into + auto n = attribute_typesize(obj_id, name); + char buffer[n]; + + // Read attribute and set string + read_attr_string(obj_id, name, n, buffer); + str = std::string{buffer, n}; +} + +template void read_dataset(hid_t obj_id, const char* name, T buffer, bool indep=false) { read_dataset(obj_id, name, H5TypeMap::type_id, &buffer, indep);