summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2018-07-17 14:12:10 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2018-07-17 14:12:10 (GMT)
commit3aa24435180d10aeca6493f7c1b277cfd5c73fad (patch)
tree4b2a16506fd6b76f3c86d30c82f2d83a26b60869
parent944735221e3dc6545aca753b09041cef7ea09fb1 (diff)
downloadhdf5-3aa24435180d10aeca6493f7c1b277cfd5c73fad.zip
hdf5-3aa24435180d10aeca6493f7c1b277cfd5c73fad.tar.gz
hdf5-3aa24435180d10aeca6493f7c1b277cfd5c73fad.tar.bz2
Fixed HDFFV-10458 partially
Description: Added wrappers for H5Oget_info_by_idx2. // Returns information about an HDF5 object, given its index. void getInfo(const char* grp_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo, unsigned fields = H5O_INFO_BASIC, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) void getInfo(const H5std_string& grp_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo, unsigned fields = H5O_INFO_BASIC, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) Platforms tested: Linux/64 (jelly) Linux/32 (jam) Darwin (osx1010test)
-rw-r--r--c++/src/H5Object.cpp77
-rw-r--r--c++/src/H5Object.h18
-rw-r--r--c++/test/dsets.cpp62
-rw-r--r--c++/test/trefer.cpp15
4 files changed, 163 insertions, 9 deletions
diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp
index 58b34ae..a33acb3 100644
--- a/c++/src/H5Object.cpp
+++ b/c++/src/H5Object.cpp
@@ -228,10 +228,17 @@ int H5Object::iterateAttrs(attr_operator_t user_op, unsigned *_idx, void *op_dat
//--------------------------------------------------------------------------
// Function: H5Object::getInfo
-///\brief Returns information about an HDF5 object.
+///\brief Retrieves information about an HDF5 object.
///\param objinfo - OUT: Struct containing the object info
///\param fields - IN: Indicates the group of information to be retrieved
-/// - default to H5O_INFO_BASIC
+///\par Description
+/// Valid values of \a fields are as follows:
+/// \li \c H5O_INFO_BASIC (default)
+/// \li \c H5O_INFO_TIME
+/// \li \c H5O_INFO_NUM_ATTRS
+/// \li \c H5O_INFO_HDR
+/// \li \c H5O_INFO_META_SIZE
+/// \li \c H5O_INFO_ALL
// July, 2018
//--------------------------------------------------------------------------
void H5Object::getInfo(H5O_info_t& objinfo, unsigned fields) const
@@ -242,17 +249,25 @@ void H5Object::getInfo(H5O_info_t& objinfo, unsigned fields) const
// Throw exception if C API returns failure
if (ret_value < 0)
- throwException(inMemFunc("getObjinfo"), "H5Oget_info2 failed");
+ throwException(inMemFunc("getInfo"), "H5Oget_info2 failed");
}
//--------------------------------------------------------------------------
// Function: H5Object::getInfo
-///\brief Returns information about an HDF5 object given its name.
+///\brief Retrieves information about an HDF5 object given its name.
///\param name - IN: Name of the object to be queried - \c char *
///\param objinfo - OUT: Struct containing the object info
///\param fields - IN: Indicates the group of information to be retrieved
/// - default to H5O_INFO_BASIC
///\param lapl - IN: Link access property list
+///\par Description
+/// Valid values of \a fields are as follows:
+/// \li \c H5O_INFO_BASIC (default)
+/// \li \c H5O_INFO_TIME
+/// \li \c H5O_INFO_NUM_ATTRS
+/// \li \c H5O_INFO_HDR
+/// \li \c H5O_INFO_META_SIZE
+/// \li \c H5O_INFO_ALL
// July, 2018
//--------------------------------------------------------------------------
void H5Object::getInfo(const char* name, H5O_info_t& objinfo, unsigned fields, const LinkAccPropList& lapl) const
@@ -262,7 +277,7 @@ void H5Object::getInfo(const char* name, H5O_info_t& objinfo, unsigned fields, c
// Throw exception if C API returns failure
if (ret_value < 0)
- throwException(inMemFunc("getObjinfo"), "H5Oget_info_by_name2 failed");
+ throwException(inMemFunc("getInfo"), "H5Oget_info_by_name2 failed");
}
//--------------------------------------------------------------------------
@@ -279,12 +294,60 @@ void H5Object::getInfo(const char* name, H5O_info_t& objinfo, unsigned fields, c
//--------------------------------------------------------------------------
void H5Object::getInfo(const H5std_string& name, H5O_info_t& objinfo, unsigned fields, const LinkAccPropList& lapl) const
{
+ getInfo(name.c_str(), objinfo, fields, lapl);
+}
+
+//--------------------------------------------------------------------------
+// Function: H5Object::getInfo
+///\brief Retrieves information about an HDF5 object given its index.
+///\param grp_name - IN: Group name where the object belongs - \c char *
+///\param idx_type - IN: Type of index
+///\param order - IN: Order to traverse
+///\param idx - IN: Object position
+///\param objinfo - OUT: Struct containing the object info
+///\param fields - IN: Indicates the group of information to be retrieved
+/// - default to H5O_INFO_BASIC
+///\param lapl - IN: Link access property list
+///\par Description
+/// Valid values of \a fields are as follows:
+/// \li \c H5O_INFO_BASIC (default)
+/// \li \c H5O_INFO_TIME
+/// \li \c H5O_INFO_NUM_ATTRS
+/// \li \c H5O_INFO_HDR
+/// \li \c H5O_INFO_META_SIZE
+/// \li \c H5O_INFO_ALL
+// July, 2018
+//--------------------------------------------------------------------------
+void H5Object::getInfo(const char* grp_name, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo, unsigned fields,
+ const LinkAccPropList& lapl) const
+{
// Use C API to get information of the object
- herr_t ret_value = H5Oget_info_by_name2(getId(), name.c_str(), &objinfo, fields, lapl.getId());
+ herr_t ret_value = H5Oget_info_by_idx2(getId(), grp_name, idx_type, order,
+ idx, &objinfo, fields, lapl.getId());
// Throw exception if C API returns failure
if (ret_value < 0)
- throwException(inMemFunc("getObjinfo"), "H5Oget_info_by_name2 failed");
+ throwException(inMemFunc("getInfo"), "H5Oget_info_by_idx2 failed");
+}
+
+//--------------------------------------------------------------------------
+// Function: H5Object::getInfo
+///\brief This is an overloaded member function, provided for convenience.
+/// It differs from the above function in that it takes
+/// a reference to an \c H5std_string for \a name.
+///\param name - IN: Name of the object to be queried - \c H5std_string
+///\param objinfo - OUT: Struct containing the object info
+///\param fields - IN: Indicates a group of information to be retrieved
+/// - default to H5O_INFO_BASIC
+///\param lapl - IN: Link access property list
+// July, 2018
+//--------------------------------------------------------------------------
+void H5Object::getInfo(const H5std_string& grp_name, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo, unsigned fields,
+ const LinkAccPropList& lapl) const
+{
+ getInfo(grp_name.c_str(), idx_type, order, idx, objinfo, fields, lapl);
}
//--------------------------------------------------------------------------
diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h
index f15c8eb..268fe58 100644
--- a/c++/src/H5Object.h
+++ b/c++/src/H5Object.h
@@ -95,8 +95,22 @@ class H5_DLLCPP H5Object : public H5Location {
// Returns information about an HDF5 object.
void getInfo(H5O_info_t& objinfo, unsigned fields = H5O_INFO_BASIC) const;
// Returns information about an HDF5 object, given its name.
- void getInfo(const char* name, H5O_info_t& objinfo, unsigned fields = H5O_INFO_BASIC, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const;
- void getInfo(const H5std_string& name, H5O_info_t& objinfo, unsigned fields = H5O_INFO_BASIC, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const;
+ void getInfo(const char* name, H5O_info_t& objinfo,
+ unsigned fields = H5O_INFO_BASIC,
+ const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const;
+ void getInfo(const H5std_string& name, H5O_info_t& objinfo,
+ unsigned fields = H5O_INFO_BASIC,
+ const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const;
+
+ // Retrieves information about an HDF5 object, given its index.
+ void getInfo(const char* grp_name, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo,
+ unsigned fields = H5O_INFO_BASIC,
+ const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const;
+ void getInfo(const H5std_string& grp_name, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t idx, H5O_info_t& objinfo,
+ unsigned fields = H5O_INFO_BASIC,
+ const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const;
// Gets the name of this HDF5 object, i.e., Group, DataSet, or
// DataType.
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp
index 250ce90..e86052b 100644
--- a/c++/test/dsets.cpp
+++ b/c++/test/dsets.cpp
@@ -1116,6 +1116,67 @@ static herr_t test_types(H5File& file)
/*-------------------------------------------------------------------------
+ * Function: test_getinfo
+ *
+ * Purpose Tests getInfo()
+ *
+ * Return Success: 0
+ *
+ * Failure: -1
+ *
+ * July, 2018
+ *-------------------------------------------------------------------------
+ */
+static herr_t test_getinfo(H5File& file)
+{
+ SUBTEST("Getting object information");
+
+ try {
+ // Create a data space
+ hsize_t dims[2];
+ dims[0] = 256;
+ dims[1] = 512;
+ DataSpace space (2, dims, NULL);
+
+ // Create a dataset using the default dataset creation properties.
+ // We're not sure what they are, so we won't check.
+ DataSet dataset(file.openDataSet(DSET_CHUNKED_NAME));
+
+ // Get dataset header info
+ H5O_info_t oinfo;
+ HDmemset(&oinfo, 0, sizeof(oinfo));
+ dataset.getInfo(oinfo, H5O_INFO_HDR);
+ verify_val(oinfo.hdr.nchunks, 1, "DataSet::getInfo", __LINE__, __FILE__);
+ dataset.close();
+
+ // Open the dataset we created above and then close it. This is one
+ // way to open an existing dataset for accessing.
+ dataset = file.openDataSet(DSET_DEFAULT_NAME);
+ HDmemset(&oinfo, 0, sizeof(oinfo));
+ dataset.getInfo(oinfo, H5O_INFO_ALL);
+ verify_val(oinfo.hdr.nchunks, 1, "DataSet::getInfo", __LINE__, __FILE__);
+ dataset.close();
+
+ PASSED();
+ return 0;
+ } // outer most try block
+
+ catch (InvalidActionException& E)
+ {
+ cerr << " FAILED" << endl;
+ cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl;
+ return -1;
+ }
+ // catch all other exceptions
+ catch (Exception& E)
+ {
+ issue_fail_msg("test_getinfo", __LINE__, __FILE__);
+ return -1;
+ }
+} // test_getinfo
+
+
+/*-------------------------------------------------------------------------
* Function: test_virtual
*
* Purpose Tests fixed, unlimited, and printf selections in the same
@@ -1237,6 +1298,7 @@ void test_dset()
nerrors += test_create(file) < 0 ? 1:0;
nerrors += test_simple_io(file) < 0 ? 1:0;
+ nerrors += test_getinfo(file) < 0 ? 1:0;
nerrors += test_tconv(file) < 0 ? 1:0;
nerrors += test_compression(file) < 0 ? 1:0;
nerrors += test_nbit_compression(file) < 0 ? 1:0;
diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp
index bb09616..fa214df 100644
--- a/c++/test/trefer.cpp
+++ b/c++/test/trefer.cpp
@@ -481,6 +481,21 @@ static void test_reference_group()
fname = group.getFileName();
verify_val(fname, FILE1, "H5Group::getFileName",__LINE__,__FILE__);
+ // Check object type using Group::getInfo()
+ H5O_info_t oinfo;
+ HDmemset(&oinfo, 0, sizeof(oinfo));
+ group.getInfo(".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)0, oinfo);
+ verify_val(oinfo.type, H5O_TYPE_DATASET, "Group::getInfo",__LINE__,__FILE__);
+
+ // Check for out of bound query by index
+ try {
+ HDmemset(&oinfo, 0, sizeof(oinfo));
+ group.getInfo(".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)9, oinfo);
+
+ // Should FAIL but didn't, so throw an invalid action exception
+ throw InvalidActionException("Group::getInfo", "Out of bound index.");
+ } catch (Exception& err) {} // do nothing, failure expected
+
// Unlink one of the objects in the dereferenced group, and re-check
refgroup.unlink(GROUPNAME2);
nobjs = refgroup.getNumObjs();