[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
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "H5File.h"
|
||||
#include "H5DataSet.h"
|
||||
#include "H5Attribute.h"
|
||||
#include "H5private.h" // for HDmemset
|
||||
|
||||
#ifndef H5_NO_NAMESPACE
|
||||
namespace H5 {
|
||||
@@ -52,6 +53,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
|
||||
|
||||
Reference in New Issue
Block a user