Skip to content

Commit

Permalink
Distinguish between buffer pointer and iterator.
Browse files Browse the repository at this point in the history
There's a notion of pointer to the first byte of the buffer. This
is what one passes to HDF5, e.g. in `H5Dread`. There's also the concept
of a iterator which is used for serialization.

Currently, both ideas are represented by an `hdf5_type*`. However, the
StringBuffer will need to return proxy objects. This commits splits the
notion. Conveniently, we can rename `get_pointer` to the more in-style
`getPointer` and hence the compiler checks that we've considered all
occurrences of `get_pointer`.
  • Loading branch information
1uc committed May 5, 2023
1 parent 39bdd5f commit 6d3ddea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
8 changes: 4 additions & 4 deletions include/highfive/bits/H5Attribute_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ inline void Attribute::read(T& array) const {
}

auto r = details::data_converter::get_reader<T>(dims, array, file_datatype);
read(r.get_pointer(), buffer_info.data_type);
read(r.getPointer(), buffer_info.data_type);
// re-arrange results
r.unserialize(array);
auto t = create_datatype<typename details::inspector<T>::base_type>();
auto c = t.getClass();
if (c == DataTypeClass::VarLen || t.isVariableStr()) {
#if H5_VERSION_GE(1, 12, 0)
// This one have been created in 1.12.0
(void) H5Treclaim(t.getId(), mem_space.getId(), H5P_DEFAULT, r.get_pointer());
(void) H5Treclaim(t.getId(), mem_space.getId(), H5P_DEFAULT, r.getPointer());
#else
// This one is deprecated since 1.12.0
(void) H5Dvlen_reclaim(t.getId(), mem_space.getId(), H5P_DEFAULT, r.get_pointer());
(void) H5Dvlen_reclaim(t.getId(), mem_space.getId(), H5P_DEFAULT, r.getPointer());
#endif
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ inline void Attribute::write(const T& buffer) {
throw DataSpaceException(ss.str());
}
auto w = details::data_converter::serialize<T>(buffer, file_datatype);
write_raw(w.get_pointer(), buffer_info.data_type);
write_raw(w.getPointer(), buffer_info.data_type);
}

template <typename T>
Expand Down
21 changes: 16 additions & 5 deletions include/highfive/bits/H5Converter_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ struct enable_shallow_copy: public std::enable_if<inspector<T>::is_trivially_cop
template <class T, class V = void>
struct enable_deep_copy: public std::enable_if<!inspector<T>::is_trivially_copyable, V> {};


template <typename T, bool IsReadOnly>
struct ShallowCopyBuffer {
using type = unqualified_t<T>;
Expand All @@ -36,10 +35,14 @@ struct ShallowCopyBuffer {
explicit ShallowCopyBuffer(typename std::conditional<IsReadOnly, const T&, T&>::type val)
: ptr(inspector<T>::data(val)){};

hdf5_type* get_pointer() const {
hdf5_type* getPointer() const {
return ptr;
}

hdf5_type* begin() const {
return getPointer();
}

void unserialize(T& val) const {
/* nothing to do. */
}
Expand All @@ -57,14 +60,22 @@ struct DeepCopyBuffer {
: buffer(inspector<T>::getSize(_dims))
, dims(_dims) {}

hdf5_type* get_pointer() {
hdf5_type* getPointer() {
return buffer.data();
}

hdf5_type const* get_pointer() const {
hdf5_type const* getPointer() const {
return buffer.data();
}

hdf5_type* begin() {
return getPointer();
}

hdf5_type const* begin() const {
return getPointer();
}

void unserialize(T& val) const {
inspector<type>::unserialize(buffer.data(), dims, val);
}
Expand Down Expand Up @@ -92,7 +103,7 @@ template <typename T>
struct Writer<T, typename enable_deep_copy<T>::type>: public DeepCopyBuffer<T> {
explicit Writer(const T& val, const DataType& file_datatype)
: DeepCopyBuffer<T>(inspector<T>::getDimensions(val)) {
inspector<T>::serialize(val, this->get_pointer());
inspector<T>::serialize(val, this->begin());
}
};

Expand Down
8 changes: 4 additions & 4 deletions include/highfive/bits/H5Slice_traits_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,18 @@ inline void SliceTraits<Derivate>::read(T& array, const DataTransferProps& xfer_
}

auto r = details::data_converter::get_reader<T>(dims, array, file_datatype);
read(r.get_pointer(), buffer_info.data_type, xfer_props);
read(r.getPointer(), buffer_info.data_type, xfer_props);
// re-arrange results
r.unserialize(array);
auto t = create_datatype<typename details::inspector<T>::base_type>();
auto c = t.getClass();
if (c == DataTypeClass::VarLen || t.isVariableStr()) {
#if H5_VERSION_GE(1, 12, 0)
// This one have been created in 1.12.0
(void) H5Treclaim(t.getId(), mem_space.getId(), xfer_props.getId(), r.get_pointer());
(void) H5Treclaim(t.getId(), mem_space.getId(), xfer_props.getId(), r.getPointer());
#else
// This one is deprecated since 1.12.0
(void) H5Dvlen_reclaim(t.getId(), mem_space.getId(), xfer_props.getId(), r.get_pointer());
(void) H5Dvlen_reclaim(t.getId(), mem_space.getId(), xfer_props.getId(), r.getPointer());
#endif
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ inline void SliceTraits<Derivate>::write(const T& buffer, const DataTransferProp
throw DataSpaceException(ss.str());
}
auto w = details::data_converter::serialize<T>(buffer, file_datatype);
write_raw(w.get_pointer(), buffer_info.data_type, xfer_props);
write_raw(w.getPointer(), buffer_info.data_type, xfer_props);
}


Expand Down

0 comments on commit 6d3ddea

Please sign in to comment.