20#include "../H5DataSpace.hpp"
28 return details::get_name(
29 [&](
char* buffer,
size_t length) {
return H5Aget_name(
_hid, length, buffer); });
33 return static_cast<size_t>(H5Aget_storage_size(
_hid));
44 if ((space.
_hid = H5Aget_space(
_hid)) < 0) {
45 HDF5ErrMapper::ToException<AttributeException>(
"Unable to get DataSpace out of Attribute");
64 const details::BufferInfo<T> buffer_info(
66 [
this]() -> std::string {
return this->
getName(); },
67 details::BufferInfo<T>::read);
69 if (!details::checkDimensions(mem_space, buffer_info.n_dimensions)) {
70 std::ostringstream ss;
72 <<
" into arrays of dimensions " << buffer_info.n_dimensions;
78 auto effective_dims = details::squeezeDimensions(dims,
79 details::inspector<T>::recursive_ndim);
81 details::inspector<T>::prepare(array, effective_dims);
85 auto r = details::data_converter::get_reader<T>(dims, array);
86 read(r.get_pointer(), buffer_info.data_type);
89 auto t = create_datatype<typename details::inspector<T>::base_type>();
90 auto c = t.getClass();
92#if H5_VERSION_GE(1, 12, 0)
94 (void) H5Treclaim(t.getId(), mem_space.
getId(), H5P_DEFAULT, r.get_pointer());
97 (void) H5Dvlen_reclaim(t.getId(), mem_space.
getId(), H5P_DEFAULT, r.get_pointer());
104 static_assert(!std::is_const<T>::value,
105 "read() requires a non-const structure to read data into");
106 using element_type =
typename details::inspector<T>::base_type;
108 const DataType& mem_datatype = dtype.
empty() ? create_and_check_datatype<element_type>()
111 if (H5Aread(
getId(), mem_datatype.
getId(),
static_cast<void*
>(array)) < 0) {
112 HDF5ErrMapper::ToException<AttributeException>(
"Error during HDF5 Read: ");
124 const details::BufferInfo<T> buffer_info(
126 [
this]() -> std::string {
return this->
getName(); },
127 details::BufferInfo<T>::write);
129 if (!details::checkDimensions(mem_space, buffer_info.n_dimensions)) {
130 std::ostringstream ss;
131 ss <<
"Impossible to write buffer of dimensions " << buffer_info.n_dimensions
135 auto w = details::data_converter::serialize<T>(buffer);
136 write_raw(w.get_pointer(), buffer_info.data_type);
141 using element_type =
typename details::inspector<T>::base_type;
142 const auto& mem_datatype = dtype.
empty() ? create_and_check_datatype<element_type>() : dtype;
144 if (H5Awrite(
getId(), mem_datatype.getId(), buffer) < 0) {
145 HDF5ErrMapper::ToException<DataSetException>(
"Error during HDF5 Write: ");
void write_raw(const T *buffer, const DataType &dtype={})
Write a buffer to this attribute.
Definition H5Attribute_misc.hpp:140
DataSpace getSpace() const
getSpace
Definition H5Attribute_misc.hpp:42
DataType getDataType() const
getDataType
Definition H5Attribute_misc.hpp:36
std::string getName() const
return the name of the current attribute
Definition H5Attribute_misc.hpp:27
void write(const T &buffer)
Definition H5Attribute_misc.hpp:117
T read() const
Return the attribute.
Definition H5Attribute_misc.hpp:55
DataSpace getMemSpace() const
getMemSpace
Definition H5Attribute_misc.hpp:50
size_t getStorageSize() const
Definition H5Attribute_misc.hpp:32
Exception specific to HighFive DataSpace interface.
Definition H5Exception.hpp:112
Class representing the space (dimensions) of a dataset.
Definition H5DataSpace.hpp:25
size_t getNumberDimensions() const
getNumberDimensions
Definition H5Dataspace_misc.hpp:93
size_t getElementCount() const
getElementCount
Definition H5Dataspace_misc.hpp:112
std::vector< size_t > getDimensions() const
getDimensions
Definition H5Dataspace_misc.hpp:102
HDF5 Data Type.
Definition H5DataType.hpp:54
bool empty() const noexcept
Check the DataType was default constructed. Such value might represent auto-detection of the datatype...
Definition H5DataType_misc.hpp:35
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:65
hid_t _hid
Definition H5Object.hpp:105
Definition H5_definitions.hpp:15