summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2001-11-14 23:11:06 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2001-11-14 23:11:06 (GMT)
commitd03a993abdd005bd652c8c21febb167eaf23675c (patch)
treef2037c7f3c6509d9de9f0576976607dd0f312b71
parente6dd69dc5fc2c507ca88bb8f3a02f54905e9c3a4 (diff)
downloadhdf5-d03a993abdd005bd652c8c21febb167eaf23675c.zip
hdf5-d03a993abdd005bd652c8c21febb167eaf23675c.tar.gz
hdf5-d03a993abdd005bd652c8c21febb167eaf23675c.tar.bz2
[svn-r4607]
Purpose: Bug fix Description: Add the overloaded member function Attribute::getName to return the attribute name's length as in C API. This functionality was missing. Note that the current getName that returns "string" is not removed, for different way of using getName. Platforms tested: SunOS 5.7 (arabica)
-rw-r--r--c++/src/H5Attribute.cpp23
-rw-r--r--c++/src/H5Attribute.h5
2 files changed, 19 insertions, 9 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index de184a5..fa37059 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -24,7 +24,7 @@ Attribute::Attribute( const Attribute& original ) : AbstractDs( original ) {}
Attribute::Attribute( const hid_t attr_id ) : AbstractDs( attr_id ) {}
// Writes data to this attribute.
-void Attribute::write( const DataType& mem_type, void *buf ) const
+void Attribute::write( const DataType& mem_type, const void *buf ) const
{
herr_t ret_value = H5Awrite( id, mem_type.getId(), buf );
if( ret_value < 0 )
@@ -76,23 +76,32 @@ hid_t Attribute::p_getType() const
}
}
-// Gets the name of this attribute.
-string Attribute::getName( size_t buf_size ) const
+// Gets the name of this attribute, returning its length.
+ssize_t Attribute::getName( size_t buf_size, string& attr_name ) const
{
char* name_C = new char[buf_size+1]; // temporary C-string for C API
// Calls C routine H5Aget_name to get the name of the attribute
- herr_t name_size = H5Aget_name( id, buf_size, name_C );
+ ssize_t name_size = H5Aget_name( id, buf_size, name_C );
// If H5Aget_name returns a negative value, raise an exception,
if( name_size < 0 )
{
throw AttributeIException("Attribute::getName", "H5Aget_name failed");
}
- // otherwise, create the string to hold the attribute name and return it
- string name = string( name_C );
+ // otherwise, convert the C string attribute name and return
+ attr_name = string( name_C );
delete name_C;
- return( name );
+ return( name_size );
+}
+
+// Gets the name of this attribute, returning the name, not the length.
+string Attribute::getName( size_t buf_size ) const
+{
+ string attr_name;
+ ssize_t name_size = getName( buf_size, attr_name );
+ return( attr_name );
+ // let caller catch exception if any
}
// This private function calls the C API H5Aclose to close this attribute.
diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h
index b4ad208..7c509d5 100644
--- a/c++/src/H5Attribute.h
+++ b/c++/src/H5Attribute.h
@@ -9,7 +9,7 @@ namespace H5 {
class Attribute : public AbstractDs {
public:
// Writes data to this attribute.
- void write(const DataType& mem_type, void *buf ) const;
+ void write(const DataType& mem_type, const void *buf ) const;
// Reads data from this attribute.
void read( const DataType& mem_type, void *buf ) const;
@@ -18,7 +18,8 @@ class Attribute : public AbstractDs {
virtual DataSpace getSpace() const;
// Gets the name of this attribute.
- string getName( size_t buf_size ) const;
+ ssize_t getName( size_t buf_size, string& attr_name ) const;
+ string getName( size_t buf_size ) const; // returns name, not its length
// do not inherit iterateAttrs from H5Object
int iterateAttrs() { return 0; }