summaryrefslogtreecommitdiffstats
path: root/c++/src/H5CommonFG.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2013-09-19 02:41:00 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2013-09-19 02:41:00 (GMT)
commitd95f5e293a2c550f24522a98873a08ad7942ee06 (patch)
treec5cf910060adc63724b65e57f540261f33961063 /c++/src/H5CommonFG.cpp
parent18b896112c1fd7db68323a9dd4a18cfa19deedc2 (diff)
downloadhdf5-d95f5e293a2c550f24522a98873a08ad7942ee06.zip
hdf5-d95f5e293a2c550f24522a98873a08ad7942ee06.tar.gz
hdf5-d95f5e293a2c550f24522a98873a08ad7942ee06.tar.bz2
[svn-r24162] backing out a commit that includes wrong files
Diffstat (limited to 'c++/src/H5CommonFG.cpp')
-rw-r--r--c++/src/H5CommonFG.cpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index 3bf4b4f..d6fe5dc 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -460,6 +460,137 @@ H5std_string CommonFG::getLinkval( const H5std_string& name, size_t size ) const
}
//--------------------------------------------------------------------------
+// Function: CommonFG::setComment
+///\brief Sets or resets the comment for an object specified by its name.
+///\param name - IN: Name of the object
+///\param comment - IN: New comment
+///\exception H5::FileIException or H5::GroupIException
+///\par Description
+/// If \a comment is an empty string or a null pointer, the comment
+/// message is removed from the object.
+/// Comments should be relatively short, null-terminated, ASCII
+/// strings. They can be attached to any object that has an
+/// object header, e.g., data sets, groups, named data types,
+/// and data spaces, but not symbolic links.
+// Programmer Binh-Minh Ribler - 2000
+// Modification
+// 2007: QAK modified to use H5O APIs; however the first parameter is
+// no longer just file or group, this function should be moved
+// to another class to accommodate attribute, dataset, and named
+// datatype. - BMR
+//--------------------------------------------------------------------------
+void CommonFG::setComment( const char* name, const char* comment ) const
+{
+ herr_t ret_value = H5Oset_comment_by_name( getLocId(), name, comment, H5P_DEFAULT );
+ if( ret_value < 0 )
+ throwException("setComment", "H5Oset_comment_by_name failed");
+}
+
+//--------------------------------------------------------------------------
+// Function: CommonFG::setComment
+///\brief This is an overloaded member function, provided for convenience.
+/// It differs from the above function in that it takes an
+/// \c H5std_string for \a name and \a comment.
+// Programmer Binh-Minh Ribler - 2000
+//--------------------------------------------------------------------------
+void CommonFG::setComment( const H5std_string& name, const H5std_string& comment ) const
+{
+ setComment( name.c_str(), comment.c_str() );
+}
+
+//--------------------------------------------------------------------------
+// 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
+// 2007: QAK modified to use H5O APIs; however the first parameter is
+// no longer just file or group, this function should be moved
+// to another class to accommodate attribute, dataset, and named
+// datatype. - BMR
+//--------------------------------------------------------------------------
+void CommonFG::removeComment(const char* name) const
+{
+ herr_t ret_value = H5Oset_comment_by_name(getLocId(), name, NULL, H5P_DEFAULT);
+ if( ret_value < 0 )
+ throwException("removeComment", "H5Oset_comment_by_name 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 H5std_string for \a name.
+// Programmer Binh-Minh Ribler - May 2005
+//--------------------------------------------------------------------------
+void CommonFG::removeComment(const H5std_string& name) const
+{
+ removeComment (name.c_str());
+}
+
+//--------------------------------------------------------------------------
+// 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
+// Programmer Binh-Minh Ribler - 2000
+// 2007: QAK modified to use H5O APIs; however the first parameter is
+// no longer just file or group, this function should be moved
+// to another class to accommodate attribute, dataset, and named
+// datatype. - BMR
+//--------------------------------------------------------------------------
+H5std_string CommonFG::getComment( const char* name, size_t bufsize ) const
+{
+ // bufsize is default to 256
+ // temporary variable
+ hid_t loc_id = getLocId(); // temporary variable
+
+ // temporary C-string for the object's comment; bufsize already including
+ // null character
+ char* comment_C = new char[bufsize];
+ ssize_t ret_value = H5Oget_comment_by_name(loc_id, name, comment_C, bufsize, H5P_DEFAULT);
+
+ // if the actual length of the comment is longer than bufsize and bufsize
+ // was the default value, i.e., not given by the user, then call
+ // H5Oget_comment_by_name again with the correct value.
+ // If the call to H5Oget_comment_by_name returned an error, skip this block
+ // and throw an exception below.
+ if (ret_value >= 0 && (size_t)ret_value > bufsize && bufsize == 256)
+ {
+ size_t new_size = ret_value;
+ delete []comment_C;
+ comment_C = new char[new_size]; // new_size including null terminator
+ ret_value = H5Oget_comment_by_name(loc_id, name, comment_C, new_size, H5P_DEFAULT);
+ }
+
+ // if H5Oget_comment_by_name returns SUCCEED, return the string comment,
+ // otherwise, throw an exception
+ if( ret_value < 0 ) {
+ delete []comment_C;
+ throwException("getComment", "H5Oget_comment_by_name failed");
+ }
+
+ H5std_string comment = H5std_string(comment_C);
+ delete []comment_C;
+ return (comment);
+}
+
+//--------------------------------------------------------------------------
+// Function: CommonFG::getComment
+///\brief This is an overloaded member function, provided for convenience.
+/// It differs from the above function in that it takes an
+/// \c H5std_string for \a name.
+// Programmer Binh-Minh Ribler - 2000
+//--------------------------------------------------------------------------
+H5std_string CommonFG::getComment( const H5std_string& name, size_t bufsize ) const
+{
+ return( getComment( name.c_str(), bufsize ));
+}
+
+//--------------------------------------------------------------------------
// Function: CommonFG::mount
///\brief Mounts the file \a child onto this group.
///\param name - IN: Name of the group