diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2008-05-20 20:24:44 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2008-05-20 20:24:44 (GMT) |
commit | 988e907b113c992cd2878705a5b98b499a4ccf41 (patch) | |
tree | 31b669eff3d8afade2cc50fa621d5559bb4c945c /c++/src/H5PropList.cpp | |
parent | 980d1837908aa700efcf7edc0be62a9fc207c6ed (diff) | |
download | hdf5-988e907b113c992cd2878705a5b98b499a4ccf41.zip hdf5-988e907b113c992cd2878705a5b98b499a4ccf41.tar.gz hdf5-988e907b113c992cd2878705a5b98b499a4ccf41.tar.bz2 |
[svn-r15046] 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.
Also fixed bugzilla 1045: revised Attribute::write and Attribute::read
wrappers to handle memory allocation/deallocation properly. (bugzilla 1045)
Platforms tested:
SunOS 5.10 (linew)
Linux 2.6 (kagiso)
FreeBSD (duty)
Diffstat (limited to 'c++/src/H5PropList.cpp')
-rw-r--r-- | c++/src/H5PropList.cpp | 87 |
1 files changed, 68 insertions, 19 deletions
diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp index 136fb3b..64c1743 100644 --- a/c++/src/H5PropList.cpp +++ b/c++/src/H5PropList.cpp @@ -25,6 +25,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5private.h" // for HDfree #ifndef H5_NO_NAMESPACE namespace H5 { @@ -44,7 +45,7 @@ const PropList PropList::DEFAULT( H5P_DEFAULT ); ///\brief Default constructor: creates a stub property list object. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -PropList::PropList() : IdComponent( 0 ) {} +PropList::PropList() : IdComponent(), id(0) {} //-------------------------------------------------------------------------- // Function: PropList copy constructor @@ -52,7 +53,11 @@ PropList::PropList() : IdComponent( 0 ) {} ///\param original - IN: The original property list to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -PropList::PropList( const PropList& original ) : IdComponent( original ) {} +PropList::PropList(const PropList& original) : IdComponent(original) +{ + id = original.getId(); + incRefCount(); // increment number of references to this id +} //-------------------------------------------------------------------------- // Function: PropList overloaded constructor @@ -68,7 +73,7 @@ PropList::PropList( const PropList& original ) : IdComponent( original ) {} // description was what I came up with from reading the code. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -PropList::PropList( const hid_t plist_id ) : IdComponent(0) +PropList::PropList( const hid_t plist_id ) : IdComponent() { if (H5I_GENPROP_CLS == H5Iget_type(plist_id)) { // call C routine to create the new property @@ -157,7 +162,7 @@ void PropList::copyProp(PropList& dest, const char *name) const /// It differs from the above function only in what arguments it /// accepts. ///\param dest - IN: Destination property list or class -///\param name - IN: Name of the property to copy - \c std::string +///\param name - IN: Name of the property to copy - \c H5std_string // Programmer Binh-Minh Ribler - Jul, 2005 //-------------------------------------------------------------------------- void PropList::copyProp( PropList& dest, const H5std_string& name ) const @@ -194,7 +199,7 @@ void PropList::copyProp( PropList& dest, PropList& src, const char *name ) const /// accepts. - Obsolete ///\param dest - IN: Destination property list or class ///\param src - IN: Source property list or class -///\param name - IN: Name of the property to copy - \c std::string +///\param name - IN: Name of the property to copy - \c H5std_string // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void PropList::copyProp( PropList& dest, PropList& src, const H5std_string& name ) const @@ -203,6 +208,49 @@ void PropList::copyProp( PropList& dest, PropList& src, const H5std_string& name } //-------------------------------------------------------------------------- +// Function: PropList::getId +// Purpose: Get the id of this attribute +// Description: +// Class hierarchy is revised to address bugzilla 1068. Class +// AbstractDS and Attribute are moved out of H5Object. In +// addition, member IdComponent::id is moved into subclasses, and +// IdComponent::getId now becomes pure virtual function. +// Programmer Binh-Minh Ribler - May, 2008 +//-------------------------------------------------------------------------- +hid_t PropList::getId() const +{ + return(id); +} + +//-------------------------------------------------------------------------- +// Function: PropList::setId +///\brief Sets the identifier of this object to a new value. +/// +///\exception H5::IdComponentException when the attempt to close the HDF5 +/// object fails +// Description: +// The underlaying reference counting in the C library ensures +// that the current valid id of this object is properly closed. +// Then the object's id is reset to the new id. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +void PropList::setId(const hid_t new_id) +{ + // handling references to this old id + try { + close(); + } + catch (Exception close_error) { + throw PropListIException(inMemFunc("setId"), close_error.getDetailMsg()); + } + // reset object's id to the given id + id = new_id; + + // increment the reference counter of the new id + incRefCount(); +} + +//-------------------------------------------------------------------------- // Function: PropList::close ///\brief Closes the property list if it is not a default one. /// @@ -273,7 +321,7 @@ bool PropList::propExist(const char* name ) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function only in what arguments it /// accepts. -///\param name - IN: Name of property to check for - \c std::string +///\param name - IN: Name of property to check for - \c H5std_string // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- bool PropList::propExist(const H5std_string& name ) const @@ -326,7 +374,7 @@ void PropList::getProperty(const char* name, void* value) const /// It differs from the above function only in what arguments it /// accepts. ///\param name - IN: Name of property to query - \c char pointer -///\return The property that is a \c std::string. +///\return The property that is a \c H5std_string. ///\exception H5::PropListIException // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- @@ -343,7 +391,7 @@ H5std_string PropList::getProperty(const char* name) const } // Return propety value as a string after deleting temp C-string - H5std_string prop_strg = H5std_string(prop_strg_C); + H5std_string prop_strg(prop_strg_C); delete []prop_strg_C; return (prop_strg); } @@ -352,7 +400,7 @@ H5std_string PropList::getProperty(const char* name) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function only in what arguments it /// accepts. -///\param name - IN: Name of property to query - \c std::string +///\param name - IN: Name of property to query - \c H5std_string ///\param value - OUT: Pointer to the buffer for the property value // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- @@ -365,8 +413,8 @@ void PropList::getProperty(const H5std_string& name, void* value) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function only in what arguments it /// accepts. -///\param name - IN: Name of property to query - \c std::string -///\return The property that is a \c std::string. +///\param name - IN: Name of property to query - \c H5std_string +///\return The property that is a \c H5std_string. // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- H5std_string PropList::getProperty(const H5std_string& name) const @@ -402,7 +450,7 @@ size_t PropList::getPropSize(const char *name) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function only in what arguments it /// accepts. -///\param name - IN: Name of property to query - \c std::string +///\param name - IN: Name of property to query - \c H5std_string /// // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- @@ -421,12 +469,13 @@ size_t PropList::getPropSize(const H5std_string& name) const H5std_string PropList::getClassName() const { char* temp_str; - temp_str = H5Pget_class_name(id); + temp_str = H5Pget_class_name(id); // this API specified that temp_str must + // be freed. if (temp_str != NULL) { - H5std_string class_name = H5std_string(temp_str); - free(temp_str); + H5std_string class_name(temp_str); + HDfree(temp_str); return(class_name); } else @@ -489,7 +538,7 @@ void PropList::setProperty(const char* name, const char* charptr) const /// It differs from the above function only in what arguments it /// accepts. ///\param name - IN: Name of property to set - \c char pointer -///\param strg - IN: Value for the property is a \c std::string +///\param strg - IN: Value for the property is a \c H5std_string // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- void PropList::setProperty(const char* name, H5std_string& strg) const @@ -502,7 +551,7 @@ void PropList::setProperty(const char* name, H5std_string& strg) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function only in what arguments it /// accepts. -///\param name - IN: Name of property to set - \c std::string +///\param name - IN: Name of property to set - \c H5std_string ///\param value - IN: Void pointer to the value for the property // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- @@ -516,7 +565,7 @@ void PropList::setProperty(const H5std_string& name, void* value) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function only in what arguments it /// accepts. -///\param name - IN: Name of property to set - \c std::string +///\param name - IN: Name of property to set - \c H5std_string ///\param strg - IN: Value for the property is a \c std::string // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- @@ -569,7 +618,7 @@ void PropList::removeProp(const char *name) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function only in what arguments it /// accepts. -///\param name - IN: Name of property to remove - \c std::string +///\param name - IN: Name of property to remove - \c H5std_string // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- void PropList::removeProp(const H5std_string& name) const |