Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read_raw and prepare to deprecate read(T*, ...). #928

Merged
merged 6 commits into from
Feb 5, 2024
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
34 changes: 33 additions & 1 deletion include/highfive/bits/H5Slice_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class SliceTraits {

///
/// Read the entire dataset into a buffer
///
/// An exception is raised is if the numbers of dimension of the buffer and
/// of the dataset are different.
///
Expand All @@ -305,11 +306,13 @@ class SliceTraits {
///
/// Read the entire dataset into a raw buffer
///
/// \deprecated Use `read_raw` instead.
///
/// No dimensionality checks will be performed, it is the user's
/// responsibility to ensure that the right amount of space has been
/// allocated.
/// \param array: A buffer containing enough space for the data
/// \param dtype: The type of the data, in case it cannot be automatically guessed
/// \param dtype: The datatype of elements of the in memory buffer.
/// \param xfer_props: Data Transfer properties
template <typename T>
void read(T* array,
Expand All @@ -319,6 +322,8 @@ class SliceTraits {
///
/// Read the entire dataset into a raw buffer
///
/// \deprecated Use `read_raw` instead.
///
/// Same as `read(T*, const DataType&, const DataTransferProps&)`. However,
/// this overload deduces the HDF5 datatype of the element of `array` from
/// `T`. Note, that the file datatype is already fixed.
Expand All @@ -328,6 +333,33 @@ class SliceTraits {
template <typename T>
void read(T* array, const DataTransferProps& xfer_props = DataTransferProps()) const;

///
/// Read the entire dataset into a raw buffer
///
/// No dimensionality checks will be performed, it is the user's
/// responsibility to ensure that the right amount of space has been
/// allocated.
/// \param array: A buffer containing enough space for the data
/// \param dtype: The type of the data, in case it cannot be automatically guessed
/// \param xfer_props: Data Transfer properties
template <typename T>
void read_raw(T* array,
const DataType& dtype,
const DataTransferProps& xfer_props = DataTransferProps()) const;

///
/// Read the entire dataset into a raw buffer
///
/// Same as `read(T*, const DataType&, const DataTransferProps&)`. However,
/// this overload deduces the HDF5 datatype of the element of `array` from
/// `T`. Note, that the file datatype is already fixed.
///
/// \param array: A buffer containing enough space for the data
/// \param xfer_props: Data Transfer properties
template <typename T>
void read_raw(T* array, const DataTransferProps& xfer_props = DataTransferProps()) const;


///
/// Write the integrality N-dimension buffer to this dataset
/// An exception is raised is if the numbers of dimension of the buffer and
Expand Down
24 changes: 20 additions & 4 deletions include/highfive/bits/H5Slice_traits_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ inline void SliceTraits<Derivate>::read(T& array, const DataTransferProps& xfer_
auto dims = mem_space.getDimensions();

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

Expand All @@ -207,12 +207,26 @@ inline void SliceTraits<Derivate>::read(T& array, const DataTransferProps& xfer_
}
}


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

template <typename Derivate>
template <typename T>
inline void SliceTraits<Derivate>::read(T* array, const DataTransferProps& xfer_props) const {
read_raw(array, xfer_props);
}


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

Expand All @@ -226,13 +240,14 @@ inline void SliceTraits<Derivate>::read(T* array,
static_cast<void*>(array));
}


template <typename Derivate>
template <typename T>
inline void SliceTraits<Derivate>::read(T* array, const DataTransferProps& xfer_props) const {
inline void SliceTraits<Derivate>::read_raw(T* array, const DataTransferProps& xfer_props) const {
using element_type = typename details::inspector<T>::base_type;
const DataType& mem_datatype = create_and_check_datatype<element_type>();

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


Expand Down Expand Up @@ -276,6 +291,7 @@ inline void SliceTraits<Derivate>::write_raw(const T* buffer,
static_cast<const void*>(buffer));
}


template <typename Derivate>
template <typename T>
inline void SliceTraits<Derivate>::write_raw(const T* buffer, const DataTransferProps& xfer_props) {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/read_write_raw_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
auto nd_array = std::vector<double>(n_elements);

// Finally, read into the memory by passing a raw pointer to the library.
dataset.read<double>(nd_array.data());
dataset.read_raw<double>(nd_array.data());

Check warning on line 69 in src/examples/read_write_raw_ptr.cpp

View check run for this annotation

Codecov / codecov/patch

src/examples/read_write_raw_ptr.cpp#L69

Added line #L69 was not covered by tests
}

return 0;
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 @@ -2422,7 +2422,7 @@ TEST_CASE("HighFiveFixedString") {
// Due to missing non-const overload of `data()` until C++17 we'll
// read into something else instead (don't forget the '\0').
auto expected = std::vector<char>(n_chars, '!');
ds.read(expected.data(), datatype);
ds.read_raw(expected.data(), datatype);

CHECK(expected.size() == value.size() + 1);
for (size_t i = 0; i < value.size(); ++i) {
Expand Down Expand Up @@ -2453,7 +2453,7 @@ TEST_CASE("HighFiveFixedString") {
ds.write_raw(value.data(), datatype);

auto expected = std::vector<char>(value.size(), '-');
ds.read(expected.data(), datatype);
ds.read_raw(expected.data(), datatype);

CHECK(expected.size() == value.size());
for (size_t i = 0; i < value.size(); ++i) {
Expand Down
Loading