//-------------------------------------------------------------------------- // Function: IdComponent::p_get_file_name (protected) // Purpose Gets the name of the file, in which this object belongs. // Exception: H5::IdComponentException // Description: // This function is protected so that the user applications can // only have access to its code via H5Location subclasses. // September 2017 // This function should be moved to H5Location now that Attribute // inherits from H5Location. // Programmer Binh-Minh Ribler - Jul, 2004 //-------------------------------------------------------------------------- H5std_string IdComponent::p_get_file_name() const { hid_t temp_id = getId(); // Preliminary call to H5Fget_name to get the length of the file name ssize_t name_size = H5Fget_name(temp_id, NULL, 0); // If H5Aget_name returns a negative value, raise an exception, if (name_size < 0) { throw IdComponentException("", "H5Fget_name failed"); } // Call H5Fget_name again to get the actual file name char* name_C = new char[name_size+1]; // temporary C-string for C API HDmemset(name_C, 0, name_size+1); // clear buffer name_size = H5Fget_name(temp_id, name_C, name_size+1); // Check for failure again if (name_size < 0) { delete []name_C; throw IdComponentException("", "H5Fget_name failed"); } // Convert the C file name and return H5std_string file_name(name_C); delete []name_C; return(file_name); }
//-------------------------------------------------------------------------- // Function: Exception::getMajorString ///\brief Returns a text string that describes the error /// specified by a major error number. ///\param err_major - IN: Major error number ///\return Major error string ///\par Description /// In the failure case, the string "Invalid major error number" /// will be returned. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5std_string Exception::getMajorString( hid_t err_major ) const { // Preliminary call to H5Eget_msg() to get the length of the message ssize_t mesg_size = H5Eget_msg(err_major, NULL, NULL, 0); // If H5Eget_msg() returns a negative value, raise an exception, if( mesg_size < 0 ) throw IdComponentException("Exception::getMajorString", "H5Eget_msg failed"); // Call H5Eget_msg again to get the actual message char* mesg_C = new char[mesg_size+1]; // temporary C-string for C API mesg_size = H5Eget_msg(err_major, NULL, mesg_C, mesg_size+1); // Check for failure again if( mesg_size < 0 ) { delete []mesg_C; throw IdComponentException("Exception::getMajorString", "H5Eget_msg failed"); } // Convert the C error description and return H5std_string major_str(mesg_C); delete []mesg_C; return( major_str ); }
//-------------------------------------------------------------------------- // Function: IdComponent::decRefCount ///\brief Decrement reference counter for a given id. // Programmer Binh-Minh Ribler - May 2005 // Modification: // Added the check for ref counter to give a little more info // on why H5Idec_ref fails in some cases - BMR 5/19/2005 //-------------------------------------------------------------------------- void IdComponent::decRefCount(const hid_t obj_id) const { if (p_valid_id(obj_id)) if (H5Idec_ref(obj_id) < 0) if (H5Iget_ref(obj_id) <= 0) throw IdComponentException(inMemFunc("decRefCount"), "object ref count is 0 or negative"); else throw IdComponentException(inMemFunc("decRefCount"), "decrementing object ref count failed"); }
//-------------------------------------------------------------------------- // Function: H5Object::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 // Exception H5::IdComponentException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- void H5Object::p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const { herr_t ret_value = H5Rcreate(ref, getId(), name, ref_type, space_id); if (ret_value < 0) { throw IdComponentException("", "H5Rcreate failed"); } }
//-------------------------------------------------------------------------- // Function: H5Object::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 H5Object::p_get_region(void *ref, H5R_type_t ref_type) const { hid_t space_id = H5Rget_region(getId(), ref_type, ref); if (space_id < 0) { throw IdComponentException("", "H5Rget_region failed"); } return(space_id); }
//-------------------------------------------------------------------------- // Function: H5Object::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 ref - IN: Reference pointer ///\param name - IN: Name of the object to be referenced - \c char pointer ///\exception H5::IdComponentException ///\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 H5Object::reference(void* ref, const char* name) const { try { p_reference(ref, name, -1, H5R_OBJECT); } catch (IdComponentException E) { throw IdComponentException("H5Object::reference", E.getDetailMsg()); } }
//-------------------------------------------------------------------------- // Function: H5Object::reference ///\brief Creates a reference to an HDF5 object or a dataset region. ///\param ref - IN: Reference pointer ///\param name - IN: Name of the object to be referenced ///\param dataspace - IN: Dataspace with selection ///\param ref_type - IN: Type of reference to query, valid values are: /// \li \c H5R_OBJECT - Reference is an object reference. /// \li \c H5R_DATASET_REGION - Reference is a dataset region /// reference. - this is the default ///\exception H5::IdComponentException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- void H5Object::reference(void* ref, const char* name, const DataSpace& dataspace, H5R_type_t ref_type) const { try { p_reference(ref, name, dataspace.getId(), ref_type); } catch (IdComponentException E) { throw IdComponentException("H5Object::reference", E.getDetailMsg()); } }
//-------------------------------------------------------------------------- // Function: getNumMembers (static) ///\brief Returns the number of members of the given type. ///\return Number of members ///\par Description /// If there is no member of the given type, getNumMembers will /// return 0. Valid types are: /// \li \c H5I_FILE (= 1) /// \li \c H5I_GROUP /// \li \c H5I_DATATYPE /// \li \c H5I_DATASPACE /// \li \c H5I_DATASET /// \li \c H5I_ATTR /// \li \c H5I_VFL /// \li \c H5I_VOL /// \li \c H5I_GENPROP_CLS /// \li \c H5I_GENPROP_LST /// \li \c H5I_ERROR_CLASS /// \li \c H5I_ERROR_MSG /// \li \c H5I_ERROR_STACK // Programmer Binh-Minh Ribler - Feb, 2017 //-------------------------------------------------------------------------- hsize_t IdComponent::getNumMembers(H5I_type_t type) { hsize_t nmembers = 0; herr_t ret_value = H5Inmembers(type, &nmembers); if (ret_value < 0) throw IdComponentException("getNumMembers", "H5Inmembers failed"); else return(nmembers); }
//-------------------------------------------------------------------------- // Function: H5Object::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 H5Object::p_get_obj_type(void *ref, H5R_type_t ref_type) const { H5G_obj_t obj_type = H5Rget_obj_type1(getId(), ref_type, ref); if (obj_type == H5G_UNKNOWN) { throw IdComponentException("", "H5Rget_obj_type failed"); } return(obj_type); }
//-------------------------------------------------------------------------- // Function: IdComponent::getCounter ///\brief Returns the reference counter for a given id. ///\return Reference count // Programmer Binh-Minh Ribler - May 2005 //-------------------------------------------------------------------------- int IdComponent::getCounter(const hid_t obj_id) const { int counter = 0; if (p_valid_id(obj_id)) { counter = H5Iget_ref(obj_id); if (counter < 0) throw IdComponentException(inMemFunc("incRefCount"), "getting object ref count failed - negative"); } return (counter); }
//-------------------------------------------------------------------------- // Function: typeExists (static) ///\brief Queries if a given type is currently registered with the /// library. ///\return true if the given type exists, and false, otherwise. ///\par Description /// Valid types are: /// \li \c H5I_FILE (= 1) /// \li \c H5I_GROUP /// \li \c H5I_DATATYPE /// \li \c H5I_DATASPACE /// \li \c H5I_DATASET /// \li \c H5I_ATTR /// \li \c H5I_VFL /// \li \c H5I_VOL /// \li \c H5I_GENPROP_CLS /// \li \c H5I_GENPROP_LST /// \li \c H5I_ERROR_CLASS /// \li \c H5I_ERROR_MSG /// \li \c H5I_ERROR_STACK // Programmer Binh-Minh Ribler - Feb, 2017 //-------------------------------------------------------------------------- bool IdComponent::typeExists(H5I_type_t type) { // Call C function htri_t ret_value = H5Itype_exists(type); if (ret_value > 0) return true; else if (ret_value == 0) return false; else // Raise exception when H5Itype_exists returns a negative value throw IdComponentException("typeExists", "H5Itype_exists failed"); }
//-------------------------------------------------------------------------- // Function: isValid (static) ///\brief Checks if the given ID is valid. ///\return true if the given identifier is valid, and false, otherwise. ///\par Description /// A valid ID is one that is in use and has an application /// reference count of at least 1. // Programmer Binh-Minh Ribler - Mar 1, 2017 //-------------------------------------------------------------------------- bool IdComponent::isValid(hid_t an_id) { // Call C function htri_t ret_value = H5Iis_valid(an_id); if (ret_value > 0) return true; else if (ret_value == 0) return false; else // Raise exception when H5Iis_valid returns a negative value throw IdComponentException("isValid", "H5Iis_valid failed"); }
//-------------------------------------------------------------------------- // Function: IdComponent::incRefCount ///\brief Increment reference counter for a given id. // Programmer Binh-Minh Ribler - May 2005 //-------------------------------------------------------------------------- void IdComponent::incRefCount(const hid_t obj_id) const { if (p_valid_id(obj_id)) if (H5Iinc_ref(obj_id) < 0) throw IdComponentException(inMemFunc("incRefCount"), "incrementing object ref count failed"); }