diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2005-12-03 12:21:25 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2005-12-03 12:21:25 (GMT) |
commit | 5ed48cf279c7cbf46a0107cf9726f8607fc714c4 (patch) | |
tree | 71309b6dcb43df4f4e51613a114d04245295103a /c++/src/H5DataType.cpp | |
parent | 25576025eb5261a6bc90dc75ab28f40208ef2fdd (diff) | |
download | hdf5-5ed48cf279c7cbf46a0107cf9726f8607fc714c4.zip hdf5-5ed48cf279c7cbf46a0107cf9726f8607fc714c4.tar.gz hdf5-5ed48cf279c7cbf46a0107cf9726f8607fc714c4.tar.bz2 |
[svn-r11755] Purpose: Code improvement
Description:
There was a workaround for predefined types, in the C++ library,
implemented when the C++ library was handling the reference
counting of the object ids on its own. Currently, the C++ library
is using the available APIs from the C library for that purpose,
and there were bugs reported involving that part of the C++ library.
So, I decided to remove the workaround completely.
Also, improved the use of std members.
Platforms tested:
Linux 2.4 (heping)
SunOS 5.8 64-bit (sol)
Linux 2.4 w/PGI (colonelk)
Diffstat (limited to 'c++/src/H5DataType.cpp')
-rw-r--r-- | c++/src/H5DataType.cpp | 89 |
1 files changed, 43 insertions, 46 deletions
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 7eaed51..b248d7f 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -12,13 +12,19 @@ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include <string> #ifdef OLD_HEADER_FILENAME #include <iostream.h> #else #include <iostream> #endif +#include <string> +#ifndef H5_NO_NAMESPACE +#ifndef H5_NO_STD + using std::string; +#endif // H5_NO_STD +#endif + #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" @@ -35,7 +41,8 @@ #ifndef H5_NO_NAMESPACE namespace H5 { #ifndef H5_NO_STD - using namespace std; + using std::cerr; + using std::endl; #endif // H5_NO_STD #endif @@ -54,7 +61,7 @@ namespace H5 { // - BMR 5/2004 // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataType::DataType(const hid_t existing_id, bool predefined) : H5Object(existing_id), is_predtype(predefined) {} +DataType::DataType(const hid_t existing_id) : H5Object(existing_id) {} //-------------------------------------------------------------------------- // Function: DataType overloaded constructor @@ -64,7 +71,7 @@ DataType::DataType(const hid_t existing_id, bool predefined) : H5Object(existing ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataType::DataType( const H5T_class_t type_class, size_t size ) : H5Object(), is_predtype( false ) +DataType::DataType( const H5T_class_t type_class, size_t size ) : H5Object() { // Call C routine to create the new datatype id = H5Tcreate( type_class, size ); @@ -79,17 +86,14 @@ DataType::DataType( const H5T_class_t type_class, size_t size ) : H5Object(), is ///\brief Default constructor: Creates a stub datatype // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataType::DataType() : H5Object(), is_predtype( false ) {} +DataType::DataType() : H5Object() {} //-------------------------------------------------------------------------- // Function: DataType copy constructor ///\brief Copy constructor: makes a copy of the original DataType object. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataType::DataType(const DataType& original) : H5Object(original) -{ - is_predtype = original.is_predtype; // copy data member from original -} +DataType::DataType(const DataType& original) : H5Object(original) {} //-------------------------------------------------------------------------- // Function: DataType::copy @@ -103,22 +107,20 @@ DataType::DataType(const DataType& original) : H5Object(original) //-------------------------------------------------------------------------- void DataType::copy( const DataType& like_type ) { - // reset the identifier of this instance, H5Tclose will be called - // if needed - if( is_predtype == false ) { - try { - decRefCount(); - } - catch (Exception close_error) { - throw DataTypeIException(inMemFunc("copy"), close_error.getDetailMsg()); - } + // reset the identifier of this instance, H5Tclose will be called + // if needed + try { + decRefCount(); + } + catch (Exception close_error) { + throw DataTypeIException(inMemFunc("copy"), close_error.getDetailMsg()); } - // call C routine to copy the datatype - id = H5Tcopy( like_type.getId() ); + // call C routine to copy the datatype + id = H5Tcopy( like_type.getId() ); - if( id < 0 ) - throw DataTypeIException(inMemFunc("copy"), "H5Tcopy failed"); + if( id < 0 ) + throw DataTypeIException(inMemFunc("copy"), "H5Tcopy failed"); } //-------------------------------------------------------------------------- @@ -199,7 +201,8 @@ void DataType::commit(CommonFG& loc, const string& name) const // Function: DataType::committed ///\brief Determines whether a datatype is a named type or a /// transient type. -///\return true if the datatype is a named type, and false, otherwise. +///\return \c true if the datatype is a named type, and \c false, +/// otherwise. ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- @@ -503,7 +506,8 @@ bool DataType::detectClass(H5T_class_t cls) const return false; else { - throw DataTypeIException(inMemFunc("detectClass"), "H5Tdetect_class returns negative value"); + throw DataTypeIException(inMemFunc("detectClass"), + "H5Tdetect_class returns negative value"); } } @@ -524,7 +528,8 @@ bool DataType::isVariableStr() const return false; else { - throw DataTypeIException(inMemFunc("isVariableStr"), "H5Tis_variable_str returns negative value"); + throw DataTypeIException(inMemFunc("isVariableStr"), + "H5Tis_variable_str returns negative value"); } } @@ -637,19 +642,13 @@ DataSpace DataType::getRegion(void *ref, H5R_type_t ref_type) const //-------------------------------------------------------------------------- void DataType::close() { - // If this datatype is not a predefined type, call H5Tclose on it. - if( is_predtype == false ) - { - herr_t ret_value = H5Tclose(id); - if( ret_value < 0 ) - { - throw DataTypeIException(inMemFunc("close"), "H5Tclose failed"); - } - // reset the id because the datatype that it represents is now closed - id = 0; - } - else // cannot close a predefined type - throw DataTypeIException("DataType::close", "Cannot close a predefined type"); + herr_t ret_value = H5Tclose(id); + if( ret_value < 0 ) + { + throw DataTypeIException(inMemFunc("close"), "H5Tclose failed"); + } + // reset the id because the datatype that it represents is now closed + id = 0; } //-------------------------------------------------------------------------- @@ -662,14 +661,12 @@ void DataType::close() //-------------------------------------------------------------------------- DataType::~DataType() { - // The datatype id will be closed properly - if( is_predtype == false ) { - try { - decRefCount(); - } - catch (Exception close_error) { - cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl; - } + // The datatype id will be closed properly + try { + decRefCount(); + } + catch (Exception close_error) { + cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl; } } |