9#ifndef H5ATTRIBUTE_MISC_HPP
10#define H5ATTRIBUTE_MISC_HPP
19#include <boost/multi_array.hpp>
25#include "H5Converter_misc.hpp"
31 return details::get_name([&](
char *buffer, hsize_t length) {
32 return H5Aget_name(_hid, length, buffer);
37 return static_cast<size_t>(H5Aget_storage_size(_hid));
42 res._hid = H5Aget_type(_hid);
48 if ((space._hid = H5Aget_space(_hid)) < 0) {
49 HDF5ErrMapper::ToException<AttributeException>(
50 "Unable to get DataSpace out of Attribute");
57inline File Attribute::getFile()
const {
58 hid_t fileId = H5Iget_file_id(_hid);
59 if (!H5Iis_valid(fileId)){
60 HDF5ErrMapper::ToException<AttributeException>(
61 std::string(
"File ID is invalid. Probably the object doesn't belong to any file"));
63 return File::FromId(fileId,
false);
69 static_assert(!std::is_const<typename std::remove_reference<T>::type>::value,
70 "read() requires a non-const array to read into");
71 using element_type =
typename details::inspector<T>::base_type;
76 if (!details::checkDimensions(mem_space, dim_array)) {
77 std::ostringstream ss;
78 ss <<
"Impossible to read attribute of dimensions "
84 const DataType mem_datatype = create_and_check_datatype<element_type>();
89 if (H5Aread(
getId(
false), mem_datatype.
getId(
false),
90 static_cast<void*
>(converter.transform_read(array))) < 0) {
91 HDF5ErrMapper::ToException<AttributeException>(
92 "Error during HDF5 Read: ");
96 converter.process_result(array);
101 static_assert(!std::is_const<T>::value,
102 "read() requires a non-const structure to read data into");
103 const auto& mem_datatype = dtype.
empty() ? create_and_check_datatype<T>() : dtype;
105 if (H5Aread(
getId(
false), mem_datatype.getId(
false),
106 static_cast<void*
>(array)) < 0) {
107 HDF5ErrMapper::ToException<AttributeException>(
108 "Error during HDF5 Read: ");
114 using element_type =
typename details::inspector<T>::base_type;
119 if (!details::checkDimensions(mem_space, dim_buffer)) {
120 std::ostringstream ss;
121 ss <<
"Impossible to write buffer of dimensions " << dim_buffer
122 <<
" into attribute of dimensions "
127 const DataType mem_datatype = create_and_check_datatype<element_type>();
130 if (H5Awrite(
getId(
false), mem_datatype.
getId(
false),
131 static_cast<const void*
>(converter.transform_write(buffer))) < 0) {
132 HDF5ErrMapper::ToException<DataSetException>(
133 "Error during HDF5 Write: ");
139 const DataType mem_datatype = dtype.
empty() ? create_and_check_datatype<T>() : dtype;
141 if (H5Awrite(
getId(
false), mem_datatype.
getId(
false), buffer) < 0) {
142 HDF5ErrMapper::ToException<DataSetException>(
143 "Error during HDF5 Write: ");
void write(const T &buffer)
Definition H5Attribute_misc.hpp:113
DataType getDataType() const
getDataType
Definition H5Attribute_misc.hpp:40
void write_raw(const T *buffer, const DataType &dtype=DataType())
Definition H5Attribute_misc.hpp:138
void read(T &array) const
Definition H5Attribute_misc.hpp:68
DataSpace getMemSpace() const
getMemSpace
Definition H5Attribute_misc.hpp:55
std::string getName() const
return the name of the current attribute
Definition H5Attribute_misc.hpp:30
size_t getStorageSize() const
getStorageSize
Definition H5Attribute_misc.hpp:36
DataSpace getSpace() const
getSpace
Definition H5Attribute_misc.hpp:46
Exception specific to h5gt 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:48
bool empty() const noexcept
Check the DataType was default constructed. Such value might represent auto-detection of the datatype...
Definition H5DataType_misc.hpp:28
File class.
Definition H5File.hpp:25
hid_t getId(const bool &increaseRefCount=false) const noexcept
getId
Definition H5Object_misc.hpp:172
Definition H5Converter_misc.hpp:124
Definition H5Utils.hpp:49