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

Read datatype #796

Merged
merged 3 commits into from
Jul 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
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>(

Check warning on line 184 in include/highfive/bits/H5Node_traits_misc.hpp

View check run for this annotation

Codecov / codecov/patch

include/highfive/bits/H5Node_traits_misc.hpp#L184

Added line #L184 was not covered by tests
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);
alkino marked this conversation as resolved.
Show resolved Hide resolved

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