Skip to content

Commit 73c07de

Browse files
radistmorse1uc
andauthored
add: extend support for AttributePhaseChange. (#67)
The attribute phase change property can be applied to group, dataset and file create property lists. This commit adds support for dataset and file property lists. --------- Co-authored-by: Luc Grosheintz <luc.grosheintz@gmail.com>
1 parent a4e2f35 commit 73c07de

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

include/highfive/H5PropertyList.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,16 +689,27 @@ class AttributePhaseChange {
689689
/// attributes are moved to compact storage.
690690
AttributePhaseChange(unsigned max_compact, unsigned min_dense);
691691

692+
/// \brief Extract threshold values from property list.
693+
explicit AttributePhaseChange(const FileCreateProps& gcpl);
694+
692695
/// \brief Extract threshold values from property list.
693696
explicit AttributePhaseChange(const GroupCreateProps& gcpl);
694697

698+
/// \brief Extract threshold values from property list.
699+
explicit AttributePhaseChange(const DataSetCreateProps& gcpl);
700+
695701
unsigned max_compact() const;
696702
unsigned min_dense() const;
697703

698704
private:
705+
friend DataSetCreateProps;
706+
friend FileCreateProps;
699707
friend GroupCreateProps;
700708
void apply(hid_t hid) const;
701709

710+
template <class PList>
711+
void init(const PList& plist);
712+
702713
unsigned _max_compact;
703714
unsigned _min_dense;
704715
};

include/highfive/bits/H5PropertyList_misc.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,21 @@ inline AttributePhaseChange::AttributePhaseChange(unsigned max_compact, unsigned
472472
: _max_compact(max_compact)
473473
, _min_dense(min_dense) {}
474474

475+
template <class PList>
476+
void AttributePhaseChange::init(const PList& plist) {
477+
detail::h5p_get_attr_phase_change(plist.getId(), &_max_compact, &_min_dense);
478+
}
479+
480+
inline AttributePhaseChange::AttributePhaseChange(const FileCreateProps& fcpl) {
481+
init(fcpl);
482+
}
483+
475484
inline AttributePhaseChange::AttributePhaseChange(const GroupCreateProps& gcpl) {
476-
detail::h5p_get_attr_phase_change(gcpl.getId(), &_max_compact, &_min_dense);
485+
init(gcpl);
486+
}
487+
488+
inline AttributePhaseChange::AttributePhaseChange(const DataSetCreateProps& dcpl) {
489+
init(dcpl);
477490
}
478491

479492
inline unsigned AttributePhaseChange::max_compact() const {

tests/unit/tests_high_five_base.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,19 +1225,41 @@ TEST_CASE("WriteLargeAttribute") {
12251225
CHECK_NOTHROW(group.createAttribute("attr", large_attr));
12261226
}
12271227

1228+
template <class CPL, class CreateObject>
1229+
void check_attribute_phase_change(CreateObject create_object) {
1230+
auto cpl = CPL::Default();
1231+
cpl.add(HighFive::AttributePhaseChange(42, 24));
1232+
1233+
auto obj = create_object(cpl);
1234+
auto actual = AttributePhaseChange(obj.getCreatePropertyList());
1235+
CHECK(actual.min_dense() == 24);
1236+
CHECK(actual.max_compact() == 42);
1237+
}
1238+
12281239
TEST_CASE("AttributePhaseChange") {
1229-
auto fapl = HighFive::FileAccessProps::Default();
1230-
fapl.add(HighFive::FileVersionBounds(H5F_LIBVER_LATEST, H5F_LIBVER_LATEST));
1231-
HighFive::File file("attribute_phase_change.h5", HighFive::File::Truncate, fapl);
1240+
auto create_file = [](HighFive::FileCreateProps fcpl = HighFive::FileCreateProps::Default()) {
1241+
auto fapl = HighFive::FileAccessProps::Default();
1242+
fapl.add(HighFive::FileVersionBounds(H5F_LIBVER_LATEST, H5F_LIBVER_LATEST));
1243+
return HighFive::File("attribute_phase_change.h5", HighFive::File::Truncate, fcpl, fapl);
1244+
};
12321245

1233-
auto gcpl = HighFive::GroupCreateProps::Default();
1234-
gcpl.add(HighFive::AttributePhaseChange(42, 24));
1246+
SECTION("File") {
1247+
check_attribute_phase_change<HighFive::FileCreateProps>(create_file);
1248+
}
12351249

1236-
auto group = file.createGroup("grp", gcpl);
1250+
SECTION("Group") {
1251+
auto file = create_file();
1252+
check_attribute_phase_change<HighFive::GroupCreateProps>(
1253+
[&file](auto gcpl) { return file.createGroup("grp", gcpl); });
1254+
}
12371255

1238-
auto actual = AttributePhaseChange(group.getCreatePropertyList());
1239-
CHECK(actual.min_dense() == 24);
1240-
CHECK(actual.max_compact() == 42);
1256+
SECTION("Dataset") {
1257+
auto file = create_file();
1258+
check_attribute_phase_change<HighFive::DataSetCreateProps>([&file](auto dcpl) {
1259+
auto space = HighFive::DataSpace::Scalar();
1260+
return file.createDataSet<double>("dset", space, dcpl);
1261+
});
1262+
}
12411263
}
12421264

12431265
TEST_CASE("datasetOffset") {

0 commit comments

Comments
 (0)