Skip to content

Commit

Permalink
Read commited datatype (#796)
Browse files Browse the repository at this point in the history
Adds the ability to open committed data types (including compound datatypes) along with documentation and tests.

---------

Co-authored-by: sbouteille <s.bouteille@iris-instruments.com>
Co-authored-by: Nicolas Cornu <nicolas.cornu@epfl.ch>
  • Loading branch information
3 people authored Jul 11, 2023
1 parent 2c8b6b7 commit 60a3b06
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/highfive/H5DataType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class DataType: public Object {
friend class File;
friend class DataSet;
friend class CompoundType;
template <typename Derivate>
friend class NodeTraits;
};


Expand Down
8 changes: 8 additions & 0 deletions include/highfive/bits/H5Node_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ class NodeTraits {
/// \return the group object
Group getGroup(const std::string& group_name) const;

///
/// \brief open a commited datatype with the name type_name
/// \param type_name
/// \return the datatype object
DataType getDataType(
const std::string& type_name,
const DataTypeAccessProps& accessProps = DataTypeAccessProps::Default()) const;

///
/// \brief return the number of leaf objects of the node / group
/// \return number of leaf objects
Expand Down
13 changes: 13 additions & 0 deletions include/highfive/bits/H5Node_traits_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ inline Group NodeTraits<Derivate>::getGroup(const std::string& group_name) const
return detail::make_group(hid);
}

template <typename Derivate>
inline DataType NodeTraits<Derivate>::getDataType(const std::string& type_name,
const DataTypeAccessProps& accessProps) const {
const auto hid = H5Topen2(static_cast<const Derivate*>(this)->getId(),
type_name.c_str(),
accessProps.getId());
if (hid < 0) {
HDF5ErrMapper::ToException<DataTypeException>(
std::string("Unable to open the datatype \"") + type_name + "\":");
}
return DataType(hid);
}

template <typename Derivate>
inline size_t NodeTraits<Derivate>::getNumberObjects() const {
hsize_t res;
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/tests_high_five_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2899,6 +2899,27 @@ TEST_CASE("HighFiveEnum") {
}
}

TEST_CASE("HighFiveReadType") {
const std::string file_name("readtype_test.h5");
const std::string datatype_name1("my_type");
const std::string datatype_name2("position");

File file(file_name, File::ReadWrite | File::Create | File::Truncate);

CompoundType t1 = create_compound_csl1();
t1.commit(file, datatype_name1);

CompoundType t2 = file.getDataType(datatype_name1);

auto t3 = create_enum_position();
t3.commit(file, datatype_name2);

DataType t4 = file.getDataType(datatype_name2);

CHECK(t2 == t1);
CHECK(t4 == t3);
}

TEST_CASE("HighFiveFixedString") {
const std::string file_name("array_atomic_types.h5");
const std::string group_1("group1");
Expand Down

0 comments on commit 60a3b06

Please sign in to comment.