From 60a7eb1e422f56005b2d2bcd517484cc76d4b610 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Sun, 22 May 2005 22:33:15 -0500 Subject: [svn-r10782] Purpose: Added more APIs Description: - Added another overloaded CommonFG::getComment so the user will not have to provide the comment's length. - Added wrappers for H5Gget_comment when the comment is to be removed, CommonFG::removeComment. - Corrected several 'delete' statements Platforms tested: Linux 2.4 (heping) SunOS 5.8 64-bit (sol) AIX 5.1 (copper) --- c++/src/H5ArrayType.cpp | 2 +- c++/src/H5Attribute.cpp | 6 ++-- c++/src/H5CommonFG.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++-- c++/src/H5CommonFG.h | 5 ++++ c++/src/H5DataSet.cpp | 2 +- c++/src/H5EnumType.cpp | 2 +- c++/src/H5IdComponent.cpp | 2 +- c++/src/H5PropList.cpp | 2 +- 8 files changed, 83 insertions(+), 11 deletions(-) diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp index b580660..6766602 100644 --- a/c++/src/H5ArrayType.cpp +++ b/c++/src/H5ArrayType.cpp @@ -164,7 +164,7 @@ ArrayType::~ArrayType() { // Free allocated memory if (dimensions != NULL) - delete [] dimensions; + delete []dimensions; } #ifndef H5_NO_NAMESPACE diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index 1268611..cd6e737 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -135,7 +135,7 @@ void Attribute::read( const DataType& mem_type, string& strg ) const throw AttributeIException("Attribute::read", "H5Aread failed"); } strg = strg_C; - delete strg_C; + delete []strg_C; } //-------------------------------------------------------------------------- @@ -205,7 +205,7 @@ ssize_t Attribute::getName( size_t buf_size, string& attr_name ) const } // otherwise, convert the C attribute name and return attr_name = name_C; - delete name_C; + delete []name_C; return( name_size ); } @@ -252,7 +252,7 @@ string Attribute::getName() const else attr_name = name_C; - delete name_C; + delete []name_C; return( attr_name ); } diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index ba7cd9c..0b839ba 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -355,7 +355,7 @@ string CommonFG::getLinkval( const char* name, size_t size ) const throwException("getLinkval", "H5Gget_linkval failed"); } string value = string( value_C ); - delete value_C; + delete []value_C; return( value ); } @@ -408,9 +408,76 @@ void CommonFG::setComment( const string& name, const string& comment ) const } //-------------------------------------------------------------------------- +// Function: CommonFG::removeComment +///\brief Removes the comment from an object specified by its name. +///\param name - IN: Name of the object +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - May 2005 +//-------------------------------------------------------------------------- +void CommonFG::removeComment(const char* name) const +{ + herr_t ret_value = H5Gset_comment(getLocId(), name, NULL); + if( ret_value < 0 ) + { + throwException("removeComment", "H5Gset_comment failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::removeComment +///\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 - May 2005 +//-------------------------------------------------------------------------- +void CommonFG::removeComment(const string& name) const +{ + removeComment (name.c_str()); +} + +//-------------------------------------------------------------------------- // Function: CommonFG::getComment ///\brief Retrieves comment for the specified object. ///\param name - IN: Name of the object +///\return Comment string +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - May 2005 +//-------------------------------------------------------------------------- +string CommonFG::getComment (const string& name) const +{ + size_t bufsize = 256; // anticipating the comment's length + hid_t loc_id = getLocId(); // temporary variable + + // temporary C-string for the object's comment + char* comment_C = new char[bufsize+1]; + herr_t ret_value = H5Gget_comment (loc_id, name.c_str(), bufsize, comment_C); + + // if the actual length of the comment is longer than the anticipated + // value, then call H5Gget_comment again with the correct value + if (ret_value > bufsize) + { + bufsize = ret_value; + delete []comment_C; + comment_C = new char[bufsize+1]; + ret_value = H5Gget_comment (loc_id, name.c_str(), bufsize, comment_C); + } + + // if H5Gget_comment returns SUCCEED, return the string comment, + // otherwise, throw an exception + if( ret_value < 0 ) + { + throwException("getComment", "H5Gget_comment failed"); + } + string comment = string( comment_C ); + delete []comment_C; + return (comment); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::getComment +///\brief Retrieves comment for the specified object and its comment's +/// length. +///\param name - IN: Name of the object ///\param bufsize - IN: Length of the comment to retrieve ///\return Comment string ///\exception H5::FileIException or H5::GroupIException @@ -429,7 +496,7 @@ string CommonFG::getComment( const char* name, size_t bufsize ) const throwException("getComment", "H5Gget_comment failed"); } string comment = string( comment_C ); - delete comment_C; + delete []comment_C; return( comment ); } @@ -784,7 +851,7 @@ string CommonFG::getObjnameByIdx(hsize_t idx) const // clean up and return the string string name = string(name_C); - delete [] name_C; + delete []name_C; return (name); } diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h index 075aca2..7541627 100644 --- a/c++/src/H5CommonFG.h +++ b/c++/src/H5CommonFG.h @@ -47,9 +47,14 @@ class H5_DLLCPP CommonFG { DataSet openDataSet(const string& name) const; // Retrieves comment for the HDF5 object specified by its name. + string getComment(const string& name) const; string getComment(const char* name, size_t bufsize) const; string getComment(const string& name, size_t bufsize) const; + // Removes the comment for the HDF5 object specified by its name. + void removeComment(const char* name) const; + void removeComment(const string& name) const; + // Sets the comment for an HDF5 object specified by its name. void setComment(const char* name, const char* comment) const; void setComment(const string& name, const string& comment) const; diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp index a6de2dc..be8abb2 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -260,7 +260,7 @@ void DataSet::read( string& strg, const DataType& mem_type, const DataSpace& mem // Get the String and clean up strg = strg_C; - delete strg_C; + delete []strg_C; } //-------------------------------------------------------------------------- diff --git a/c++/src/H5EnumType.cpp b/c++/src/H5EnumType.cpp index 2f04d1e..47673b4 100644 --- a/c++/src/H5EnumType.cpp +++ b/c++/src/H5EnumType.cpp @@ -160,7 +160,7 @@ string EnumType::nameOf( void *value, size_t size ) const } // otherwise, create the string to hold the datatype name and return it string name = string( name_C ); - delete [] name_C; + delete []name_C; return( name ); } diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index 7c9457a..53980ca 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -265,7 +265,7 @@ string IdComponent::p_get_file_name() const // Convert the C file name and return string file_name(name_C); - delete name_C; + delete []name_C; return(file_name); } diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp index cb3f211..4f5f3b5 100644 --- a/c++/src/H5PropList.cpp +++ b/c++/src/H5PropList.cpp @@ -307,7 +307,7 @@ string PropList::getProperty(const char* name) const // Return propety value as a string after deleting temp C-string string prop_strg = string(prop_strg_C); - delete prop_strg_C; + delete []prop_strg_C; return (prop_strg); } //-------------------------------------------------------------------------- -- cgit v0.12