summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2005-02-20 22:07:55 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2005-02-20 22:07:55 (GMT)
commitab0253507459c6b163fad1c5039f54bdb3fa3f5c (patch)
treef049cd04f8cf6f29e83682939562003f9487abb9 /c++
parentb362c692dc09558ce93b1d27aa59d4646201ad32 (diff)
downloadhdf5-ab0253507459c6b163fad1c5039f54bdb3fa3f5c.zip
hdf5-ab0253507459c6b163fad1c5039f54bdb3fa3f5c.tar.gz
hdf5-ab0253507459c6b163fad1c5039f54bdb3fa3f5c.tar.bz2
[svn-r10051] Purpose: Fix bugzilla #242
Description: In the release branch, RefCounter was still used for maintaining the reference count and there was a memory leak problem (bug 242) which is not a simple fix. Solution: Removed this reference counting approach completely and started using the C library's new APIs for that purpose. Platforms tested: Linux 2.4 (heping) SunOS 5.8 64-bit (sol)
Diffstat (limited to 'c++')
-rw-r--r--c++/src/H5AbstractDs.cpp1
-rw-r--r--c++/src/H5ArrayType.cpp1
-rw-r--r--c++/src/H5AtomType.cpp1
-rw-r--r--c++/src/H5Attribute.cpp16
-rw-r--r--c++/src/H5CommonFG.cpp1
-rw-r--r--c++/src/H5CompType.cpp1
-rw-r--r--c++/src/H5Cpp.h1
-rw-r--r--c++/src/H5DataSet.cpp12
-rw-r--r--c++/src/H5DataSpace.cpp46
-rw-r--r--c++/src/H5DataType.cpp37
-rw-r--r--c++/src/H5DcreatProp.cpp1
-rw-r--r--c++/src/H5DxferProp.cpp1
-rw-r--r--c++/src/H5EnumType.cpp1
-rw-r--r--c++/src/H5FaccProp.cpp1
-rw-r--r--c++/src/H5FcreatProp.cpp1
-rw-r--r--c++/src/H5File.cpp30
-rw-r--r--c++/src/H5FloatType.cpp1
-rw-r--r--c++/src/H5Group.cpp11
-rw-r--r--c++/src/H5IdComponent.cpp116
-rw-r--r--c++/src/H5IdComponent.h2
-rw-r--r--c++/src/H5IntType.cpp1
-rw-r--r--c++/src/H5Object.cpp2
-rw-r--r--c++/src/H5PredType.cpp1
-rw-r--r--c++/src/H5PropList.cpp29
-rw-r--r--c++/src/H5RefCounter.cpp1
-rw-r--r--c++/src/H5StrType.cpp1
-rw-r--r--c++/src/H5VarLenType.cpp1
27 files changed, 138 insertions, 180 deletions
diff --git a/c++/src/H5AbstractDs.cpp b/c++/src/H5AbstractDs.cpp
index 7771c6a..33fadc5 100644
--- a/c++/src/H5AbstractDs.cpp
+++ b/c++/src/H5AbstractDs.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp
index 681b9c4..b580660 100644
--- a/c++/src/H5ArrayType.cpp
+++ b/c++/src/H5ArrayType.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5AtomType.cpp b/c++/src/H5AtomType.cpp
index fb4c81a..902d07c 100644
--- a/c++/src/H5AtomType.cpp
+++ b/c++/src/H5AtomType.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index 1b92a6f..a5d4964 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -21,9 +21,7 @@
#include "H5Include.h"
#include "H5Exception.h"
-#include "H5RefCounter.h"
#include "H5IdComponent.h"
-#include "H5Idtemplates.h"
#include "H5PropList.h"
#include "H5Object.h"
#include "H5AbstractDs.h"
@@ -282,15 +280,19 @@ void Attribute::p_close() const
// Function: Attribute destructor
///\brief Properly terminates access to this attribute.
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
Attribute::~Attribute()
{
// The attribute id will be closed properly
- try {
- resetIdComponent(this); }
- catch (Exception close_error) { // thrown by p_close
- cerr << "Attribute::~Attribute - " << close_error.getDetailMsg() << endl;
- }
+ try {
+ decRefCount();
+ }
+ catch (Exception close_error) {
+ cerr << "Attribute::~Attribute - " << close_error.getDetailMsg() << endl;
+ }
}
#ifndef H5_NO_NAMESPACE
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index 6d60c6d..05da7bd 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp
index e004ab9..738506e 100644
--- a/c++/src/H5CompType.cpp
+++ b/c++/src/H5CompType.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5Cpp.h b/c++/src/H5Cpp.h
index f11bbbd..e9f8585 100644
--- a/c++/src/H5Cpp.h
+++ b/c++/src/H5Cpp.h
@@ -17,7 +17,6 @@
#define _H5CPP_H
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5DataSpace.h"
diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp
index 6392767..2967183 100644
--- a/c++/src/H5DataSet.cpp
+++ b/c++/src/H5DataSet.cpp
@@ -20,10 +20,8 @@
#endif
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
-#include "H5Idtemplates.h"
#include "H5PropList.h"
#include "H5Object.h"
#include "H5PropList.h"
@@ -504,13 +502,17 @@ void DataSet::p_close() const
// Function: DataSet destructor
///\brief Properly terminates access to this dataset.
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
DataSet::~DataSet()
{
- // The dataset id will be closed properly
+ // The dataset id will be closed properly
try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
+ decRefCount();
+ }
+ catch (Exception close_error) {
cerr << "DataSet::~DataSet - " << close_error.getDetailMsg() << endl;
}
}
diff --git a/c++/src/H5DataSpace.cpp b/c++/src/H5DataSpace.cpp
index 1dc7b43..d13deed 100644
--- a/c++/src/H5DataSpace.cpp
+++ b/c++/src/H5DataSpace.cpp
@@ -20,10 +20,8 @@
#endif
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
-#include "H5Idtemplates.h"
#include "H5DataSpace.h"
#ifndef H5_NO_NAMESPACE
@@ -95,23 +93,26 @@ DataSpace::DataSpace( const DataSpace& original ) : IdComponent( original ) {}
///\param like_space - IN: Dataspace to be copied
///\exception H5::DataSpaceIException
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
void DataSpace::copy( const DataSpace& like_space )
{
- // reset the identifier of this object - send 'this' in so that
- // H5Sclose can be called appropriately
- try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
- throw DataSpaceIException("DataSpace::copy", close_error.getDetailMsg());
- }
+ // If this object has a valid id, appropriately decrement reference
+ // counter and close the id.
+ if( id != H5S_ALL ) {
+ try {
+ decRefCount();
+ }
+ catch (Exception close_error) {
+ throw DataSpaceIException("DataSpace::copy", close_error.getDetailMsg());
+ }
+ } // if
- // call C routine to copy the dataspace
+ // call C routine to copy the dataspace
id = H5Scopy( like_space.getId() );
- // new ref counter for this id
- ref_count = new RefCounter;
-
if( id <= 0 )
throw DataSpaceIException("DataSpace::copy", "H5Scopy failed");
}
@@ -564,15 +565,22 @@ void DataSpace::p_close() const
// Function: DataSpace destructor
///\brief Properly terminates access to this dataspace.
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
DataSpace::~DataSpace()
{
- // The dataspace id will be closed properly
- try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
- cerr << "DataSpace::~DataSpace - " << close_error.getDetailMsg() << endl;
- }
+ // If this object has a valid id, appropriately decrement reference
+ // counter and close the id.
+ if( id != H5S_ALL ) {
+ try {
+ decRefCount();
+ }
+ catch (Exception close_error) {
+ throw DataSpaceIException("DataSpace::copy", close_error.getDetailMsg());
+ }
+ } // if
}
#ifndef H5_NO_NAMESPACE
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp
index 8dcb7bd..3a26990 100644
--- a/c++/src/H5DataType.cpp
+++ b/c++/src/H5DataType.cpp
@@ -20,10 +20,8 @@
#endif
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
-#include "H5Idtemplates.h"
#include "H5PropList.h"
#include "H5DataSpace.h"
#include "H5Object.h"
@@ -96,23 +94,26 @@ DataType::DataType(const DataType& original) : H5Object(original)
///\param like_type - IN: Datatype to be copied
///\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
void DataType::copy( const DataType& like_type )
{
- // reset the identifier of this instance, H5Tclose will be called
- // if needed
- try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
- throw DataTypeIException("DataType::copy", close_error.getDetailMsg());
+ // reset the identifier of this instance, H5Tclose will be called
+ // if needed
+ if( is_predtype == false ) {
+ try {
+ decRefCount();
+ }
+ catch (Exception close_error) {
+ throw DataTypeIException("DataType::copy", close_error.getDetailMsg());
+ }
}
// call C routine to copy the datatype
id = H5Tcopy( like_type.getId() );
- // new reference counter for this id
- ref_count = new RefCounter;
-
if( id <= 0 )
throw DataTypeIException("DataType::copy", "H5Tcopy failed");
}
@@ -642,14 +643,20 @@ void DataType::p_close() const
// Function: DataType destructor
///\brief Properly terminates access to this datatype.
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
DataType::~DataType()
{
// The datatype id will be closed properly
- try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
- cerr << "DataType::~DataType - " << close_error.getDetailMsg() << endl;
+ if( is_predtype == false ) {
+ try {
+ decRefCount();
+ }
+ catch (Exception close_error) {
+ cerr << "DataType::~DataType - " << close_error.getDetailMsg() << endl;
+ }
}
}
diff --git a/c++/src/H5DcreatProp.cpp b/c++/src/H5DcreatProp.cpp
index c9a16ba..c468819 100644
--- a/c++/src/H5DcreatProp.cpp
+++ b/c++/src/H5DcreatProp.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5DxferProp.cpp b/c++/src/H5DxferProp.cpp
index f6f41a4..7ee347b 100644
--- a/c++/src/H5DxferProp.cpp
+++ b/c++/src/H5DxferProp.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5EnumType.cpp b/c++/src/H5EnumType.cpp
index f40ae06..2f04d1e 100644
--- a/c++/src/H5EnumType.cpp
+++ b/c++/src/H5EnumType.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5FaccProp.cpp b/c++/src/H5FaccProp.cpp
index 515e883..0c915c1 100644
--- a/c++/src/H5FaccProp.cpp
+++ b/c++/src/H5FaccProp.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5FcreatProp.cpp b/c++/src/H5FcreatProp.cpp
index ff8eb47..d023ca9 100644
--- a/c++/src/H5FcreatProp.cpp
+++ b/c++/src/H5FcreatProp.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp
index e4e9edd..670bfbe 100644
--- a/c++/src/H5File.cpp
+++ b/c++/src/H5File.cpp
@@ -20,10 +20,8 @@
#endif
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
-#include "H5Idtemplates.h"
#include "H5PropList.h"
#include "H5Object.h"
#include "H5FaccProp.h"
@@ -183,24 +181,28 @@ bool H5File::isHdf5(const string& name )
// If this object has represented another HDF5 file, the previous
// HDF5 file need to be closed first.
// Programmer Binh-Minh Ribler - 2000
+// Note: This wrapper doesn't seem right regarding the 'id' and should
+// be investigated. BMR - 2/20/2005
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
void H5File::reOpen()
{
- // reset the identifier of this H5File - send 'this' in so that
- // H5Fclose can be called appropriately
+ // If this object has a valid id, appropriately decrement reference
+ // counter and close the id.
try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
- throw FileIException("H5File::reopen", close_error.getDetailMsg());
+ decRefCount();
+ }
+ catch (Exception close_error) {
+ throw FileIException("H5File::reOpen", close_error.getDetailMsg());
}
// call C routine to reopen the file - Note: not sure about this
// does id need to be closed later? which id to be the parameter?
id = H5Freopen( id );
if( id <= 0 ) // Raise exception when H5Freopen returns a neg value
- {
- throw FileIException("H5File::reopen", "H5Freopen failed");
- }
+ throw FileIException("H5File::reOpen", "H5Freopen failed");
}
//--------------------------------------------------------------------------
@@ -574,13 +576,17 @@ void H5File::throwException(const string func_name, const string msg) const
// Function: H5File destructor
///\brief Properly terminates access to this file.
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
H5File::~H5File()
{
// The HDF5 file id will be closed properly
try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
+ decRefCount();
+ }
+ catch (Exception close_error) {
cerr << "H5File::~H5File - " << close_error.getDetailMsg() << endl;
}
}
diff --git a/c++/src/H5FloatType.cpp b/c++/src/H5FloatType.cpp
index 0401718..1912edb 100644
--- a/c++/src/H5FloatType.cpp
+++ b/c++/src/H5FloatType.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp
index 32a4478..2774f13 100644
--- a/c++/src/H5Group.cpp
+++ b/c++/src/H5Group.cpp
@@ -20,10 +20,8 @@
#endif
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
-#include "H5Idtemplates.h"
#include "H5PropList.h"
#include "H5Object.h"
#include "H5AbstractDs.h"
@@ -188,16 +186,19 @@ void Group::throwException(const string func_name, const string msg) const
// Function: Group destructor
///\brief Properly terminates access to this group.
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
Group::~Group()
{
// The group id will be closed properly
try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
+ decRefCount();
+ }
+ catch (Exception close_error) {
cerr << "Group::~Group - " << close_error.getDetailMsg() << endl;
}
-
}
#ifndef H5_NO_NAMESPACE
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp
index f7f8573..4d7841c 100644
--- a/c++/src/H5IdComponent.cpp
+++ b/c++/src/H5IdComponent.cpp
@@ -15,11 +15,9 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5Library.h"
#include "H5IdComponent.h"
-#include "H5Idtemplates.h"
#ifndef H5_NO_NAMESPACE
namespace H5 {
@@ -32,11 +30,7 @@ namespace H5 {
///\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-IdComponent::IdComponent( const hid_t h5_id ) : id( h5_id )
-{
- // starts counting object references
- ref_count = new RefCounter;
-}
+IdComponent::IdComponent(const hid_t h5_id) : id(h5_id) {}
//--------------------------------------------------------------------------
// Function: IdComponent copy constructor
@@ -47,8 +41,7 @@ IdComponent::IdComponent( const hid_t h5_id ) : id( h5_id )
IdComponent::IdComponent( const IdComponent& original )
{
id = original.id;
- ref_count = original.ref_count; // points to the same ref counter
- ref_count->increment(); // increment number of references to this id
+ H5Iinc_ref(id); // increment number of references to this id
}
//--------------------------------------------------------------------------
@@ -56,14 +49,19 @@ IdComponent::IdComponent( const IdComponent& original )
///\brief Increment id reference counter.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-void IdComponent::incRefCount() { ref_count->increment(); }
+void IdComponent::incRefCount() { H5Iinc_ref(id); }
//--------------------------------------------------------------------------
// Function: IdComponent::decRefCount
///\brief Decrement id reference counter.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-void IdComponent::decRefCount() { ref_count->decrement(); }
+void IdComponent::decRefCount()
+{
+ if(id>0)
+ if(H5Idec_ref(id)<0)
+ throw IdComponentException("IdComponent::decRefCount", "decrementing object ref count failed");
+}
//--------------------------------------------------------------------------
// Function: IdComponent::getCounter
@@ -71,24 +69,7 @@ void IdComponent::decRefCount() { ref_count->decrement(); }
///\return Reference count
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-int IdComponent::getCounter() { return( ref_count->getCounter()); }
-
-//--------------------------------------------------------------------------
-// Function: IdComponent::noReference
-///\brief Determines whether this object has any references.
-///\return \c true if there is no reference, and \c false, otherwise.
-///\note This function will be obsolete in the next release.
-// Description
-// Decrements the reference counter then determines if there
-// are no more reference to this object.
-// Programmer Binh-Minh Ribler - 2000
-//--------------------------------------------------------------------------
-bool IdComponent::noReference()
-{
- if( ref_count->getCounter() > 0 )
- ref_count->decrement();
- return( ref_count->getCounter() == 0 ? true:false );
-}
+int IdComponent::getCounter() { return( H5Iget_ref(id)); }
//--------------------------------------------------------------------------
// Function: IdComponent::operator=
@@ -98,28 +79,23 @@ bool IdComponent::noReference()
///\exception H5::IdComponentException when attempt to close the HDF5
/// object fails
// Description
-// Reset the identifier of this object so that the HDF5 id can
-// be properly closed. Copy the id from rhs to this object,
-// then increment the reference counter of the id to indicate
-// that another object is referencing it.
+// The underlaying reference counting in the C library ensures
+// that the current valid id of this object is properly closed.
+// Copy the id from rhs to this object, then increment the
+// reference counter of the id to indicate that another object
+// is referencing it.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
IdComponent& IdComponent::operator=( const IdComponent& rhs )
{
- // reset the identifier of this object - resetIdComponent will call the
- // appropriate H5xclose to close the id
- try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
- throw IdComponentException("IdComponent::operator=", close_error.getDetailMsg());
- }
+ // handling references to this id
+ decRefCount();
// copy the data members from the rhs object
id = rhs.id;
- ref_count = rhs.ref_count; // points to the same ref counter
// increment the reference counter
- ref_count->increment();
+ H5Iinc_ref(id);
return( *this );
}
@@ -128,30 +104,20 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs )
// Function: IdComponent::setId
///\brief Sets the identifier of this object to a new value.
///\exception H5::IdComponentException when the attempt to close the HDF5
-/// object fails
-///\par Description:
-/// The calling routine must reset the id of this object by
-/// calling resetIdComponent and passing in the "this" pointer.
-/// resetIdComponent ensures that the HDF5 id will be
-/// appropriately closed. If only this object references its
-/// id, its reference counter will be deleted. A new reference
-/// counter is created for the new HDF5 object id.
+/// 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 IdComponent::setId( hid_t new_id )
{
- // reset the identifier of this object, call appropriate H5Xclose
- try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
- throw IdComponentException("IdComponent::setId", close_error.getDetailMsg());
- }
+ // handling references to this id
+ decRefCount();
// reset object's id to the given id
id = new_id;
-
- // starts counting object references
- ref_count = new RefCounter;
}
//--------------------------------------------------------------------------
@@ -166,18 +132,6 @@ hid_t IdComponent::getId () const
}
//--------------------------------------------------------------------------
-// Function: IdComponent::reset
-///\brief Reset this object by deleting/resetting its reference counter.
-///\return HDF5 object id
-// Programmer Binh-Minh Ribler - 2000
-//--------------------------------------------------------------------------
-void IdComponent::reset ()
-{
- delete ref_count;
- ref_count = NULL;
-}
-
-//--------------------------------------------------------------------------
// Function: IdComponent destructor
///\brief Noop destructor.
// Programmer Binh-Minh Ribler - 2000
@@ -209,11 +163,18 @@ IdComponent::~IdComponent() {
}
//
-// Implementation of protected functions
+// Implementation of protected functions for HDF5 Reference Interface.
//
#ifndef DOXYGEN_SHOULD_SKIP_THIS
//--------------------------------------------------------------------------
+// Function: IdComponent default constructor - private
+///\brief Default constructor.
+// Programmer Binh-Minh Ribler - 2000
+//--------------------------------------------------------------------------
+IdComponent::IdComponent() : id(-1) {}
+
+//--------------------------------------------------------------------------
// Function: IdComponent::p_get_file_name
// Purpose: Gets the name of the file, in which this object belongs.
// Exception: H5::IdComponentException
@@ -322,17 +283,6 @@ hid_t IdComponent::p_get_region(void *ref, H5R_type_t ref_type) const
return(space_id);
}
-//--------------------------------------------------------------------------
-// Function: IdComponent default constructor - private
-///\brief Default constructor.
-// Programmer Binh-Minh Ribler - 2000
-//--------------------------------------------------------------------------
-IdComponent::IdComponent() : id(-1)
-{
- // starts counting object references
- ref_count = new RefCounter;
-}
-
#endif // DOXYGEN_SHOULD_SKIP_THIS
#ifndef H5_NO_NAMESPACE
diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h
index c01cd08..154da46 100644
--- a/c++/src/H5IdComponent.h
+++ b/c++/src/H5IdComponent.h
@@ -69,8 +69,6 @@ class H5_DLLCPP IdComponent {
protected:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
hid_t id; // HDF5 object id
- RefCounter* ref_count; // used to keep track of the
- // number of copies of an object
// Default constructor.
IdComponent();
diff --git a/c++/src/H5IntType.cpp b/c++/src/H5IntType.cpp
index a6d17e0..ba14de1 100644
--- a/c++/src/H5IntType.cpp
+++ b/c++/src/H5IntType.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp
index 774ea41..9c8f5f4 100644
--- a/c++/src/H5Object.cpp
+++ b/c++/src/H5Object.cpp
@@ -15,10 +15,8 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
-#include "H5Idtemplates.h"
#include "H5PropList.h"
#include "H5Object.h"
#include "H5DcreatProp.h"
diff --git a/c++/src/H5PredType.cpp b/c++/src/H5PredType.cpp
index 1208a1a..a5233af 100644
--- a/c++/src/H5PredType.cpp
+++ b/c++/src/H5PredType.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp
index 2239724..2564c3f 100644
--- a/c++/src/H5PropList.cpp
+++ b/c++/src/H5PropList.cpp
@@ -20,10 +20,8 @@
#endif
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
-#include "H5Idtemplates.h"
#include "H5PropList.h"
#ifndef H5_NO_NAMESPACE
@@ -88,23 +86,24 @@ PropList::PropList( const hid_t plist_id ) : IdComponent(0)
///\param like_plist - IN: Reference to the existing property list
///\exception H5::PropListIException
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
void PropList::copy( const PropList& like_plist )
{
- // reset the identifier of this PropList - send 'this' in so that
- // H5Pclose can be called appropriately
+ // If this object has a valid id, appropriately decrement reference
+ // counter and close the id.
try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
+ decRefCount();
+ }
+ catch (Exception close_error) {
throw PropListIException("PropList::copy", close_error.getDetailMsg());
}
// call C routine to copy the property list
id = H5Pcopy( like_plist.getId() );
- // points to the same ref counter
- ref_count = new RefCounter;
-
if( id <= 0 )
throw PropListIException("PropList::copy", "H5Pcopy failed");
}
@@ -582,14 +581,18 @@ PropList PropList::getClassParent() const
// Function: PropList destructor
///\brief Properly terminates access to this property list.
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Replaced resetIdComponent with decRefCount to use new ID
+// reference counting mechanisms by QAK, Feb 20, 2005
//--------------------------------------------------------------------------
PropList::~PropList()
-{
+{
// The property list id will be closed properly
try {
- resetIdComponent( this ); }
- catch (Exception close_error) { // thrown by p_close
- cerr << "PropList::~PropList" << close_error.getDetailMsg() << endl;
+ decRefCount();
+ }
+ catch (Exception close_error) {
+ cerr << "PropList::~PropList - " << close_error.getDetailMsg() << endl;
}
}
diff --git a/c++/src/H5RefCounter.cpp b/c++/src/H5RefCounter.cpp
index db1c5a1..860e1b5 100644
--- a/c++/src/H5RefCounter.cpp
+++ b/c++/src/H5RefCounter.cpp
@@ -14,7 +14,6 @@
#include "H5Include.h"
#include "H5Exception.h"
-#include "H5RefCounter.h"
#ifndef H5_NO_NAMESPACE
namespace H5 {
diff --git a/c++/src/H5StrType.cpp b/c++/src/H5StrType.cpp
index 4d30be1..ed011bd 100644
--- a/c++/src/H5StrType.cpp
+++ b/c++/src/H5StrType.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
diff --git a/c++/src/H5VarLenType.cpp b/c++/src/H5VarLenType.cpp
index 9cb3bac..ebe0e86 100644
--- a/c++/src/H5VarLenType.cpp
+++ b/c++/src/H5VarLenType.cpp
@@ -15,7 +15,6 @@
#include <string>
#include "H5Include.h"
-#include "H5RefCounter.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"