summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2010-05-02 19:15:43 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2010-05-02 19:15:43 (GMT)
commit85ca829e712aa303e74806fc1d9af8b900fdbc4f (patch)
treef73d94650d485f7c90d88c61449eb770a7730efc /c++
parent54cd6ecec92e81bdcac3299b844a61f14bc89d69 (diff)
downloadhdf5-85ca829e712aa303e74806fc1d9af8b900fdbc4f.zip
hdf5-85ca829e712aa303e74806fc1d9af8b900fdbc4f.tar.gz
hdf5-85ca829e712aa303e74806fc1d9af8b900fdbc4f.tar.bz2
[svn-r18685] Description:
Added missing overloaded function getObjTypeByIdx to return type name as a char*. Platforms tested: Linux/32 2.6 (jam) FreeBSD/64 6.3 (liberty) SunOS 5.10 (linew)
Diffstat (limited to 'c++')
-rw-r--r--c++/src/H5CommonFG.cpp30
-rw-r--r--c++/src/H5CommonFG.h1
-rw-r--r--c++/test/h5cpputil.cpp37
-rw-r--r--c++/test/h5cpputil.h3
-rw-r--r--c++/test/trefer.cpp20
5 files changed, 90 insertions, 1 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index 2772903..7748963 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -1112,7 +1112,35 @@ H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx) const
// Function: CommonFG::getObjTypeByIdx
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function because it also provides
-/// the returned object type in text.
+/// the returned object type in text (char*)
+///\param idx - IN: Transient index of the object
+///\param type_name - IN: Object type in text
+///\return Object type
+///\exception H5::FileIException or H5::GroupIException
+// Programmer Binh-Minh Ribler - May, 2010
+//--------------------------------------------------------------------------
+H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx, char* type_name) const
+{
+ H5G_obj_t obj_type = H5Gget_objtype_by_idx(getLocId(), idx);
+ switch (obj_type)
+ {
+ case H5G_LINK: strcpy(type_name, "symbolic link"); break;
+ case H5G_GROUP: strcpy(type_name, "group"); break;
+ case H5G_DATASET: strcpy(type_name, "dataset"); break;
+ case H5G_TYPE: strcpy(type_name, "datatype"); break;
+ case H5G_UNKNOWN:
+ default:
+ {
+ throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
+ }
+ }
+ return (obj_type);
+}
+//--------------------------------------------------------------------------
+// Function: CommonFG::getObjTypeByIdx
+///\brief This is an overloaded member function, provided for convenience.
+/// It differs from the above function because it also provides
+/// the returned object type in text (H5std_string&)
///\param idx - IN: Transient index of the object
///\param type_name - IN: Object type in text
///\return Object type
diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h
index 75c9259..4f32d21 100644
--- a/c++/src/H5CommonFG.h
+++ b/c++/src/H5CommonFG.h
@@ -78,6 +78,7 @@ class H5_DLLCPP CommonFG {
// Returns the type of an object in this group, given the
// object's index.
H5G_obj_t getObjTypeByIdx(hsize_t idx) const;
+ H5G_obj_t getObjTypeByIdx(hsize_t idx, char* type_name) const;
H5G_obj_t getObjTypeByIdx(hsize_t idx, H5std_string& type_name) const;
// Returns information about an HDF5 object, given by its name,
diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp
index 5e0f904..4485808 100644
--- a/c++/test/h5cpputil.cpp
+++ b/c++/test/h5cpputil.cpp
@@ -138,6 +138,43 @@ int check_values (hsize_t i, hsize_t j, int apoint, int acheck)
return 0;
} // check_values
+/*-------------------------------------------------------------------------
+ * Function: verify_val (const char*, const char*,...)
+ *
+ * Purpose: Compares two character strings. If they are
+ * different, the function will print out a message and the
+ * different values.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Binh-Minh Ribler
+ * May 2, 2010
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void verify_val(const char* x, const char* value, const char* where, int line, const char* file_name)
+{
+ if (GetTestVerbosity()>=VERBO_HI)
+ {
+ cerr << endl;
+ cerr << " Call to routine: " << where << " at line " << line
+ << " in " << file_name << " had value " << x << endl;
+ }
+ if (strcmp(x, value) != 0)
+ {
+ cerr << endl;
+ cerr << "*** UNEXPECTED VALUE from " << where << " should be "
+ << value << ", but is " << x << " at line " << line
+ << " in " << file_name << endl;
+ IncTestNumErrs();
+ throw TestFailedException(where, "");
+ }
+}
+
//--------------------------------------------------------------------------
// Function: InvalidActionException default constructor
//--------------------------------------------------------------------------
diff --git a/c++/test/h5cpputil.h b/c++/test/h5cpputil.h
index 3313483..02f3d0d 100644
--- a/c++/test/h5cpputil.h
+++ b/c++/test/h5cpputil.h
@@ -57,6 +57,9 @@ class TestFailedException : public Exception {
virtual ~TestFailedException();
};
+// Overloaded/Template functions to verify values and display proper info
+void verify_val(const char* x, const char* value, const char* where, int line, const char* file_name);
+
template <class Type1, class Type2>
void verify_val(Type1 x, Type2 value, const char* where, int line, const char* file_name)
{
diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp
index 41ee808..d17e6e3 100644
--- a/c++/test/trefer.cpp
+++ b/c++/test/trefer.cpp
@@ -249,6 +249,26 @@ static void test_reference_obj(void)
verify_val(name, DSET1_NAME, "Group::getObjnameByIdx(index,(char*)buf,buf_len)", __LINE__, __FILE__);
verify_val(name_size, DSET1_LEN, "Group::getObjnameByIdx(index,(char*)buf,buf_len)", __LINE__, __FILE__);
+ // Test getting the type of objects
+
+ // Test getObjTypeByIdx(hsize_t idx)
+ obj_type = group.getObjTypeByIdx(0);
+ verify_val(obj_type, H5G_DATASET, "Group::getObjTypeByIdx(index)", __LINE__, __FILE__);
+
+ // Test getObjTypeByIdx(hsize_t idx, char* type_name)
+ obj_type = H5G_UNKNOWN;
+ char type_name_C[256];
+ obj_type = group.getObjTypeByIdx(0, type_name_C);
+ verify_val(obj_type, H5G_DATASET, "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__);
+ verify_val((const char*)type_name_C, (const char*)"dataset", "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__);
+
+ // Test getObjTypeByIdx(hsize_t idx, H5std_string& type_name)
+ obj_type = H5G_UNKNOWN;
+ H5std_string type_name;
+ obj_type = group.getObjTypeByIdx(0, type_name);
+ verify_val(obj_type, H5G_DATASET, "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__);
+ verify_val(type_name, "dataset", "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__);
+
// Close group
group.close();