[svn-r6303] Purpose:

new functions
Description:
    Added these member functions to class Group per the new C functions
    H5Gget_num_objs, H5Gget_objname_by_idx and H5Gget_objtype_by_idx:

        // Returns the number of objects in the group.
        hsize_t getNumObjs() const;

        // Retrieves the name of an object in a given group by giving index
        ssize_t getObjnameByIdx(hsize_t idx, string& name, size_t size) const;

        // Returns the type of an object in a given group by giving index;
        // the overloaded function also provided the object type in text as
        // "group" for H5G_GROUP
        // "dataset" for H5G_DATASET
        // "datatype" for H5G_TYPE
        int getObjTypeByIdx(hsize_t idx) const;
        int getObjTypeByIdx(hsize_t idx, string& type_name) const;
Platforms:
    SunOS 5.7 (arabica)
    Linux 6.2 (eirene)
    IRIX 6.5.11 (modi4)
This commit is contained in:
Binh-Minh Ribler 2003-01-20 20:31:43 -05:00
parent 052153434e
commit fffa25d34c
2 changed files with 68 additions and 0 deletions

View File

@ -53,6 +53,59 @@ hid_t Group::getLocId() const
// Creates a copy of an existing Group using its id
Group::Group( const hid_t group_id ) : H5Object( group_id ) {}
// Returns the number of objects in the group.
hsize_t Group::getNumObjs() const
{
hsize_t num_objs;
herr_t ret_value = H5Gget_num_objs(id, &num_objs);
if(ret_value < 0)
{
throwException("getNumObjs", "H5Gget_num_objs failed");
}
return (num_objs);
}
// Retrieves the name of an object in a given group by giving index
ssize_t Group::getObjnameByIdx(hsize_t idx, string& name, size_t size) const
{
char* name_C = new char[size];
ssize_t name_len = H5Gget_objname_by_idx(id, idx, name_C, size);
if(name_len < 0)
{
throwException("getObjnameByIdx", "H5Gget_objname_by_idx failed");
}
name = string( name_C );
delete [] name_C;
return (name_len);
}
// Returns the type of an object in a given group by giving index
int Group::getObjTypeByIdx(hsize_t idx) const
{
int obj_type = H5Gget_objtype_by_idx(id, idx);
if (obj_type == H5G_UNKNOWN)
{
throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
}
return (obj_type);
}
int Group::getObjTypeByIdx(hsize_t idx, string& type_name) const
{
int obj_type = H5Gget_objtype_by_idx(id, idx);
switch (obj_type)
{
case H5G_GROUP: type_name = string("group"); break;
case H5G_DATASET: type_name = string("dataset"); break;
case H5G_TYPE: type_name = string("datatype"); break;
case H5G_UNKNOWN:
default:
{
throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed");
}
}
return (obj_type);
}
// Iterates a user's function over the entries of a group.
//int Group::iterateElems( const string& name, int *idx, H5G_iterate_t op , void *op_data )
//{

View File

@ -28,6 +28,21 @@ class H5_DLLCPP Group : public H5Object, public CommonFG {
// Copy constructor: makes a copy of the original object
Group( const Group& original );
// Returns the number of objects in the group.
hsize_t getNumObjs() const;
// Retrieves the name of an object in a given group by giving index
//ssize_t getObjnameByIdx(hsize_t idx, char *name, size_t size) const;
ssize_t getObjnameByIdx(hsize_t idx, string& name, size_t size) const;
// Returns the type of an object in a given group by giving index;
// the overloaded function also provided the object type in text as
// "group" for H5G_GROUP
// "dataset" for H5G_DATASET
// "datatype" for H5G_TYPE
int getObjTypeByIdx(hsize_t idx) const;
int getObjTypeByIdx(hsize_t idx, string& type_name) const;
// for CommonFG to get the file id
virtual hid_t getLocId() const;