Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions include/highfive/H5Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ class Attribute: public Object, public PathTraits<Attribute> {
template <typename T>
void read(T& array) const;

/// \brief Read the attribute into a pre-allocated buffer.
/// \deprecated use `read(T&` or `read_raw`.
template <typename T>
void read(T* array, const DataType& mem_datatype) const;

/// \brief Read the attribute into a buffer.
/// \deprecated use `read(T&` or `read_raw`.
template <typename T>
void read(T* array) const;

/// \brief Read the attribute into a pre-allocated buffer.
/// \param array A pointer to the first byte of sufficient pre-allocated memory.
/// \param mem_datatype The DataType of the array.
Expand All @@ -132,7 +142,7 @@ class Attribute: public Object, public PathTraits<Attribute> {
/// \endcode
/// \since 2.2.2
template <typename T>
void read(T* array, const DataType& mem_datatype) const;
void read_raw(T* array, const DataType& mem_datatype) const;

/// \brief Read the attribute into a buffer.
/// Behaves like Attribute::read(T*, const DataType&) const but
Expand All @@ -154,7 +164,7 @@ class Attribute: public Object, public PathTraits<Attribute> {
/// \endcode
/// \since 2.2.2
template <typename T>
void read(T* array) const;
void read_raw(T* array) const;

/// \brief Write the value into the Attribute.
///
Expand Down
14 changes: 12 additions & 2 deletions include/highfive/bits/H5Attribute_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ inline void Attribute::read(T& array) const {
}

auto r = details::data_converter::get_reader<T>(dims, array, file_datatype);
read(r.getPointer(), buffer_info.data_type);
read_raw(r.getPointer(), buffer_info.data_type);
// re-arrange results
r.unserialize(array);

Expand All @@ -103,6 +103,11 @@ inline void Attribute::read(T& array) const {

template <typename T>
inline void Attribute::read(T* array, const DataType& mem_datatype) const {
read_raw(array, mem_datatype);
}

template <typename T>
inline void Attribute::read_raw(T* array, const DataType& mem_datatype) const {
static_assert(!std::is_const<T>::value,
"read() requires a non-const structure to read data into");

Expand All @@ -111,10 +116,15 @@ inline void Attribute::read(T* array, const DataType& mem_datatype) const {

template <typename T>
inline void Attribute::read(T* array) const {
read_raw(array);
}

template <typename T>
inline void Attribute::read_raw(T* array) const {
using element_type = typename details::inspector<T>::base_type;
const DataType& mem_datatype = create_and_check_datatype<element_type>();

read(array, mem_datatype);
read_raw(array, mem_datatype);
}

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/tests_high_five_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,7 @@ TEST_CASE("DirectWriteBool") {
SECTION("WriteReadCycleAttribute") {
auto attr = file.createAttribute("attr", dataspace, datatype);
attr.write_raw(expected);
attr.read(actual);
attr.read_raw(actual);

for (size_t i = 0; i < n; ++i) {
REQUIRE(expected[i] == actual[i]);
Expand All @@ -2123,7 +2123,7 @@ TEST_CASE("DirectWriteBool") {
SECTION("WriteReadCycleDataSet") {
auto dset = file.createAttribute("dset", dataspace, datatype);
dset.write_raw(expected);
dset.read(actual);
dset.read_raw(actual);

for (size_t i = 0; i < n; ++i) {
REQUIRE(expected[i] == actual[i]);
Expand Down