summaryrefslogtreecommitdiffstats
path: root/c++/src
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2003-01-21 01:31:43 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2003-01-21 01:31:43 (GMT)
commitfffa25d34c3a7b8395a42b66fa5886f87110e9b1 (patch)
treefb1ad55501c6c4423c349d837a82741899012c6f /c++/src
parent052153434e54887cd6d90e4ac4194faf0776f777 (diff)
downloadhdf5-fffa25d34c3a7b8395a42b66fa5886f87110e9b1.zip
hdf5-fffa25d34c3a7b8395a42b66fa5886f87110e9b1.tar.gz
hdf5-fffa25d34c3a7b8395a42b66fa5886f87110e9b1.tar.bz2
[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)
Diffstat (limited to 'c++/src')
-rw-r--r--c++/src/H5Group.cpp53
-rw-r--r--c++/src/H5Group.h15
2 files changed, 68 insertions, 0 deletions
diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp
index a7d72f8..b8cc4a4 100644
--- a/c++/src/H5Group.cpp
+++ b/c++/src/H5Group.cpp
@@ -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 )
//{
diff --git a/c++/src/H5Group.h b/c++/src/H5Group.h
index c65a335..25c1b9e 100644
--- a/c++/src/H5Group.h
+++ b/c++/src/H5Group.h
@@ -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;