From be0a7c4a64893b0258d820de1dffd4e272d096f4 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Sun, 2 May 2010 10:10:11 -0500 Subject: [svn-r18683] Purpose: Fix bugzilla 1857 Description: Added missing overloaded function getObjnameByIdx to take char* for name. Platforms tested: Linux/32 2.6 (jam) FreeBSD/64 6.3 (liberty) SunOS 5.10 (linew) --- c++/src/H5CommonFG.cpp | 19 ++++++++++++++++++- c++/src/H5CommonFG.h | 3 ++- c++/test/trefer.cpp | 26 ++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index 43698bb..0b1ff21 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -1058,10 +1058,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"); diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h index d472d42..75c9259 100644 --- a/c++/src/H5CommonFG.h +++ b/c++/src/H5CommonFG.h @@ -70,8 +70,9 @@ 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 diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp index 16f6628..41ee808 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