summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2010-05-10 01:04:50 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2010-05-10 01:04:50 (GMT)
commit9e595dec197d2812b13c4b86cf3389549c54fbb5 (patch)
tree1ffd9af7a5b781e4cf673f7c773bbacb9af5102e /c++
parent4bebb65cc961fd417ac645f0f0fa10ec2917a7cf (diff)
downloadhdf5-9e595dec197d2812b13c4b86cf3389549c54fbb5.zip
hdf5-9e595dec197d2812b13c4b86cf3389549c54fbb5.tar.gz
hdf5-9e595dec197d2812b13c4b86cf3389549c54fbb5.tar.bz2
[svn-r18749] Purpose: Fixed bugs 1852 & 1599
Description: - When a property class id is given to PropList(id), create new prop list, but when a property list id is given, make a copy of it. - Fixed operator= to use setId() properly. Platforms tested: Linux/32 2.6 (jam) FreeBSD/64 6.3 (liberty) SunOS 5.10 (linew)
Diffstat (limited to 'c++')
-rw-r--r--c++/src/H5IdComponent.cpp18
-rw-r--r--c++/src/H5PropList.cpp44
2 files changed, 34 insertions, 28 deletions
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp
index 2ee62ee..8124ab0 100644
--- a/c++/src/H5IdComponent.cpp
+++ b/c++/src/H5IdComponent.cpp
@@ -161,6 +161,10 @@ H5I_type_t IdComponent::getHDFObjType(const hid_t obj_id)
// copy the id from rhs to this object, and increment the
// reference counter of the id to indicate that another object
// is referencing that id.
+// Modification
+// 2010/5/9 - BMR
+// Removed close() and incRefCount() because setId/p_setId takes
+// care of close() and setId takes care incRefCount().
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
IdComponent& IdComponent::operator=( const IdComponent& rhs )
@@ -169,16 +173,13 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs )
{
// handling references to this id
try {
- close();
+ setId(rhs.getId());
+ // Note: a = b, so there are two objects with the same hdf5 id
+ // that's why incRefCount is needed, and it is called by setId
}
catch (Exception close_error) {
throw FileIException(inMemFunc("operator="), close_error.getDetailMsg());
}
-
- // copy the data members from the rhs object
- setId(rhs.getId());
-// incRefCount(getId()); // a = b, so there are two objects with the same
- // hdf5 id
}
return *this;
}
@@ -190,9 +191,8 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs )
///\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.
+// p_setId ensures that the current valid id of this object is
+// properly closed before resetting the object's id to the new id.
// Programmer Binh-Minh Ribler - 2000
// Modification
// 2008/7/23 - BMR
diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp
index 6706a01..1ed5916 100644
--- a/c++/src/H5PropList.cpp
+++ b/c++/src/H5PropList.cpp
@@ -66,29 +66,35 @@ PropList::PropList(const PropList& original) : IdComponent(original)
///\param plist_id - IN: Id of the existing property list
///\exception H5::PropListIException
// Description
-// This function calls H5Pcreate to create a new property list
-// if the given id, plist_id, is that of a property class. If
-// the given id is equal to H5P_ROOT, then set this
-// property's id to H5P_DEFAULT, otherwise, to the given id.
-// Note: someone else added this code without comments and this
-// description was what I came up with from reading the code.
+// This function creates a new property list if a property
+// class is provided or makes a copy of a property list if one
+// is given. If the given id is anything else, then set this
+// property's id to H5P_DEFAULT.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
PropList::PropList( const hid_t plist_id ) : IdComponent()
{
- if (H5I_GENPROP_CLS == H5Iget_type(plist_id)) {
- // call C routine to create the new property
- id = H5Pcreate(plist_id);
- if( id < 0 )
- {
- throw PropListIException("PropList constructor", "H5Pcreate failed");
- }
- }
- else {
- if(plist_id==H5P_ROOT)
- id=H5P_DEFAULT;
- else
- id=plist_id;
+ H5I_type_t id_type = H5Iget_type(plist_id);
+ switch (id_type) {
+ case H5I_GENPROP_CLS:
+ // call C routine to create a new property from the given prop class
+ id = H5Pcreate(plist_id);
+ if( id < 0 )
+ {
+ throw PropListIException("PropList constructor", "H5Pcreate failed");
+ }
+ break;
+ case H5I_GENPROP_LST:
+ // call C routine to make a copy of the given property list
+ id = H5Pcopy(plist_id);
+ if( id < 0 )
+ {
+ throw PropListIException("PropList constructor", "H5Pcopy failed");
+ }
+ break;
+ default:
+ id = H5P_DEFAULT;
+ break;
}
}