summaryrefslogtreecommitdiffstats
path: root/c++/src/H5Attribute.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c++/src/H5Attribute.cpp')
-rw-r--r--c++/src/H5Attribute.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index 86f1377..fa37059 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -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.