From 315ca49e4a04ce8874cac02d1cc4a6b7a45bd57c Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Thu, 27 May 2004 02:54:58 -0500 Subject: [svn-r8588] Purpose: Add C++ wrappers - incrementally check-in Description Added wrapper for these C APIs: H5Rcreate H5Rget_obj_type H5Rget_region This is an incremental check-in to preserve the code, corresponding tests will follow in a few weeks. Platforms: Linux 2.4 (eirene) I'm checking the code out and test on arabica too. Misc. update: --- c++/src/H5DataSet.cpp | 68 ++++++++++++++++++++++++++++ c++/src/H5DataSet.h | 13 ++++++ c++/src/H5DataType.cpp | 68 ++++++++++++++++++++++++++++ c++/src/H5DataType.h | 13 ++++++ c++/src/H5File.cpp | 110 ++++++++++++++++++++++++++++++++++++++-------- c++/src/H5File.h | 25 ++++++++--- c++/src/H5Group.cpp | 80 ++++++++++++++++++++++++++------- c++/src/H5Group.h | 13 ++++++ c++/src/H5IdComponent.cpp | 74 +++++++++++++++++++++++++++++++ c++/src/H5IdComponent.h | 39 ++++------------ 10 files changed, 433 insertions(+), 70 deletions(-) diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp index c8171b9..b8ee423 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -411,6 +411,74 @@ void DataSet::fillMemBuf(void *buf, DataType& buf_type, DataSpace& space) } //-------------------------------------------------------------------------- +// Function: DataSet::Reference +///\brief Creates a reference to an HDF5 object or a dataset region. +///\param name - IN: Name of the object to be referenced +///\param dataspace - IN: Dataspace with selection +///\param ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION +///\return A reference +///\exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* DataSet::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const +{ + return(p_reference(name, dataspace.getId(), ref_type)); +} + +//-------------------------------------------------------------------------- +// Function: DataSet::Reference +///\brief This is an overloaded function, provided for your convenience. +/// It differs from the above function in that it only creates +/// a reference to an HDF5 object, not to a dataset region. +///\param name - IN: Name of the object to be referenced +///\return A reference +///\exception H5::ReferenceIException +///\par Description +// This function passes H5R_OBJECT and -1 to the protected +// function for it to pass to the C API H5Rcreate +// to create a reference to the named object. +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* DataSet::Reference(const char* name) const +{ + return(p_reference(name, -1, H5R_OBJECT)); +} + +//-------------------------------------------------------------------------- +// Function: DataSet::getObjType +///\brief Retrieves the type of object that an object reference points to. +///\param ref_type - IN: Type of reference to query +///\param ref - IN: Reference to query +// Return An object type, which can be one of the following: +// H5G_LINK Object is a symbolic link. +// H5G_GROUP Object is a group. +// H5G_DATASET Object is a dataset. +// H5G_TYPE Object is a named datatype +// Exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5G_obj_t DataSet::getObjType(void *ref, H5R_type_t ref_type) const +{ + return(p_get_obj_type(ref, ref_type)); +} + +//-------------------------------------------------------------------------- +// Function: DataSet::getRegion +///\brief Retrieves a dataspace with the region pointed to selected. +///\param ref_type - IN: Type of reference to get region of - default +/// to H5R_DATASET_REGION +///\param ref - IN: Reference to get region of +///\return DataSpace instance +///\exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +DataSpace DataSet::getRegion(void *ref, H5R_type_t ref_type) const +{ + DataSpace dataspace(p_get_region(ref, ref_type)); + return(dataspace); +} + +//-------------------------------------------------------------------------- // Function: DataSet::p_close (private) ///\brief Closes this dataset. ///\exception H5::DataSetIException diff --git a/c++/src/H5DataSet.h b/c++/src/H5DataSet.h index e97a963..39640ea 100644 --- a/c++/src/H5DataSet.h +++ b/c++/src/H5DataSet.h @@ -66,6 +66,19 @@ class H5_DLLCPP DataSet : public AbstractDs { // Fills a selection in memory with zero void fillMemBuf(void *buf, DataType& buf_type, DataSpace& space); + // Creates a reference to a named Hdf5 object in this object. + void* Reference(const char* name) const; + + // Creates a reference to a named Hdf5 object or to a dataset region + // in this object. + void* Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type = H5R_DATASET_REGION) const; + + // Retrieves the type of object that an object reference points to. + H5G_obj_t getObjType(void *ref, H5R_type_t ref_type) const; + + // Retrieves a dataspace with the region pointed to selected. + DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; + // Creates a copy of an existing DataSet using its id // Note: used by CommonFG to return a DataSet; should be modified // to use friend template function instead) diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 1b268e7..0945a76 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -26,6 +26,7 @@ #include "H5Idtemplates.h" #include "H5PropList.h" #include "H5Object.h" +#include "H5DataSpace.h" #include "H5DataType.h" #include "H5AtomType.h" #include "H5PredType.h" @@ -529,6 +530,73 @@ bool DataType::isVariableStr() const } //-------------------------------------------------------------------------- +// Function: DataType::Reference +///\brief Creates a reference to an HDF5 object or a dataset region. +///\param name - IN: Name of the object to be referenced +///\param dataspace - IN: Dataspace with selection +///\param ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION +///\return A reference +///\exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* DataType::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const +{ + return(p_reference(name, dataspace.getId(), ref_type)); +} + +//-------------------------------------------------------------------------- +// Function: DataType::Reference +///\brief This is an overloaded function, provided for your convenience. +/// It differs from the above function in that it only creates +/// a reference to an HDF5 object, not to a dataset region. +///\param name - IN: Name of the object to be referenced +///\return A reference +///\exception H5::ReferenceIException +///\par Description +// This function passes H5R_OBJECT and -1 to the protected +// function for it to pass to the C API H5Rcreate +// to create a reference to the named object. +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* DataType::Reference(const char* name) const +{ + return(p_reference(name, -1, H5R_OBJECT)); +} + +//-------------------------------------------------------------------------- +// Function: DataType::getObjType +///\brief Retrieves the type of object that an object reference points to. +///\param ref - IN: Reference to query +///\param ref_type - IN: Type of reference to query +///\return Object type, which can be one of the following: +/// \li \c H5G_LINK Object is a symbolic link. +/// \li \c H5G_GROUP Object is a group. +/// \li \c H5G_DATASET Object is a dataset. +/// \li \c H5G_TYPE Object is a named datatype +///\exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5G_obj_t DataType::getObjType(void *ref, H5R_type_t ref_type) const +{ + return(p_get_obj_type(ref, ref_type)); +} + +//-------------------------------------------------------------------------- +// Function: DataType::getRegion +///\brief Retrieves a dataspace with the region pointed to selected. +///\param ref - IN: Reference to get region of +///\param ref_type - IN: Type of reference to get region of - default +///\return DataSpace instance +///\exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +DataSpace DataType::getRegion(void *ref, H5R_type_t ref_type) const +{ + DataSpace dataspace(p_get_region(ref, ref_type)); + return(dataspace); +} + +//-------------------------------------------------------------------------- // Function: DataType::p_close (private) ///\brief Closes this datatype. ///\exception H5::DataTypeIException diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h index 24b7ba3..d01c81d 100644 --- a/c++/src/H5DataType.h +++ b/c++/src/H5DataType.h @@ -87,6 +87,19 @@ class H5_DLLCPP DataType : public H5Object { // Checks whether this datatype is a variable-length string. bool isVariableStr() const; + // Creates a reference to a named Hdf5 object in this object. + void* Reference(const char* name) const; + + // Creates a reference to a named Hdf5 object or to a dataset region + // in this object. + void* Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type = H5R_DATASET_REGION) const; + + // Retrieves the type of object that an object reference points to. + H5G_obj_t getObjType(void *ref, H5R_type_t ref_type) const; + + // Retrieves a dataspace with the region pointed to selected. + DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; + // Used by the API to appropriately close a datatype void p_close() const; diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index d869c6f..74be4e9 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -178,19 +178,6 @@ bool H5File::isHdf5(const string& name ) } //-------------------------------------------------------------------------- -// Function: H5File::getLocId -// Purpose: Get the id of this file -// Description -// This function is a redefinition of CommonFG::getLocId. It -// is used by CommonFG member functions to get the file id. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -hid_t H5File::getLocId() const -{ - return( getId() ); -} - -//-------------------------------------------------------------------------- // Function: H5File::reopen ///\brief Reopens this file ///\exception H5::FileIException @@ -273,7 +260,7 @@ FileAccPropList H5File::getAccessPlist() const ///\exception H5::FileIException // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -hssize_t H5File::getFreeSpace() +hssize_t H5File::getFreeSpace() const { hssize_t free_space = H5Fget_freespace(id); if( free_space < 0 ) @@ -303,7 +290,7 @@ hssize_t H5File::getFreeSpace() /// Multiple object types can be combined with the logical OR operator (|). // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -int H5File::getObjCount(unsigned types) +int H5File::getObjCount(unsigned types) const { int num_objs = H5Fget_obj_count(id, types); if( num_objs < 0 ) @@ -322,7 +309,7 @@ int H5File::getObjCount(unsigned types) ///\exception H5::FileIException // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -int H5File::getObjCount() +int H5File::getObjCount() const { int num_objs = H5Fget_obj_count(id, H5F_OBJ_ALL); if( num_objs < 0 ) @@ -355,7 +342,7 @@ int H5File::getObjCount() // Notes: will do the overload for this one after hearing from Quincey??? // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -void H5File::getObjIDs(unsigned types, int max_objs, hid_t *oid_list) +void H5File::getObjIDs(unsigned types, int max_objs, hid_t *oid_list) const { herr_t ret_value = H5Fget_obj_ids(id, types, max_objs, oid_list); if( ret_value < 0 ) @@ -383,7 +370,7 @@ void H5File::getObjIDs(unsigned types, int max_objs, hid_t *oid_list) /// closed and reopened or opened during a subsequent session. // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -void H5File::getVFDHandle(FileAccPropList& fapl, void **file_handle) +void H5File::getVFDHandle(FileAccPropList& fapl, void **file_handle) const { hid_t fapl_id = fapl.getId(); herr_t ret_value = H5Fget_vfd_handle(id, fapl_id, file_handle); @@ -403,7 +390,7 @@ void H5File::getVFDHandle(FileAccPropList& fapl, void **file_handle) ///\exception H5::FileIException // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -void H5File::getVFDHandle(void **file_handle) +void H5File::getVFDHandle(void **file_handle) const { herr_t ret_value = H5Fget_vfd_handle(id, H5P_DEFAULT, file_handle); if( ret_value < 0 ) @@ -413,6 +400,91 @@ void H5File::getVFDHandle(void **file_handle) } //-------------------------------------------------------------------------- +// Function: H5File::Reference +///\brief Creates a reference to an Hdf5 object or a dataset region. +///\param name - IN: Name of the object to be referenced +///\param dataspace - IN: Dataspace with selection +///\param ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION +///\return A reference +///\exception H5::ReferenceIException +///\par Description +/// Note that, for H5File, name must be an absolute path to the +/// object in the file. +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* H5File::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const +{ + return(p_reference(name, dataspace.getId(), ref_type)); +} + +//-------------------------------------------------------------------------- +// Function: H5File::Reference +///\brief This is an overloaded function, provided for your convenience. +/// It differs from the above function in that it only creates +/// a reference to an HDF5 object, not to a dataset region. +///\param name - IN: Name of the object to be referenced +///\return A reference +///\exception H5::ReferenceIException +///\par Description +// This function passes H5R_OBJECT and -1 to the protected +// function for it to pass to the C API H5Rcreate +// to create a reference to the named object. +///\par +/// Note that, for H5File, name must be an absolute path to the +/// object in the file. +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* H5File::Reference(const char* name) const +{ + return(p_reference(name, -1, H5R_OBJECT)); +} + +//-------------------------------------------------------------------------- +// Function: H5File::getObjType +///\brief Retrieves the type of object that an object reference points to. +///\param ref - IN: Reference to query +///\param ref_type - IN: Type of reference to query +///\return Object type, which can be one of the following: +/// \li \c H5G_LINK Object is a symbolic link. +/// \li \c H5G_GROUP Object is a group. +/// \li \c H5G_DATASET Object is a dataset. +/// \li \c H5G_TYPE Object is a named datatype +///\exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5G_obj_t H5File::getObjType(void *ref, H5R_type_t ref_type) const +{ + return(p_get_obj_type(ref, ref_type)); +} + +//-------------------------------------------------------------------------- +// Function: H5File::getRegion +///\brief Retrieves a dataspace with the region pointed to selected. +///\param ref - IN: Reference to get region of +///\param ref_type - IN: Type of reference to get region of - default +///\return DataSpace instance +///\exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +DataSpace H5File::getRegion(void *ref, H5R_type_t ref_type) const +{ + DataSpace dataspace(p_get_region(ref, ref_type)); + return(dataspace); +} +//-------------------------------------------------------------------------- +// Function: H5File::getLocId +// Purpose: Get the id of this file +// Description +// This function is a redefinition of CommonFG::getLocId. It +// is used by CommonFG member functions to get the file id. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +hid_t H5File::getLocId() const +{ + return( getId() ); +} + +//-------------------------------------------------------------------------- // Function: H5File::p_close (private) ///\brief Closes this H5 file. ///\exception H5::FileIException diff --git a/c++/src/H5File.h b/c++/src/H5File.h index 3edc6a3..c1720f3 100644 --- a/c++/src/H5File.h +++ b/c++/src/H5File.h @@ -40,25 +40,38 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { virtual hid_t getLocId() const; // Returns the amount of free space in the file. - hssize_t getFreeSpace(); + hssize_t getFreeSpace() const; // Returns the number of opened object IDs (files, datasets, groups // and datatypes) in the same file. - int getObjCount(unsigned types); - int getObjCount(); + int getObjCount(unsigned types) const; + int getObjCount() const; // Retrieves a list of opened object IDs (files, datasets, groups // and datatypes) in the same file. - void getObjIDs(unsigned types, int max_objs, hid_t *oid_list); + void getObjIDs(unsigned types, int max_objs, hid_t *oid_list) const; // Returns the pointer to the file handle of the low-level file driver. - void getVFDHandle(FileAccPropList& fapl, void **file_handle); - void getVFDHandle(void **file_handle); + void getVFDHandle(FileAccPropList& fapl, void **file_handle) const; + void getVFDHandle(void **file_handle) const; // Determines if a file, specified by its name, is in HDF5 format static bool isHdf5(const string& name ); static bool isHdf5(const char* name ); + // Creates a reference to a named Hdf5 object in this object. + void* Reference(const char* name) const; + + // Creates a reference to a named Hdf5 object or to a dataset region + // in this object. + void* Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type = H5R_DATASET_REGION) const; + + // Retrieves the type of object that an object reference points to. + H5G_obj_t getObjType(void *ref, H5R_type_t ref_type) const; + + // Retrieves a dataspace with the region pointed to selected. + DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; + // Reopens this file void reopen(); diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index 4530dba..dcc6aca 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -161,23 +161,40 @@ int Group::getObjTypeByIdx(hsize_t idx, string& type_name) const 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 ) -//{ - //return( iterateElems( name.c_str(), idx, op, op_data )); -//} -//int Group::iterateElems( const char* name, int *idx, H5G_iterate_t op , void *op_data ) -//{ - //int ret_value = H5Giterate( id, name, idx, op, op_data ); - //if( ret_value >= 0 ) - //return( ret_value ); - //else // raise exception when H5Aiterate returns a negative value - //{ - //throw GroupIException("Group::iterateElems", "H5Giterate failed"); - //} -//} +//-------------------------------------------------------------------------- +// Function: Group::Reference +///\brief Creates a reference to an HDF5 object or a dataset region. +///\param name - IN: Name of the object to be referenced +///\param dataspace - IN: Dataspace with selection +///\param ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION +///\return A reference +///\exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* Group::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const +{ + return(p_reference(name, dataspace.getId(), ref_type)); +} //-------------------------------------------------------------------------- +// Function: Group::Reference +///\brief This is an overloaded function, provided for your convenience. +/// It differs from the above function in that it only creates +/// a reference to an HDF5 object, not to a dataset region. +///\param name - IN: Name of the object to be referenced +///\return A reference +///\exception H5::ReferenceIException +///\par Description +// This function passes H5R_OBJECT and -1 to the protected +// function for it to pass to the C API H5Rcreate +// to create a reference to the named object. +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* Group::Reference(const char* name) const +{ + return(p_reference(name, -1, H5R_OBJECT)); +} +//-------------------------------------------------------------------------- // Function: Group::p_close (private) ///\brief Closes this group. ///\exception H5::GroupIException @@ -196,6 +213,39 @@ void Group::p_close() const } //-------------------------------------------------------------------------- +// Function: Group::getObjType +///\brief Retrieves the type of object that an object reference points to. +///\param ref - IN: Reference to query +///\param ref_type - IN: Type of reference to query +// Return An object type, which can be one of the following: +// H5G_LINK Object is a symbolic link. +// H5G_GROUP Object is a group. +// H5G_DATASET Object is a dataset. +// H5G_TYPE Object is a named datatype +// Exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5G_obj_t Group::getObjType(void *ref, H5R_type_t ref_type) const +{ + return(p_get_obj_type(ref, ref_type)); +} + +//-------------------------------------------------------------------------- +// Function: Group::getRegion +///\brief Retrieves a dataspace with the region pointed to selected. +///\param ref - IN: Reference to get region of +///\param ref_type - IN: Type of reference to get region of - default +///\return DataSpace instance +///\exception H5::ReferenceIException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +DataSpace Group::getRegion(void *ref, H5R_type_t ref_type) const +{ + DataSpace dataspace(p_get_region(ref, ref_type)); + return(dataspace); +} + +//-------------------------------------------------------------------------- // Function: Group::throwException ///\brief Throws group exception - initially implemented for CommonFG ///\param func_name - Name of the function where failure occurs diff --git a/c++/src/H5Group.h b/c++/src/H5Group.h index 7967533..65ce914 100644 --- a/c++/src/H5Group.h +++ b/c++/src/H5Group.h @@ -43,6 +43,19 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { int getObjTypeByIdx(hsize_t idx) const; int getObjTypeByIdx(hsize_t idx, string& type_name) const; + // Creates a reference to a named Hdf5 object in this object. + void* Reference(const char* name) const; + + // Creates a reference to a named Hdf5 object or to a dataset region + // in this object. + void* Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type = H5R_DATASET_REGION) const; + + // Retrieves the type of object that an object reference points to. + H5G_obj_t getObjType(void *ref, H5R_type_t ref_type) const; + + // Retrieves a dataspace with the region pointed to selected. + DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; + // for CommonFG to get the file id virtual hid_t getLocId() const; diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index 3140836..4056dc2 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -155,6 +155,80 @@ IdComponent::~IdComponent() { */ } +// +// Implementation for HDF5 Reference Interface +// + +//-------------------------------------------------------------------------- +// Function: IdComponent::p_reference (protected) +// Purpose Creates a reference to an HDF5 object or a dataset region. +// Parameters +// name - IN: Name of the object to be referenced +// dataspace - IN: Dataspace with selection +// ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION +// Return A reference +// Exception H5::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* IdComponent::p_reference(const char* name, hid_t space_id, H5R_type_t ref_type) const +{ + void *ref; + herr_t ret_value = H5Rcreate(ref, id, name, ref_type, space_id); + if (ret_value < 0) + { + throw IdComponentException("IdComponent::p_reference", + "H5Rcreate failed"); + } + return(ref); +} + +//-------------------------------------------------------------------------- +// Function: IdComponent::p_get_obj_type (protected) +// Purpose Retrieves the type of object that an object reference points to. +// Parameters +// ref - IN: Reference to query +// ref_type - IN: Type of reference to query +// Return An object type, which can be one of the following: +// H5G_LINK Object is a symbolic link. +// H5G_GROUP Object is a group. +// H5G_DATASET Object is a dataset. +// H5G_TYPE Object is a named datatype +// Exception H5::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5G_obj_t IdComponent::p_get_obj_type(void *ref, H5R_type_t ref_type) const +{ + H5G_obj_t obj_type = H5Rget_obj_type(id, ref_type, ref); + if (obj_type == H5G_UNKNOWN) + { + throw IdComponentException("IdComponent::p_get_obj_type", + "H5R_get_obj_type failed"); + } + return(obj_type); +} + +//-------------------------------------------------------------------------- +// Function: IdComponent::p_get_region (protected) +// Purpose Retrieves a dataspace with the region pointed to selected. +// Parameters +// ref_type - IN: Type of reference to get region of - default +// to H5R_DATASET_REGION +// ref - IN: Reference to get region of +// Return Dataspace id +// Exception H5::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +hid_t IdComponent::p_get_region(void *ref, H5R_type_t ref_type) const +{ + hid_t space_id = H5Rget_region(id, ref_type, ref); + if (space_id < 0) + { + throw IdComponentException("IdComponent::p_get_region", + "H5Rget_region failed"); + } + return(space_id); +} + #ifndef H5_NO_NAMESPACE } #endif diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h index 85dc83f..81e95ac 100644 --- a/c++/src/H5IdComponent.h +++ b/c++/src/H5IdComponent.h @@ -58,9 +58,6 @@ class H5_DLLCPP IdComponent { // Assignment operator IdComponent& operator=( const IdComponent& rhs ); - // Resets this IdComponent instance - //template - //void reset( Type* parent ); void reset(); void resetId(); @@ -75,35 +72,17 @@ class H5_DLLCPP IdComponent { // Default constructor IdComponent(); + // Creates a reference to an HDF5 object or a dataset region. + void* p_reference(const char* name, hid_t space_id, H5R_type_t ref_type) const; + + // Retrieves the type of object that an object reference points to. + H5G_obj_t p_get_obj_type(void *ref, H5R_type_t ref_type) const; + + // Retrieves a dataspace with the region pointed to selected. + hid_t p_get_region(void *ref, H5R_type_t ref_type) const; + }; // end class IdComponent -// BMR - including template member function implementation here to -// prevent compilation errors. When the compilers support template -// member functions in *.C files, move them to IdComponent.C. - -// This function makes sure that this IdComponent instance actually -// represents an HDF5 component and that this HDF5 component is no longer -// referenced, then calls the parent function p_close to close the -// appropriate HDF5 component. In addition, this identifier instance -// will delete itself. -// Type is the class of the instance to whom this IdComponent object -// belongs. -/* 11/10/00 - BMR: commented this member function because many compilers - still have no support for member template function. The function is - replaced by resetIdComponent in H5Idtemplates.h -template -void IdComponent::reset( Type* parent ) -{ - if( ref_count->noReference()) // ref_count is decremented here - { - if( id > 0 ) - parent->p_close(); // which p_close depends on whom this - // IdComponent object belongs to - delete ref_count; // delete the reference counter - delete this; // this IdComponent object deletes itself - } -} -*/ #ifndef H5_NO_NAMESPACE } #endif -- cgit v0.12