9 #ifndef H5ATTRIBUTE_MISC_HPP
10 #define H5ATTRIBUTE_MISC_HPP
19 #include <boost/multi_array.hpp>
22 #include <H5Apublic.h>
23 #include <H5Ppublic.h>
32 return details::get_name([&](
char *buffer, hsize_t length) {
33 return H5Aget_name(
_hid,
static_cast<size_t>(length), buffer);
38 return static_cast<size_t>(H5Aget_storage_size(
_hid));
49 if ((space.
_hid = H5Aget_space(
_hid)) < 0) {
50 HDF5ErrMapper::ToException<AttributeException>(
51 "Unable to get DataSpace out of Attribute");
61 const details::BufferInfo<T> buffer_info(
getDataType(),
62 [
this]() -> std::string {
return this->
getName(); });
64 if (!details::checkDimensions(mem_space, buffer_info.n_dimensions)) {
65 std::ostringstream ss;
66 ss <<
"Impossible to read DataSet of dimensions "
68 << buffer_info.n_dimensions;
71 details::data_converter<T> converter(mem_space);
72 read(converter.transform_read(array), buffer_info.data_type);
74 converter.process_result(array);
79 static_assert(!std::is_const<T>::value,
80 "read() requires a non-const structure to read data into");
81 using element_type =
typename details::inspector<T>::base_type;
84 dtype.
empty() ? create_and_check_datatype<element_type>() : dtype;
87 static_cast<void*
>(array)) < 0) {
88 HDF5ErrMapper::ToException<AttributeException>(
89 "Error during HDF5 Read: ");
96 const details::BufferInfo<T> buffer_info(
getDataType(),
97 [
this]() -> std::string {
return this->
getName(); });
99 if (!details::checkDimensions(mem_space, buffer_info.n_dimensions)) {
100 std::ostringstream ss;
101 ss <<
"Impossible to write buffer of dimensions " << buffer_info.n_dimensions
105 details::data_converter<T> converter(mem_space);
106 write_raw(converter.transform_write(buffer), buffer_info.data_type);
109 template <
typename T>
111 using element_type =
typename details::inspector<T>::base_type;
112 const auto& mem_datatype =
113 dtype.
empty() ? create_and_check_datatype<element_type>() : dtype;
115 if (H5Awrite(
getId(), mem_datatype.getId(), buffer) < 0) {
116 HDF5ErrMapper::ToException<DataSetException>(
117 "Error during HDF5 Write: ");
void write_raw(const T *buffer, const DataType &dtype=DataType())
Definition: H5Attribute_misc.hpp:110
DataSpace getSpace() const
getSpace
Definition: H5Attribute_misc.hpp:47
DataType getDataType() const
getDataType
Definition: H5Attribute_misc.hpp:41
std::string getName() const
return the name of the current attribute
Definition: H5Attribute_misc.hpp:31
void write(const T &buffer)
Definition: H5Attribute_misc.hpp:94
DataSpace getMemSpace() const
getMemSpace
Definition: H5Attribute_misc.hpp:56
size_t getStorageSize() const
Definition: H5Attribute_misc.hpp:37
void read(T &array) const
Definition: H5Attribute_misc.hpp:59
Exception specific to HighFive DataSpace interface.
Definition: H5Exception.hpp:99
Class representing the space (dimensions) of a dataset.
Definition: H5DataSpace.hpp:37
size_t getNumberDimensions() const
getNumberDimensions
Definition: H5Dataspace_misc.hpp:94
HDF5 Data Type.
Definition: H5DataType.hpp:42
bool empty() const noexcept
Check the DataType was default constructed. Such value might represent auto-detection of the datatype...
Definition: H5DataType_misc.hpp:28
hid_t getId() const noexcept
getId
Definition: H5Object_misc.hpp:55
hid_t _hid
Definition: H5Object.hpp:87
Definition: H5_definitions.hpp:15