summaryrefslogtreecommitdiffstats
path: root/c++/src/H5DataSpace.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c++/src/H5DataSpace.cpp')
-rw-r--r--c++/src/H5DataSpace.cpp57
1 files changed, 27 insertions, 30 deletions
diff --git a/c++/src/H5DataSpace.cpp b/c++/src/H5DataSpace.cpp
index c7a098f..e786144 100644
--- a/c++/src/H5DataSpace.cpp
+++ b/c++/src/H5DataSpace.cpp
@@ -46,7 +46,7 @@ const DataSpace DataSpace::ALL( H5S_ALL );
///\exception H5::DataSpaceIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-DataSpace::DataSpace( H5S_class_t type ) : IdComponent()
+DataSpace::DataSpace( H5S_class_t type ) : IdComponent(0)
{
id = H5Screate( type );
if( id < 0 )
@@ -64,7 +64,7 @@ DataSpace::DataSpace( H5S_class_t type ) : IdComponent()
///\exception H5::DataSpaceIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-DataSpace::DataSpace( int rank, const hsize_t * dims, const hsize_t * maxdims) : IdComponent()
+DataSpace::DataSpace( int rank, const hsize_t * dims, const hsize_t * maxdims) : IdComponent(0)
{
id = H5Screate_simple( rank, dims, maxdims );
if( id < 0 )
@@ -103,16 +103,15 @@ DataSpace::DataSpace( const DataSpace& original ) : IdComponent( original ) {}
//--------------------------------------------------------------------------
void DataSpace::copy( const DataSpace& like_space )
{
- // If this object has a valid id, appropriately decrement reference
- // counter and close the id.
+ // If this object has an hdf5 valid id, close it
if( id != H5S_ALL ) {
try {
- decRefCount();
+ close();
}
catch (Exception close_error) {
throw DataSpaceIException("DataSpace::copy", close_error.getDetailMsg());
}
- } // if
+ } // end if
// call C routine to copy the dataspace
id = H5Scopy( like_space.getId() );
@@ -134,8 +133,11 @@ void DataSpace::copy( const DataSpace& like_space )
//--------------------------------------------------------------------------
DataSpace& DataSpace::operator=( const DataSpace& rhs )
{
- copy(rhs);
- return(*this);
+ if (this != &rhs)
+ {
+ copy(rhs);
+ return(*this);
+ }
}
//--------------------------------------------------------------------------
@@ -553,18 +555,17 @@ void DataSpace::selectHyperslab( H5S_seloper_t op, const hsize_t *count, const h
//--------------------------------------------------------------------------
void DataSpace::close()
{
- if( id != H5S_ALL ) // not a constant, should call H5Sclose
- {
- herr_t ret_value = H5Sclose(id);
- if( ret_value < 0 )
- {
- throw DataSpaceIException("DataSpace::close", "H5Sclose failed");
- }
- // reset the id because the dataspace that it represents is now closed
- id = 0;
- }
- else // cannot close a constant
- throw DataSpaceIException("DataSpace::close", "Cannot close a constant");
+ // check if id is a valid hdf5 object id before trying to close it
+ if (p_valid_id(id))
+ {
+ herr_t ret_value = H5Sclose(id);
+ if( ret_value < 0 )
+ {
+ throw DataSpaceIException("DataSpace::close", "H5Sclose failed");
+ }
+ // reset the id because the dataspace that it represents is now closed
+ id = 0;
+ }
}
//--------------------------------------------------------------------------
@@ -577,16 +578,12 @@ void DataSpace::close()
//--------------------------------------------------------------------------
DataSpace::~DataSpace()
{
- // 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) {
- cerr << "DataSpace::~DataSpace - " << close_error.getDetailMsg() << endl;
- }
- } // if
+ try {
+ close();
+ }
+ catch (Exception close_error) {
+ cerr << "DataSpace::~DataSpace - " << close_error.getDetailMsg() << endl;
+ }
}
#ifndef H5_NO_NAMESPACE