summaryrefslogtreecommitdiffstats
path: root/c++/src
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2014-04-06 22:36:15 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2014-04-06 22:36:15 (GMT)
commita08f75b0737c86d51bbc91538e78b1455eb2cae7 (patch)
treea1e1c4f1cf8ddda6dd0a101af17dc8524ad23050 /c++/src
parent70daa61a876274a92c0d43ec0116d68e35d0c2ce (diff)
downloadhdf5-a08f75b0737c86d51bbc91538e78b1455eb2cae7.zip
hdf5-a08f75b0737c86d51bbc91538e78b1455eb2cae7.tar.gz
hdf5-a08f75b0737c86d51bbc91538e78b1455eb2cae7.tar.bz2
[svn-r24969] Description:
- Added wrappers to H5Object for H5Iget_name() to get object's name ssize_t getObjName(char *obj_name, size_t buf_size = 0) const; ssize_t getObjName(H5std_string& obj_name, size_t len = 0) const; H5std_string getObjName() const; - Added tests tobject.cpp - Added to various cleanup_* functions in tests to remove generated files - Added an overload H5I_type_t getHDFObjType() to get object's type Platforms tested: Linux/ppc64 (ostrich) Linux/32 2.6 (jam) SunOS 5.11 (emu) with gmake
Diffstat (limited to 'c++/src')
-rw-r--r--c++/src/H5Attribute.cpp6
-rw-r--r--c++/src/H5Attribute.h2
-rw-r--r--c++/src/H5IdComponent.cpp22
-rw-r--r--c++/src/H5IdComponent.h3
-rw-r--r--c++/src/H5Object.cpp112
-rw-r--r--c++/src/H5Object.h8
6 files changed, 147 insertions, 6 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index 9554f95..4625c2c 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -327,7 +327,7 @@ ssize_t Attribute::getName(char* attr_name, size_t buf_size) const
{
throw AttributeIException("Attribute::getName", "Attribute must have a name, name length is 0");
}
-
+ // Return length of the name
return(name_size);
}
@@ -357,7 +357,7 @@ H5std_string Attribute::getName() const
{
throw AttributeIException("Attribute::getName", "Attribute must have a name, name length is 0");
}
- // If attribute's name exists, calls C routine again to get it
+ // Attribute's name exists, retrieve it
else if (name_size > 0)
{
char* name_C = new char[name_size+1]; // temporary C-string
@@ -391,7 +391,7 @@ H5std_string Attribute::getName() const
// Programmer Binh-Minh Ribler - Nov, 2001
// Modification
// Mar 2014 - BMR
-// Revised to allow buf_size to be skipped
+// Revised to allow the argument "len" to be skipped
//--------------------------------------------------------------------------
ssize_t Attribute::getName(H5std_string& attr_name, size_t len) const
{
diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h
index 8332632..8ec04af 100644
--- a/c++/src/H5Attribute.h
+++ b/c++/src/H5Attribute.h
@@ -39,7 +39,7 @@ class H5_DLLCPP Attribute : public AbstractDs, public IdComponent {
// Gets the name of this attribute.
ssize_t getName(char* attr_name, size_t buf_size = 0) const;
- ssize_t getName(H5std_string& attr_name, size_t buf_size = 0) const;
+ ssize_t getName(H5std_string& attr_name, size_t len = 0) const;
H5std_string getName() const;
// Gets a copy of the dataspace for this attribute.
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp
index cdf4272..99a8dc4 100644
--- a/c++/src/H5IdComponent.cpp
+++ b/c++/src/H5IdComponent.cpp
@@ -130,7 +130,7 @@ int IdComponent::getCounter() const
}
//--------------------------------------------------------------------------
-// Function: hdfObjectType
+// Function: getHDFObjType (static)
///\brief Given an id, returns the type of the object.
///\return a valid HDF object type, which may be one of the following:
/// \li \c H5I_FILE
@@ -155,6 +155,26 @@ H5I_type_t IdComponent::getHDFObjType(const hid_t obj_id)
}
//--------------------------------------------------------------------------
+// Function: getHDFObjType
+///\brief Returns the type of the object. It is an overloaded function
+/// of the above function.
+///\return a valid HDF object type, which may be one of the following:
+/// \li \c H5I_FILE
+/// \li \c H5I_GROUP
+/// \li \c H5I_DATATYPE
+/// \li \c H5I_DATASPACE
+/// \li \c H5I_DATASET
+/// \li \c H5I_ATTR
+/// \li or \c H5I_BADID, if no valid type can be determined or the
+/// input object id is invalid.
+// Programmer Binh-Minh Ribler - Mar, 2014
+//--------------------------------------------------------------------------
+H5I_type_t IdComponent::getHDFObjType() const
+{
+ return(getHDFObjType(getId()));
+}
+
+//--------------------------------------------------------------------------
// Function: IdComponent::operator=
///\brief Assignment operator.
///\param rhs - IN: Reference to the existing object
diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h
index ca9352d..3208a39 100644
--- a/c++/src/H5IdComponent.h
+++ b/c++/src/H5IdComponent.h
@@ -46,6 +46,9 @@ class H5_DLLCPP IdComponent {
// Returns an HDF5 object type, given the object id.
static H5I_type_t getHDFObjType(const hid_t obj_id);
+ // Returns an HDF5 object type of this object.
+ H5I_type_t getHDFObjType() const;
+
// Assignment operator.
IdComponent& operator=( const IdComponent& rhs );
diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp
index 1d96f2e..94b03ab 100644
--- a/c++/src/H5Object.cpp
+++ b/c++/src/H5Object.cpp
@@ -31,6 +31,7 @@
#include "H5File.h"
#include "H5DataSet.h"
#include "H5Attribute.h"
+#include "H5private.h" // for HDmemset
#ifndef H5_NO_NAMESPACE
namespace H5 {
@@ -53,6 +54,117 @@ H5Object::H5Object() : H5Location() {}
H5Object::H5Object( const hid_t object_id ) : H5Location( object_id ) {}
//--------------------------------------------------------------------------
+// Function: getObjName
+///\brief Given an id, returns the type of the object.
+///\return The name of the object
+// Programmer Binh-Minh Ribler - Mar, 2014
+//--------------------------------------------------------------------------
+ssize_t H5Object::getObjName(char *obj_name, size_t buf_size) const
+{
+ // H5Iget_name will get buf_size-1 chars of the name to null terminate it
+ ssize_t name_size = H5Iget_name(getId(), obj_name, buf_size);
+
+ // If H5Iget_name returns a negative value, raise an exception
+ if (name_size < 0)
+ {
+ throw Exception(inMemFunc("getObjName"), "H5Iget_name failed");
+ }
+ else if (name_size == 0)
+ {
+ throw Exception(inMemFunc("getObjName"), "Object must have a name, but name length is 0");
+ }
+ // Return length of the name
+ return(name_size);
+}
+
+//--------------------------------------------------------------------------
+// Function: H5Object::getObjName
+///\brief Returns the name of this object as an \a H5std_string.
+///\return Name of the object
+///\exception H5::Exception
+// Programmer Binh-Minh Ribler - Mar, 2014
+// Modification
+//--------------------------------------------------------------------------
+H5std_string H5Object::getObjName() const
+{
+ H5std_string obj_name(""); // object name to return
+
+ // Preliminary call to get the size of the object name
+ ssize_t name_size = H5Iget_name(getId(), NULL, (size_t)0);
+
+ // If H5Iget_name failed, throw exception
+ if (name_size < 0)
+ {
+ throw Exception(inMemFunc("getObjName"), "H5Iget_name failed");
+ }
+ else if (name_size == 0)
+ {
+ throw Exception(inMemFunc("getObjName"), "Object must have a name, but name length is 0");
+ }
+ // Object's name exists, retrieve it
+ else if (name_size > 0)
+ {
+ char* name_C = new char[name_size+1]; // temporary C-string
+ HDmemset(name_C, 0, name_size+1); // clear buffer
+
+ // Use overloaded function
+ name_size = getObjName(name_C, name_size+1);
+
+ // Convert the C object name to return
+ obj_name = name_C;
+
+ // Clean up resource
+ delete []name_C;
+ }
+ // Return object's name
+ return(obj_name);
+}
+
+//--------------------------------------------------------------------------
+// Function: H5Object::getObjName
+///\brief Gets the name of this object, returning its length.
+///\param obj_name - OUT: Buffer for the name string as \a H5std_string
+///\param len - IN: Desired length of the name, default to 0
+///\return Actual length of the object name
+///\exception H5::Exception
+///\par Description
+/// This function retrieves the object's name as an std string.
+/// buf_size can specify a specific length or default to 0, in
+/// which case the entire name will be retrieved.
+// Programmer Binh-Minh Ribler - Mar, 2014
+//--------------------------------------------------------------------------
+ssize_t H5Object::getObjName(H5std_string& obj_name, size_t len) const
+{
+ ssize_t name_size = 0;
+
+ // If no length is provided, get the entire object name
+ if (len == 0)
+ {
+ obj_name = getObjName();
+ name_size = obj_name.length();
+ }
+ // If length is provided, get that number of characters in name
+ else
+ {
+ char* name_C = new char[len+1]; // temporary C-string
+ HDmemset(name_C, 0, len+1); // clear buffer
+
+ // Use overloaded function
+ name_size = getObjName(name_C, len+1);
+
+ // Convert the C object name to return
+ obj_name = name_C;
+
+ // Clean up resource
+ delete []name_C;
+ }
+ // Otherwise, keep obj_name intact
+
+ // Return name size
+ return(name_size);
+}
+
+//--------------------------------------------------------------------------
// Function: H5Object copy constructor
///\brief Copy constructor: makes a copy of the original H5Object
/// instance.
diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h
index 5c2ef98..5576d13 100644
--- a/c++/src/H5Object.h
+++ b/c++/src/H5Object.h
@@ -33,7 +33,7 @@
// H5Object is H5File is not an HDF5 object, and renaming H5Object
// to H5Location will risk breaking user applications.
// -BMR
-
+// Apr 2, 2014: Added wrapper getObjName for H5Iget_name
#ifndef H5_NO_NAMESPACE
namespace H5 {
#endif
@@ -50,6 +50,12 @@ class H5_DLLCPP H5Object : public H5Location {
// Copy constructor: makes copy of an H5Object object.
H5Object(const H5Object& original);
+ // Gets the name of this HDF5 object, i.e., Group, DataSet, or
+ // DataType.
+ ssize_t getObjName(char *obj_name, size_t buf_size = 0) const;
+ ssize_t getObjName(H5std_string& obj_name, size_t len = 0) const;
+ H5std_string getObjName() const;
+
// Noop destructor.
virtual ~H5Object();