summaryrefslogtreecommitdiffstats
path: root/c++/src/H5CommonFG.cpp
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-11-16 20:45:05 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-11-16 20:45:05 (GMT)
commitd2b87ec47ebdb096c331c7b62a195b9cea2f33ae (patch)
treea066f01361afaf5df457cef612bb0bb9fd80fe18 /c++/src/H5CommonFG.cpp
parentee5a1e07350f0dcf3ef07d9443aa2f4c073392f4 (diff)
downloadhdf5-d2b87ec47ebdb096c331c7b62a195b9cea2f33ae.zip
hdf5-d2b87ec47ebdb096c331c7b62a195b9cea2f33ae.tar.gz
hdf5-d2b87ec47ebdb096c331c7b62a195b9cea2f33ae.tar.bz2
[svn-r17896] Description:
Bring r17546:17895 from trunk to revise_chunks branch. Changes to fixed and extensible array dataset chunk indexing code to accommodate changes to private APIs in those interfaces. Also, other adjustments to source code and expected output in response to changes on the trunk. Tested on: FreeBSD/32 6.3 (duty) in debug mode FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/Intel compilers, w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode Mac OS X/32 10.6.2 (amazon) in debug mode Mac OS X/32 10.6.2 (amazon) w/C++ & FORTRAN, w/threadsafe, in production mode
Diffstat (limited to 'c++/src/H5CommonFG.cpp')
-rw-r--r--c++/src/H5CommonFG.cpp106
1 files changed, 48 insertions, 58 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index 80efc5d..f9311c6 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -15,11 +15,6 @@
#include <string>
-// remove when done
-#include <iostream>
- using std::cerr;
- using std::endl;
-
#include "H5Include.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
@@ -430,16 +425,37 @@ void CommonFG::getObjinfo( const H5std_string& name, H5G_stat_t& statbuf ) const
//--------------------------------------------------------------------------
H5std_string CommonFG::getLinkval( const char* name, size_t size ) const
{
- char* value_C = new char[size+1]; // temporary C-string for C API
+ H5L_info_t linkinfo;
+ char *value_C; // value in C string
+ size_t val_size = size;
+ H5std_string value = "";
+ herr_t ret_value;
- herr_t ret_value = H5Lget_val( getLocId(), name, value_C, size, H5P_DEFAULT );
- if( ret_value < 0 )
- {
- throwException("getLinkval", "H5Lget_val failed");
- }
- H5std_string value = H5std_string( value_C );
- delete []value_C;
- return( value );
+ // if user doesn't provide buffer size, determine it
+ if (size == 0)
+ {
+ ret_value = H5Lget_info(getLocId(), name, &linkinfo, H5P_DEFAULT);
+ if( ret_value < 0 )
+ {
+ throwException("getLinkval", "H5Lget_info to find buffer size failed");
+ }
+ val_size = linkinfo.u.val_size;
+ }
+
+ // if link has value, retrieve the value, otherwise, return null string
+ if (val_size > 0)
+ {
+ value_C = new char[val_size+1]; // temporary C-string for C API
+
+ ret_value = H5Lget_val(getLocId(), name, value_C, val_size, H5P_DEFAULT);
+ if( ret_value < 0 )
+ {
+ throwException("getLinkval", "H5Lget_val failed");
+ }
+ value = H5std_string(value_C);
+ delete []value_C;
+ }
+ return(value);
}
//--------------------------------------------------------------------------
@@ -529,33 +545,38 @@ void CommonFG::removeComment(const H5std_string& name) const
//--------------------------------------------------------------------------
// Function: CommonFG::getComment
-///\brief Retrieves comment for the specified object.
+///\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 - May 2005
+// 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 H5std_string& name) const
+H5std_string CommonFG::getComment( const char* name, size_t bufsize ) const
{
- size_t bufsize = 256; // anticipating the comment's length
+ // bufsize is default to 256
+ // temporary variable
hid_t loc_id = getLocId(); // temporary variable
- // temporary C-string for the object's comment
- char* comment_C = new char[bufsize+1];
- ssize_t ret_value = H5Oget_comment_by_name(loc_id, name.c_str(), comment_C, bufsize, H5P_DEFAULT);
+ // 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 the anticipated
- // value, then call H5Oget_comment_by_name again with the correct value
- if ((size_t)ret_value > bufsize)
+ // 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 ((size_t)ret_value > bufsize && bufsize == 256)
{
- bufsize = ret_value;
+ size_t new_size = ret_value;
delete []comment_C;
- comment_C = new char[bufsize+1];
- ret_value = H5Oget_comment_by_name(loc_id, name.c_str(), comment_C, bufsize, H5P_DEFAULT);
+ 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,
@@ -571,37 +592,6 @@ H5std_string CommonFG::getComment (const H5std_string& name) const
//--------------------------------------------------------------------------
// 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
-{
- // temporary C-string for the object's comment
- char* comment_C = new char[bufsize+1];
-
- herr_t ret_value = H5Oget_comment_by_name( getLocId(), name, comment_C, bufsize, H5P_DEFAULT );
-
- // if H5Oget_comment_by_name returns SUCCEED, return the string comment
- if( ret_value < 0 )
- {
- 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 std::string for \a name.