summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
Diffstat (limited to 'c++')
-rw-r--r--c++/src/H5LcreatProp.cpp39
-rw-r--r--c++/src/H5LcreatProp.h8
-rw-r--r--c++/src/H5Location.cpp7
-rw-r--r--c++/test/tobject.cpp124
4 files changed, 168 insertions, 10 deletions
diff --git a/c++/src/H5LcreatProp.cpp b/c++/src/H5LcreatProp.cpp
index 695c1fe..5c61e68 100644
--- a/c++/src/H5LcreatProp.cpp
+++ b/c++/src/H5LcreatProp.cpp
@@ -103,6 +103,45 @@ LinkCreatPropList::LinkCreatPropList(const LinkCreatPropList& original) : PropLi
LinkCreatPropList::LinkCreatPropList(const hid_t plist_id) : PropList(plist_id) {}
//--------------------------------------------------------------------------
+// Function: LinkCreatPropList::setCreateIntermediateGroup
+///\brief Specifies in property list whether to create missing
+/// intermediate groups.
+///
+///\exception H5::PropListIException
+// April, 2019
+//--------------------------------------------------------------------------
+void LinkCreatPropList::setCreateIntermediateGroup(bool crt_intmd_group) const
+{
+ herr_t ret_value = H5Pset_create_intermediate_group(id, (unsigned)crt_intmd_group);
+ // Throw exception if H5Pset_create_intermediate_group returns failure
+ if (ret_value < 0)
+ {
+ throw PropListIException("setCreateIntermediateGroup", "H5Pset_create_intermediate_group failed");
+ }
+}
+
+//--------------------------------------------------------------------------
+// Function: LinkCreatPropList::getCreateIntermediateGroup
+///\brief Determines whether property is set to enable creating missing
+/// intermediate groups.
+///
+///\exception H5::PropListIException
+// April, 2019
+//--------------------------------------------------------------------------
+bool LinkCreatPropList::getCreateIntermediateGroup() const
+{
+ unsigned crt_intmd_group;
+ herr_t ret_value = H5Pget_create_intermediate_group(id, &crt_intmd_group);
+ // Throw exception if H5Pget_create_intermediate_group returns failure
+ if (ret_value < 0)
+ {
+ throw PropListIException("getCreateIntermediateGroup", "H5Pget_create_intermediate_group failed");
+ }
+
+ return((bool)crt_intmd_group);
+}
+
+//--------------------------------------------------------------------------
// Function: LinkCreatPropList::setCharEncoding
///\brief Sets the character encoding of the string.
///
diff --git a/c++/src/H5LcreatProp.h b/c++/src/H5LcreatProp.h
index f6e10bf..908ef63 100644
--- a/c++/src/H5LcreatProp.h
+++ b/c++/src/H5LcreatProp.h
@@ -40,6 +40,14 @@ class H5_DLLCPP LinkCreatPropList : public PropList {
// using the property list id.
LinkCreatPropList (const hid_t plist_id);
+ // Specifies in property list whether to create missing
+ // intermediate groups
+ void setCreateIntermediateGroup(bool crt_intmd_group) const;
+
+ // Determines whether property is set to enable creating missing
+ // intermediate groups
+ bool getCreateIntermediateGroup() const;
+
// Sets the character encoding of the string.
void setCharEncoding(H5T_cset_t encoding) const;
diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp
index 2c49016..2641960 100644
--- a/c++/src/H5Location.cpp
+++ b/c++/src/H5Location.cpp
@@ -1066,7 +1066,7 @@ void H5Location::link(const char *curr_name, const Group& new_loc,
hid_t lcpl_id = lcpl.getId();
hid_t lapl_id = lapl.getId();
- ret_value = H5Lcreate_hard(getId(), curr_name, new_loc.getId(), new_name, H5P_DEFAULT, H5P_DEFAULT);
+ ret_value = H5Lcreate_hard(getId(), curr_name, new_loc_id, new_name, lcpl_id, lapl_id);
if (ret_value < 0)
throwException("link", "creating link failed");
}
@@ -1102,14 +1102,13 @@ void H5Location::link(const H5std_string& curr_name, const Group& new_loc,
/// H5Lcreate_hard APIs in the HDF5 C Reference Manual.
// March 2018
//--------------------------------------------------------------------------
-void H5Location::link(const char *curr_name, const hid_t same_loc,
- const char *new_name, const LinkCreatPropList& lcpl, const LinkAccPropList& lapl) const
+void H5Location::link(const char *curr_name, const hid_t same_loc, const char *new_name, const LinkCreatPropList& lcpl, const LinkAccPropList& lapl) const
{
herr_t ret_value = -1;
hid_t lcpl_id = lcpl.getId();
hid_t lapl_id = lapl.getId();
- ret_value = H5Lcreate_hard(getId(), curr_name, same_loc, new_name, H5P_DEFAULT, H5P_DEFAULT);
+ ret_value = H5Lcreate_hard(getId(), curr_name, same_loc, new_name, lcpl_id, lapl_id);
if (ret_value < 0)
throwException("link", "creating link failed");
diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp
index 23c1453..232ece2 100644
--- a/c++/test/tobject.cpp
+++ b/c++/test/tobject.cpp
@@ -615,6 +615,117 @@ static void test_getobjectinfo_same_file()
} // test_getobjectinfo_same_file
/*-------------------------------------------------------------------------
+ * Function: test_intermediate_groups
+ *
+ * Purpose Test that intermediate groups are created as specified by
+ * the property setting.
+ *
+ * Return None
+ *
+ * April, 2019
+ *-------------------------------------------------------------------------
+ */
+const H5std_string FILE_INTERGRPS("tobject_intergrps.h5");
+const H5std_string GROUP10NAME("/group10");
+const H5std_string GROUP11NAME("/group10/group11");
+const H5std_string GROUP12NAME("/group10/group11/group12");
+const H5std_string GROUP13NAME("/group10/group11/group12/group13");
+const H5std_string GROUP14NAME("/group10/group11/group12/group13/group14");
+const H5std_string GROUP14FROM13NAME("group14");
+const H5std_string GROUP20NAME("/group20");
+const H5std_string GROUP21NAME("/group20/group21");
+const H5std_string GROUP22NAME("group21/group22");
+const H5std_string GROUP22FULLNAME("/group20/group21/group22");
+static void test_intermediate_groups()
+{
+ // Output message about test being performed
+ SUBTEST("Group::set/getCreateIntermediateGroup");
+
+ try {
+ // Create a new HDF5 file
+ H5File file(FILE_INTERGRPS, H5F_ACC_TRUNC);
+
+ // Create a link create property list and set the "create
+ // intermediate groups" flag
+ LinkCreatPropList lcpl;
+ lcpl.setCreateIntermediateGroup(true);
+
+ // Verify value of create missing groups flag
+ bool crt_int_grps = lcpl.getCreateIntermediateGroup();
+ verify_val(crt_int_grps, true, "LinkCreatPropList::getCreateIntermediateGroup", __LINE__, __FILE__);
+
+ // Create GROUP12NAME with creating missing groups
+ Group grp12(file.createGroup(GROUP12NAME, lcpl));
+
+ // Missing groups: GROUP10NAME and GROUP11NAME
+
+ // Create GROUP14NAME without the use of link create plist, should
+ // fail because group GROUP13NAME is missing
+ try {
+ Group grp14_nopl(file.createGroup(GROUP14NAME));
+ } catch (FileIException& expected1) {} // Failure is ignored
+
+ // Create GROUP14NAME with the flag to create missing groups set
+ // to FALSE, should fail because group GROUP13NAME is missing
+
+ // Reset flag to not create missing groups
+ lcpl.setCreateIntermediateGroup(false);
+
+ // Verify value of create missing groups flag
+ crt_int_grps = lcpl.getCreateIntermediateGroup();
+ verify_val(crt_int_grps, false, "LinkCreatPropList::getCreateIntermediateGroup", __LINE__, __FILE__);
+
+ try {
+ Group grp14_false(file.createGroup(GROUP14NAME, lcpl));
+ } catch (FileIException& expected2) {} // Failure is ignored
+
+ // Set the flag to create missing groups set to TRUE
+ lcpl.setCreateIntermediateGroup(true);
+ crt_int_grps = lcpl.getCreateIntermediateGroup();
+ verify_val(crt_int_grps, true, "LinkCreatPropList::getCreateIntermediateGroup", __LINE__, __FILE__);
+
+
+ // Create GROUP14NAME with the use of link create plist
+ Group grp14(file.createGroup(GROUP14NAME, lcpl));
+
+ // Missing groups: GROUP13NAME
+
+ // Create group GROUP20NAME
+ Group grp20(file.createGroup(GROUP20NAME));
+
+ // Create group GROUP22NAME with missing group GROUP21NAME
+ Group grp22(grp20.createGroup(GROUP22NAME, lcpl));
+
+ // Close groups and file
+ grp12.close();
+ grp14.close();
+ grp20.close();
+ grp22.close();
+ file.close();
+
+ // Reopen the file
+ file.openFile(FILE_INTERGRPS, H5F_ACC_RDWR);
+
+ // Open the missing groups and various combinations
+ Group grp10(file.openGroup(GROUP10NAME));
+ Group grp11(file.openGroup(GROUP11NAME));
+ Group grp13(file.openGroup(GROUP13NAME));
+ Group grp14from13(grp13.openGroup(GROUP14FROM13NAME));
+ Group grp21(file.openGroup(GROUP21NAME));
+ Group grp22fromfile(file.openGroup(GROUP22FULLNAME));
+
+ PASSED();
+ } // end of try block
+ // catch all other exceptions
+ catch (Exception& E)
+ {
+ cerr << " in Exception " << E.getCFuncName() << "detail: " << E.getCDetailMsg() << endl;
+ issue_fail_msg("test_intermediate_groups()", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+
+} // test_intermediate_groups
+
+/*-------------------------------------------------------------------------
* Function: test_object
*
* Purpose Tests HDF5 object related functionality
@@ -631,12 +742,13 @@ void test_object()
// Output message about test being performed
MESSAGE(5, ("Testing Object Functions\n"));
- test_get_objname(); // Test get object name from groups/datasets
- test_existance(); // Test check for object existance
- test_get_objname_ontypes(); // Test get object name from types
- test_get_objtype(); // Test get object type
- test_open_object_header(); // Test object header functions (H5O)
- test_getobjectinfo_same_file(); // Test object info in same file
+ test_get_objname(); // Test get object name from groups/datasets
+ test_existance(); // Test check for object existance
+ test_get_objname_ontypes(); // Test get object name from types
+ test_get_objtype(); // Test get object type
+ test_open_object_header(); // Test object header functions (H5O)
+ test_getobjectinfo_same_file(); // Test object info in same file
+ test_intermediate_groups(); // Test intermediate group property
} // test_object