Miscellaneous improvements

Description:
    Moved H5Location::getNumObjs to Group::getNumObjs (i.e., H5Gget_info)
    Switched reinterpret_cast to static_cast in H5Object::iterateAttrs
    Miscellaneous cleanup
Platforms tested:
    Linux/32 2.6 (jam)
    Linux/64 (platypus)
    Darwin (osx1010test)
This commit is contained in:
Binh-Minh Ribler 2017-08-24 13:46:39 -05:00
parent a6d5bf1a86
commit 0e44181bbb
7 changed files with 71 additions and 69 deletions

View File

@ -13,8 +13,8 @@
#include <string>
#include "H5Include.h"
#include "H5private.h" // for HDstrcpy
#include "H5Include.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5DataSpace.h"
@ -64,7 +64,8 @@ DataType CommonFG::openDataType(const char* name) const
throwException("openDataType", "H5Topen2 failed");
// No failure, create and return the DataType object
DataType data_type(type_id);
DataType data_type;
f_DataType_setId(&data_type, type_id);
return(data_type);
}

View File

@ -21,7 +21,7 @@ namespace H5 {
\brief Class H5File represents an HDF5 file and inherits from class Group
as file is a root group.
Inheritance: Group -> H5Object -> H5Location -> IdComponent
Inheritance: Group -> CommonFG/H5Object -> H5Location -> IdComponent
*/
class H5_DLLCPP H5File : public Group {
public:
@ -92,7 +92,7 @@ class H5_DLLCPP H5File : public Group {
// Throw file exception.
virtual void throwException(const H5std_string& func_name, const H5std_string& msg) const;
// for CommonFG to get the file id.
// For CommonFG to get the file id.
virtual hid_t getLocId() const;
// Default constructor

View File

@ -61,44 +61,6 @@ Group::Group(const Group& original) : H5Object(), CommonFG(), id(original.id)
incRefCount(); // increment number of references to this id
}
//--------------------------------------------------------------------------
// Function: Group::getObjId
///\brief Opens an object via object header.
///\param obj_name - IN: Path to the object
///\param plist - IN: Access property list for the link pointing to
/// the object
///\exception H5::FileIException or H5::GroupIException
///\par Description
/// This function opens an object in a group or file, using
/// H5Oopen. Thus, an object can be opened without knowing
/// the object's type.
// Programmer Binh-Minh Ribler - March, 2017
//--------------------------------------------------------------------------
hid_t Group::getObjId(const char* obj_name, const PropList& plist) const
{
hid_t ret_value = H5Oopen(getId(), obj_name, plist.getId());
if (ret_value < 0)
{
throwException("Group::getObjId", "H5Oopen failed");
}
return(ret_value);
}
//--------------------------------------------------------------------------
// Function: Group::getObjId
///\brief This is an overloaded member function, provided for convenience.
/// It takes a reference to a \c H5std_string for the object's name.
///\param obj_name - IN: Path to the object
///\param plist - IN: Access property list for the link pointing to
/// the object
///\exception H5::FileIException or H5::GroupIException
// Programmer Binh-Minh Ribler - March, 2017
//--------------------------------------------------------------------------
hid_t Group::getObjId(const H5std_string& obj_name, const PropList& plist) const
{
return(getObjId(obj_name.c_str(), plist));
}
//--------------------------------------------------------------------------
// Function: Group::closeObjId
///\brief Closes an object, which was opened with Group::getObjId
@ -180,6 +142,61 @@ Group::Group(const H5Location& loc, const void* ref, H5R_type_t ref_type, const
}
*/
//--------------------------------------------------------------------------
// Function: Group::getNumObjs
///\brief Returns the number of objects in this group.
///\return Number of objects
///\exception H5::FileIException or H5::GroupIException
// Programmer Binh-Minh Ribler - January, 2003
//--------------------------------------------------------------------------
hsize_t Group::getNumObjs() const
{
H5G_info_t ginfo; // Group information
herr_t ret_value = H5Gget_info(getId(), &ginfo);
if(ret_value < 0)
throwException("getNumObjs", "H5Gget_info failed");
return (ginfo.nlinks);
}
//--------------------------------------------------------------------------
// Function: Group::getObjId
///\brief Opens an object via object header.
///\param obj_name - IN: Path to the object
///\param plist - IN: Access property list for the link pointing to
/// the object
///\exception H5::FileIException or H5::GroupIException
///\par Description
/// This function opens an object in a group or file, using
/// H5Oopen. Thus, an object can be opened without knowing
/// the object's type.
// Programmer Binh-Minh Ribler - March, 2017
//--------------------------------------------------------------------------
hid_t Group::getObjId(const char* obj_name, const PropList& plist) const
{
hid_t ret_value = H5Oopen(getId(), obj_name, plist.getId());
if (ret_value < 0)
{
throwException("Group::getObjId", "H5Oopen failed");
}
return(ret_value);
}
//--------------------------------------------------------------------------
// Function: Group::getObjId
///\brief This is an overloaded member function, provided for convenience.
/// It takes a reference to a \c H5std_string for the object's name.
///\param obj_name - IN: Path to the object
///\param plist - IN: Access property list for the link pointing to
/// the object
///\exception H5::FileIException or H5::GroupIException
// Programmer Binh-Minh Ribler - March, 2017
//--------------------------------------------------------------------------
hid_t Group::getObjId(const H5std_string& obj_name, const PropList& plist) const
{
return(getObjId(obj_name.c_str(), plist));
}
//--------------------------------------------------------------------------
// Function: Group::getId
///\brief Get the id of this group

View File

@ -53,6 +53,9 @@ class H5_DLLCPP Group : public H5Object, public CommonFG {
// Removed in 1.10.1, because H5Location is baseclass
// Group(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT);
// Returns the number of objects in this group.
hsize_t getNumObjs() const;
// Opens an object within a group or a file, i.e., root group.
hid_t getObjId(const char* name, const PropList& plist = PropList::DEFAULT) const;
hid_t getObjId(const H5std_string& name, const PropList& plist = PropList::DEFAULT) const;

View File

@ -1281,23 +1281,6 @@ int H5Location::iterateElems(const H5std_string& name, int *idx, H5G_iterate_t o
}
#endif /* H5_NO_DEPRECATED_SYMBOLS */
//--------------------------------------------------------------------------
// Function: H5Location::getNumObjs
///\brief Returns the number of objects in this group.
///\return Number of objects
///\exception H5::FileIException or H5::GroupIException
// Programmer Binh-Minh Ribler - January, 2003
//--------------------------------------------------------------------------
hsize_t H5Location::getNumObjs() const
{
H5G_info_t ginfo; // Group information
herr_t ret_value = H5Gget_info(getId(), &ginfo);
if(ret_value < 0)
throwException("getNumObjs", "H5Gget_info failed");
return (ginfo.nlinks);
}
//--------------------------------------------------------------------------
// Function: H5Location::getObjnameByIdx
///\brief Returns the name of an object in this group, given the

View File

@ -113,9 +113,6 @@ class H5_DLLCPP H5Location : public IdComponent {
H5std_string getLinkval(const char* link_name, size_t size=0) const;
H5std_string getLinkval(const H5std_string& link_name, size_t size=0) const;
// Returns the number of objects in this group.
hsize_t getNumObjs() const;
// Retrieves the name of an object in this group, given the
// object's index.
H5std_string getObjnameByIdx(hsize_t idx) const;

View File

@ -44,10 +44,10 @@ namespace H5 {
extern "C" herr_t userAttrOpWrpr(hid_t loc_id, const char *attr_name,
const H5A_info_t *ainfo, void *op_data)
{
H5std_string s_attr_name = H5std_string(attr_name);
UserData4Aiterate* myData = reinterpret_cast<UserData4Aiterate *> (op_data);
myData->op(*myData->location, s_attr_name, myData->opData);
return 0;
H5std_string s_attr_name = H5std_string(attr_name);
UserData4Aiterate* myData = reinterpret_cast<UserData4Aiterate *> (op_data);
myData->op(*myData->location, s_attr_name, myData->opData);
return 0;
}
//--------------------------------------------------------------------------
@ -81,6 +81,7 @@ H5Object::H5Object() : H5Location() {}
// This constructor is no longer appropriate because the data member "id" had
// been moved to the sub-classes. It is removed from 1.8.15 because it is
// a noop and it can be generated by the compiler if needed.
// Removed in 1.10.1 - Aug 2016
//--------------------------------------------------------------------------
// H5Object::H5Object(const H5Object& original) : H5Location() {}
@ -148,7 +149,7 @@ Attribute H5Object::createAttribute(const char* name, const DataType& data_type,
//--------------------------------------------------------------------------
Attribute H5Object::createAttribute(const H5std_string& name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist) const
{
return(createAttribute( name.c_str(), data_type, data_space, create_plist));
return(createAttribute(name.c_str(), data_type, data_space, create_plist));
}
//--------------------------------------------------------------------------
@ -183,7 +184,7 @@ Attribute H5Object::openAttribute(const char* name) const
//--------------------------------------------------------------------------
Attribute H5Object::openAttribute(const H5std_string& name) const
{
return(openAttribute( name.c_str()));
return(openAttribute(name.c_str()));
}
//--------------------------------------------------------------------------
@ -239,7 +240,7 @@ int H5Object::iterateAttrs(attr_operator_t user_op, unsigned *_idx, void *op_dat
// call the C library routine H5Aiterate2 to iterate the attributes
hsize_t idx = _idx ? static_cast<hsize_t>(*_idx) : 0;
int ret_value = H5Aiterate2(getId(), H5_INDEX_NAME, H5_ITER_INC, &idx,
userAttrOpWrpr, reinterpret_cast<void *>(userData));
userAttrOpWrpr, static_cast<void *>(userData));
// release memory
delete userData;