diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2008-07-02 14:56:42 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2008-07-02 14:56:42 (GMT) |
commit | e5df9bb33aa8b88bd0df21479942c1156ffd52aa (patch) | |
tree | 48c4dc2f0e08512addab592c0306fa57ded0898a /c++/src/H5IdComponent.cpp | |
parent | d9533d055c7f306e66e5f972068c77c939d6fc16 (diff) | |
download | hdf5-e5df9bb33aa8b88bd0df21479942c1156ffd52aa.zip hdf5-e5df9bb33aa8b88bd0df21479942c1156ffd52aa.tar.gz hdf5-e5df9bb33aa8b88bd0df21479942c1156ffd52aa.tar.bz2 |
[svn-r15309] Purpose: Fixed bugs
Description:
The class hierarchy was revised to address the problem reported in
bugzilla #1068. Classes AbstractDS and Attribute are moved out of
H5Object. Class Attribute now multiply inherits from IdComponent and
AbstractDs and class DataSet from H5Object and AbstractDs.
In addition, data member IdComponent::id was moved into subclasses:
Attribute, DataSet, DataSpace, DataType, H5File, Group, and PropList.
Platforms tested:
SunOS 5.10 (linew)
Linux 2.6 (kagiso)
FreeBSD (duty)
Diffstat (limited to 'c++/src/H5IdComponent.cpp')
-rw-r--r-- | c++/src/H5IdComponent.cpp | 200 |
1 files changed, 38 insertions, 162 deletions
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index bb015fb..fa2f3db 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -18,7 +18,6 @@ #endif /*H5_VMS*/ #include <string> - #include "H5Include.h" #include "H5Exception.h" #include "H5Library.h" @@ -36,7 +35,7 @@ namespace H5 { ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -IdComponent::IdComponent(const hid_t h5_id) : id(h5_id) {} +IdComponent::IdComponent(const hid_t h5_id) {} //-------------------------------------------------------------------------- // Function: IdComponent copy constructor @@ -44,11 +43,7 @@ IdComponent::IdComponent(const hid_t h5_id) : id(h5_id) {} ///\param original - IN: IdComponent instance to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -IdComponent::IdComponent( const IdComponent& original ) -{ - id = original.id; - incRefCount(); // increment number of references to this id -} +IdComponent::IdComponent( const IdComponent& original ) {} //-------------------------------------------------------------------------- // Function: IdComponent::incRefCount @@ -69,7 +64,7 @@ void IdComponent::incRefCount(const hid_t obj_id) const //-------------------------------------------------------------------------- void IdComponent::incRefCount() const { - incRefCount(id); + incRefCount(getId()); } //-------------------------------------------------------------------------- @@ -99,7 +94,7 @@ void IdComponent::decRefCount(const hid_t obj_id) const //-------------------------------------------------------------------------- void IdComponent::decRefCount() const { - decRefCount(id); + decRefCount(getId()); } //-------------------------------------------------------------------------- @@ -128,7 +123,7 @@ int IdComponent::getCounter(const hid_t obj_id) const //-------------------------------------------------------------------------- int IdComponent::getCounter() const { - return (getCounter(id)); + return (getCounter(getId())); } //-------------------------------------------------------------------------- @@ -173,7 +168,7 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs ) if (this != &rhs) { // handling references to this id - try { + try { close(); } catch (Exception close_error) { @@ -181,10 +176,9 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs ) } // copy the data members from the rhs object - id = rhs.id; - - // increment the reference counter - incRefCount(); + setId(rhs.getId()); + /* id = rhs.id; + */ } return *this; } @@ -201,6 +195,7 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs ) // Then the object's id is reset to the new id. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- +#if 0 void IdComponent::setId(const hid_t new_id) { // handling references to this old id @@ -212,11 +207,14 @@ void IdComponent::setId(const hid_t new_id) } // reset object's id to the given id - id = new_id; + /* id = new_id; + */ + setId(new_id); // increment the reference counter of the new id incRefCount(); } +#endif //-------------------------------------------------------------------------- // Function: IdComponent::getId @@ -224,10 +222,12 @@ void IdComponent::setId(const hid_t new_id) ///\return HDF5 id // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- +/* hid_t IdComponent::getId () const { return(id); } +*/ //-------------------------------------------------------------------------- // Function: IdComponent destructor @@ -273,7 +273,10 @@ H5std_string IdComponent::inMemFunc(const char* func_name) const ///\brief Default constructor. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -IdComponent::IdComponent() : id(-1) {} +IdComponent::IdComponent() { + /* setId(-1); + */ +} //-------------------------------------------------------------------------- // Function: IdComponent::p_get_file_name (protected) @@ -287,8 +290,10 @@ IdComponent::IdComponent() : id(-1) {} //-------------------------------------------------------------------------- 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(id, NULL, 0); + ssize_t name_size = H5Fget_name(temp_id, NULL, 0); // If H5Aget_name returns a negative value, raise an exception, if( name_size < 0 ) @@ -298,7 +303,7 @@ H5std_string IdComponent::p_get_file_name() const // Call H5Fget_name again to get the actual file name char* name_C = new char[name_size+1]; // temporary C-string for C API - name_size = H5Fget_name(id, name_C, name_size+1); + name_size = H5Fget_name(temp_id, name_C, name_size+1); // Check for failure again if( name_size < 0 ) @@ -313,83 +318,21 @@ H5std_string IdComponent::p_get_file_name() const } //-------------------------------------------------------------------------- -// Function: IdComponent::p_reference (protected) -// Purpose Creates a reference to an HDF5 object or a dataset region. +// Function: H5Object::p_dereference (protected) +// Purpose Opens the HDF5 object referenced. // 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 +// ref - IN: Reference pointer +// Exception H5::IdComponentException +// Programmer Binh-Minh Ribler - Oct, 2006 //-------------------------------------------------------------------------- -void IdComponent::p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const +hid_t IdComponent::p_dereference(void* ref) { - herr_t ret_value = H5Rcreate(ref, id, name, ref_type, space_id); - if (ret_value < 0) + hid_t temp_id = H5Rdereference(getId(), H5R_OBJECT, ref); + if (temp_id < 0) { - throw IdComponentException("", "H5Rcreate failed"); + throw ReferenceException("", "H5Rdereference failed"); } -} - -//-------------------------------------------------------------------------- -// Function: IdComponent::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 \tReference is an object reference. -/// \li \c H5R_DATASET_REGION \tReference is a dataset region -/// reference. - this is the default -///\exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void IdComponent::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("IdComponent::reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: IdComponent::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 IdComponent::reference(void* ref, const char* name) const -{ - try { - p_reference(ref, name, -1, H5R_OBJECT); - } - catch (IdComponentException E) { - throw IdComponentException("IdComponent::reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: IdComponent::reference -///\brief This is an overloaded function, provided for your convenience. -/// It differs from the above function in that it takes an -/// \c std::string for the object's name. -///\param ref - IN: Reference pointer -///\param name - IN: Name of the object to be referenced - \c std::string -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void IdComponent::reference(void* ref, const H5std_string& name) const -{ - reference(ref, name.c_str()); + return(temp_id); } //-------------------------------------------------------------------------- @@ -406,84 +349,17 @@ void IdComponent::reference(void* ref, const H5std_string& name) const // BMR - Oct 8, 2006 // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- -void* IdComponent::p_reference(const char* name, hid_t space_id, H5R_type_t ref_type) const + /* void* IdComponent::p_reference(const char* name, hid_t space_id, H5R_type_t ref_type) const { hobj_ref_t ref; - herr_t ret_value = H5Rcreate(&ref, id, name, ref_type, space_id); + herr_t ret_value = H5Rcreate(&ref, getId(), name, ref_type, space_id); if (ret_value < 0) { throw IdComponentException("", "H5Rcreate failed"); } return (reinterpret_cast<void*>(ref)); } - -//-------------------------------------------------------------------------- -// Function: IdComponent::dereference -// Purpose Opens the HDF5 object referenced. -// Parameters -// obj - IN: Dataset reference object is in or location of -// object that the dataset is located within. -// ref - IN: Reference pointer -// Exception H5::IdComponentException -// Programmer Binh-Minh Ribler - Oct, 2006 -//-------------------------------------------------------------------------- -void IdComponent::dereference(IdComponent& obj, void* ref) -{ - id = H5Rdereference(obj.getId(), H5R_OBJECT, ref); - if (id < 0) - { - throw IdComponentException("", "H5Rdereference failed"); - } -} - -#ifndef H5_NO_DEPRECATED_SYMBOLS -//-------------------------------------------------------------------------- -// 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_type1(id, ref_type, ref); - - if (obj_type == H5G_UNKNOWN) - { - throw IdComponentException("", "H5Rget_obj_type failed"); - } - return(obj_type); -} -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - -//-------------------------------------------------------------------------- -// 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("", "H5Rget_region failed"); - } - return(space_id); -} - + */ // // Local functions used in this class // @@ -495,7 +371,7 @@ hid_t IdComponent::p_get_region(void *ref, H5R_type_t ref_type) const // Return true if id is valid, false, otherwise // Programmer Binh-Minh Ribler - May, 2005 //-------------------------------------------------------------------------- -bool IdComponent::p_valid_id(const hid_t obj_id) const +bool IdComponent::p_valid_id(const hid_t obj_id) { H5I_type_t id_type = H5Iget_type(obj_id); if (id_type <= H5I_BADID || id_type >= H5I_NTYPES) |