4#ifndef DUNE_FUFEM_HDF5_ATTRIBUTES_HH
5#define DUNE_FUFEM_HDF5_ATTRIBUTES_HH
9#if __has_include(<hdf5.h>)
19 : grouplike_(grouplike), key_(key) {}
21 bool exists()
const {
return H5Aexists(grouplike_.c_obj(), key_.c_str()); }
24 hid_t root = H5Gopen(grouplike_.c_obj(),
"/", H5P_DEFAULT);
25 hid_t attr = H5Aopen_name(root, key_.c_str());
27 hid_t attrtype = H5Aget_type(attr);
28 if (H5Tget_class(attrtype) != H5T_STRING)
30 "Only string attributes are supported");
32 if (H5Tis_variable_str(attrtype))
34 "Variable-size attributes are not supported");
36 hid_t nativetype = H5Tget_native_type(attrtype, H5T_DIR_ASCEND);
38 if (H5Aread(attr, nativetype, buffer.data()) < 0)
45 return {buffer.begin(), buffer.end()};
49 hid_t stringtype = H5Tcopy(H5T_C_S1);
50 H5Tset_size(stringtype,
value.size());
51 hid_t dataspace = H5Screate(H5S_SCALAR);
53 hid_t root = H5Gopen(grouplike_.c_obj(),
"/", H5P_DEFAULT);
54 hid_t attr = H5Acreate(root, key_.c_str(), stringtype, dataspace,
55 H5P_DEFAULT, H5P_DEFAULT);
56 H5Awrite(attr, stringtype,
value.c_str());
65 Grouplike &grouplike_;
71 #warning Including the hdf5/attributes.hh but hdf5.h is missing.
static TupleAccessTraits< typenameAtType< N, Tuple >::Type >::NonConstType get(Tuple &t)
bool exists(size_type i, size_type j) const
#define DUNE_THROW(E,...)