summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2004-07-11 05:25:22 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2004-07-11 05:25:22 (GMT)
commit83ff4069fde3d5ab11fbae80eb260278fcf721a5 (patch)
treeeac5fa7071070ec9a022b65b164c93f6c026f8e3
parent34d1d056c92021efc69dc5b671133a46e3f288ec (diff)
downloadhdf5-83ff4069fde3d5ab11fbae80eb260278fcf721a5.zip
hdf5-83ff4069fde3d5ab11fbae80eb260278fcf721a5.tar.gz
hdf5-83ff4069fde3d5ab11fbae80eb260278fcf721a5.tar.bz2
[svn-r8856] Purpose: Fixing bug# 133
Description: Added a check before decrementing reference counter in RefCounter::decrement. Changed the check for counter's value before returning, in RefCounter::noReference. Platforms tested: SunOS 5.7 (arabica) Linux 2.4 (eirene) Misc. update:
-rw-r--r--c++/src/H5RefCounter.cpp60
1 files changed, 49 insertions, 11 deletions
diff --git a/c++/src/H5RefCounter.cpp b/c++/src/H5RefCounter.cpp
index bda9ef7..896d06a 100644
--- a/c++/src/H5RefCounter.cpp
+++ b/c++/src/H5RefCounter.cpp
@@ -13,35 +13,73 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "H5Include.h"
+#include "H5Exception.h"
#include "H5RefCounter.h"
#ifndef H5_NO_NAMESPACE
namespace H5 {
#endif
-// Creates a reference counter to be used by an HDF5 object
+//--------------------------------------------------------------------------
+// Function: RefCounter default constructor
+///\brief Default constructor: Creates a reference counter and set it
+/// to 1.
+// Programmer Binh-Minh Ribler - 2000
+//--------------------------------------------------------------------------
RefCounter::RefCounter() : counter(1) {}
-// Returns the current value of the reference counter
+//--------------------------------------------------------------------------
+// Function: RefCounter::getCounter
+///\brief Returns the current value of the reference counter.
+// Programmer Binh-Minh Ribler - 2000
+//--------------------------------------------------------------------------
int RefCounter::getCounter () const { return counter; }
-// Increments the reference counter as a copy of the object that uses
-// this counter is created.
+//--------------------------------------------------------------------------
+// Function: RefCounter::increment
+///\brief Increments the reference counter.
+// Programmer Binh-Minh Ribler - 2000
+//--------------------------------------------------------------------------
void RefCounter::increment() { counter++; }
-// Decrements the reference counter as a copy of the object that uses
-// this counter is destroyed.
-void RefCounter::decrement() { counter--; }
+//--------------------------------------------------------------------------
+// Function: RefCounter::decrement
+///\brief Decrements the reference counter.
+// Programmer Binh-Minh Ribler - 2000
+//--------------------------------------------------------------------------
+void RefCounter::decrement()
+{
+ if (counter > 0)
+ counter--;
+ else
+ throw IdComponentException("RefCounter::decrement",
+ "reference counter of this object has non-positive value");
+}
-// Decrements the reference counter then determines if there are no more
-// reference to the object that uses this counter
+//--------------------------------------------------------------------------
+// Function: RefCounter::noReference
+///\brief Returns true if there are no more reference to the object
+/// that uses this counter.
+///\return true if there are no more reference to the object
+/// that uses this counter, and false, otherwise.
+// Description
+// Decrements the reference counter then determines if there
+// are no more reference to the object that uses this counter.
+///\note This function will be obsolete in the next release.
+// Programmer Binh-Minh Ribler - 2000
+//--------------------------------------------------------------------------
bool RefCounter::noReference()
{
- if( counter > 0 )
+ if (counter > 0)
counter--;
- return( counter == 0 ? true:false );
+ return(counter <= 0 ? true:false);
}
+//--------------------------------------------------------------------------
+// Function: RefCounter destructor
+///\brief Noop destructor.
+// Programmer Binh-Minh Ribler - 2000
+//--------------------------------------------------------------------------
RefCounter::~RefCounter() {}
#ifndef H5_NO_NAMESPACE