summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-05-05 17:18:50 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-05-05 17:18:50 (GMT)
commitca7fc8e96a70b06b08e1db21040056ae17a51906 (patch)
tree3d665b7a3119174158fc91a05fd8055f6ca7074b /c++
parentb24e2d4dd861b67a61fcf56be5975bcd4d37203b (diff)
downloadhdf5-ca7fc8e96a70b06b08e1db21040056ae17a51906.zip
hdf5-ca7fc8e96a70b06b08e1db21040056ae17a51906.tar.gz
hdf5-ca7fc8e96a70b06b08e1db21040056ae17a51906.tar.bz2
[svn-r18708] Description:
Bring r18638:18704 from trunk to revise_chunks branch. Tested on: Mac OS X/32 10.6.3 (amazon) w/debug & production (h5committest not required on this branch)
Diffstat (limited to 'c++')
-rw-r--r--c++/src/H5Attribute.cpp7
-rw-r--r--c++/src/H5CommonFG.cpp50
-rw-r--r--c++/src/H5CommonFG.h4
-rw-r--r--c++/src/Makefile.in2
-rw-r--r--c++/test/h5cpputil.cpp37
-rw-r--r--c++/test/h5cpputil.h3
-rw-r--r--c++/test/trefer.cpp62
7 files changed, 150 insertions, 15 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index 5f04865..a2445d6 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -423,18 +423,15 @@ void Attribute::p_read_fixed_len(const DataType& mem_type, H5std_string& strg) c
// If there is data, allocate buffer and read it.
if (attr_size > 0)
{
- char *strg_C = NULL;
-
- strg_C = new char [(size_t)attr_size+1];
+ char *strg_C = new char[(size_t)attr_size+1];
herr_t ret_value = H5Aread(id, mem_type.getId(), strg_C);
-
if( ret_value < 0 )
{
delete []strg_C; // de-allocate for fixed-len string
throw AttributeIException("Attribute::read", "H5Aread failed");
}
-
// Get string from the C char* and release resource allocated locally
+ strg_C[attr_size] = '\0';
strg = strg_C;
delete []strg_C;
}
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index 8c1237d..5b93bd5 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -31,6 +31,7 @@
#include "H5DataSet.h"
#include "H5File.h"
#include "H5Alltypes.h"
+#include "H5private.h" // for HDstrcpy
// There are a few comments that are common to most of the functions
// defined in this file so they are listed here.
@@ -1058,10 +1059,27 @@ H5std_string CommonFG::getObjnameByIdx(hsize_t idx) const
/// each time the group is opened.
// Programmer Binh-Minh Ribler - January, 2003
//--------------------------------------------------------------------------
+ssize_t CommonFG::getObjnameByIdx(hsize_t idx, char* name, size_t size) const
+{
+ ssize_t name_len = H5Lget_name_by_idx(getLocId(), ".", H5_INDEX_NAME, H5_ITER_INC, idx, name, size, H5P_DEFAULT);
+ if(name_len < 0)
+ {
+ throwException("getObjnameByIdx", "H5Lget_name_by_idx failed");
+ }
+ return (name_len);
+}
+
+//--------------------------------------------------------------------------
+// Function: CommonFG::getObjnameByIdx
+///\brief This is an overloaded member function, provided for convenience.
+/// It differs from the above function in that it takes an
+/// \c std::string for \a name.
+// Programmer Binh-Minh Ribler - January, 2003
+//--------------------------------------------------------------------------
ssize_t CommonFG::getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size) const
{
char* name_C = new char[size];
- ssize_t name_len = H5Lget_name_by_idx(getLocId(), ".", H5_INDEX_NAME, H5_ITER_INC, idx, name_C, size, H5P_DEFAULT);
+ ssize_t name_len = getObjnameByIdx(idx, name_C, size);
if(name_len < 0)
{
throwException("getObjnameByIdx", "H5Lget_name_by_idx failed");
@@ -1095,7 +1113,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: HDstrcpy(type_name, "symbolic link"); break;
+ case H5G_GROUP: HDstrcpy(type_name, "group"); break;
+ case H5G_DATASET: HDstrcpy(type_name, "dataset"); break;
+ case H5G_TYPE: HDstrcpy(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 d472d42..4f32d21 100644
--- a/c++/src/H5CommonFG.h
+++ b/c++/src/H5CommonFG.h
@@ -70,13 +70,15 @@ class H5_DLLCPP CommonFG {
// Retrieves the name of an object in this group, given the
// object's index.
- ssize_t getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size) const;
H5std_string getObjnameByIdx(hsize_t idx) const;
+ ssize_t getObjnameByIdx(hsize_t idx, char* name, size_t size) const;
+ ssize_t getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size) const;
#ifndef H5_NO_DEPRECATED_SYMBOLS
// 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++/src/Makefile.in b/c++/src/Makefile.in
index 94fb618..2c595fc 100644
--- a/c++/src/Makefile.in
+++ b/c++/src/Makefile.in
@@ -390,7 +390,7 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog
# Add libtool shared library version numbers to the HDF5 library
# See libtool versioning documentation online.
LT_VERS_INTERFACE = 6
-LT_VERS_REVISION = 58
+LT_VERS_REVISION = 59
LT_VERS_AGE = 0
# Include src directory
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 3875dfd..aeb202a 100644
--- a/c++/test/trefer.cpp
+++ b/c++/test/trefer.cpp
@@ -47,6 +47,10 @@ const H5std_string FILE2("trefer2.h5");
const H5std_string FILE3("trefer3.h5");
const H5std_string DSET_DEFAULT_NAME("default");
+// Dataset 1
+const H5std_string DSET1_NAME("Dataset1");
+const int DSET1_LEN = 8;
+
const H5std_string MEMBER1( "a_name" );
const H5std_string MEMBER2( "b_name" );
const H5std_string MEMBER3( "c_name" );
@@ -109,7 +113,7 @@ static void test_reference_obj(void)
group.setComment(".", write_comment);
// Create a dataset (inside /Group1)
- DataSet dataset = group.createDataSet("Dataset1", PredType::NATIVE_UINT, sid1);
+ DataSet dataset = group.createDataSet(DSET1_NAME, PredType::NATIVE_UINT, sid1);
unsigned *tu32; // Temporary pointer to uint32 data
for (tu32=(unsigned *)wbuf, i=0; i<SPACE1_DIM1; i++)
@@ -216,11 +220,57 @@ static void test_reference_obj(void)
H5std_string read_comment1 = group.getComment(".", 10);
verify_val(read_comment1, write_comment, "Group::getComment", __LINE__, __FILE__);
- // Test that getComment handles failures gracefully
- try {
- H5std_string read_comment_tmp = group.getComment(NULL);
- }
- catch (Exception E) {} // We expect this to fail
+ // Test that getComment handles failures gracefully
+ try {
+ H5std_string read_comment_tmp = group.getComment(NULL);
+ }
+ catch (Exception E) {} // We expect this to fail
+
+ // Test reading the name of an item in the group
+
+ // Test getObjnameByIdx(idx)
+ H5std_string name;
+ name = group.getObjnameByIdx(0);
+ verify_val(name, DSET1_NAME, "Group::getObjnameByIdx", __LINE__, __FILE__);
+ // Test getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size)
+ name.clear();
+ ssize_t name_size = group.getObjnameByIdx(0, name, 5);
+ verify_val(name, "Data", "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__);
+ verify_val(name_size, DSET1_LEN, "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__);
+
+ name.clear();
+ name_size = group.getObjnameByIdx(0, name, name_size+1);
+ verify_val(name, DSET1_NAME, "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__);
+ verify_val(name_size, DSET1_LEN, "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__);
+
+ // Test getObjnameByIdx(hsize_t idx, char* name, size_t size)
+ char name_C[DSET1_LEN+1];
+ group.getObjnameByIdx(0, name, name_size+1);
+ 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__);
+
+#ifndef H5_NO_DEPRECATED_SYMBOLS
+ // 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__);
+
+#endif // ifndef H5_NO_DEPRECATED_SYMBOLS
// Close group
group.close();