Skip to content

Commit f5f28c7

Browse files
committed
Add overloads for write_hdf5_format and assert_hdf5_format without deducing storage type
1 parent 5623fcf commit f5f28c7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

c++/h5/format.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ namespace h5 {
102102
*/
103103
inline void write_hdf5_format_as_string(object obj, std::string const &s) { h5_write_attribute(obj, "Format", s); }
104104

105+
/**
106+
* @brief Write an `hdf5_format` tag for type `T` to an HDF5 attribute with the name 'Format' using template
107+
* argument deduction.
108+
*
109+
* @tparam T Type for which the `hdf5_format` tag is to be written.
110+
* @param obj h5::object to which the attribute is attached.
111+
*/
112+
template <typename T>
113+
inline void write_hdf5_format(object obj) {
114+
h5_write_attribute(obj, "Format", get_hdf5_format<T>());
115+
}
116+
105117
/**
106118
* @brief Write an `hdf5_format` tag for type `T` to an HDF5 attribute with the name 'Format' using template
107119
* argument deduction.
@@ -150,6 +162,21 @@ namespace h5 {
150162
*/
151163
void assert_hdf5_format_as_string(group g, const char *tag_expected, bool ignore_if_absent = false);
152164

165+
/**
166+
* @brief Assert that the `hdf5_format` tag attached to the given group is the same as the `hdf5_format` tag of the type `T`
167+
* using template argument deduction.
168+
*
169+
* @details Throws a std::runtime_error if the tags don't match.
170+
*
171+
* @tparam T Type for which the `hdf5_format` tag is to be checked.
172+
* @param g h5::group to be checked.
173+
* @param ignore_if_absent If true, the assertion is ignored if the group does not have a 'Format' attribute.
174+
*/
175+
template <typename T>
176+
void assert_hdf5_format(group g, bool ignore_if_absent = false) {
177+
assert_hdf5_format_as_string(g, get_hdf5_format<T>().c_str(), ignore_if_absent);
178+
}
179+
153180
/**
154181
* @brief Assert that the `hdf5_format` tag attached to the given group is the same as the `hdf5_format` tag of the type `T`
155182
* using template argument deduction.

0 commit comments

Comments
 (0)