diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2008-10-21 19:10:01 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2008-10-21 19:10:01 (GMT) |
commit | 27ae4bccfd866a9bf334dc191631499d3cea1b19 (patch) | |
tree | 828abaa9099bc36b176c8440f0d905ae267d5b02 /c++/src/H5DataType.cpp | |
parent | 22378dbd24c08d7153f4f295b5bca057191edc38 (diff) | |
download | hdf5-27ae4bccfd866a9bf334dc191631499d3cea1b19.zip hdf5-27ae4bccfd866a9bf334dc191631499d3cea1b19.tar.gz hdf5-27ae4bccfd866a9bf334dc191631499d3cea1b19.tar.bz2 |
[svn-r15922] Description:
Bring revisions 15289:15457 from trunk into metadata journaling
branch.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.5.2 (amazon) in debug mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Diffstat (limited to 'c++/src/H5DataType.cpp')
-rw-r--r-- | c++/src/H5DataType.cpp | 132 |
1 files changed, 72 insertions, 60 deletions
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index c31395e..e023bda 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -62,7 +62,10 @@ namespace H5 { // - BMR 5/2004 // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataType::DataType(const hid_t existing_id) : H5Object(existing_id) {} +DataType::DataType(const hid_t existing_id) : H5Object() +{ + id = existing_id; +} //-------------------------------------------------------------------------- // Function: DataType overloaded constructor @@ -92,9 +95,19 @@ DataType::DataType( const H5T_class_t type_class, size_t size ) : H5Object() /// is a datatype that has been named by DataType::commit. // Programmer Binh-Minh Ribler - Oct, 2006 //-------------------------------------------------------------------------- -DataType::DataType(IdComponent& obj, void* ref) : H5Object() + /* DataType::DataType(IdComponent& obj, void* ref) : H5Object() +{ + H5Object::dereference(obj, ref); +} + */ +DataType::DataType(H5Object& obj, void* ref) : H5Object() { - IdComponent::dereference(obj, ref); + id = obj.p_dereference(ref); +} + +DataType::DataType(H5File& file, void* ref) : H5Object() +{ + id = file.p_dereference(ref); } //-------------------------------------------------------------------------- @@ -102,14 +115,18 @@ DataType::DataType(IdComponent& obj, void* ref) : H5Object() ///\brief Default constructor: Creates a stub datatype // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataType::DataType() : H5Object() {} +DataType::DataType() : H5Object(), id(0) {} //-------------------------------------------------------------------------- // 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) {} +DataType::DataType(const DataType& original) : H5Object(original) +{ + id = original.getId(); + incRefCount(); // increment number of references to this id +} //-------------------------------------------------------------------------- // Function: DataType::copy @@ -616,52 +633,6 @@ bool DataType::isVariableStr() const } } -//-------------------------------------------------------------------------- -// Function: DataType::Reference -///\brief Important!!! - This functions may not work correctly, it -/// will be removed in the near future. Please use similar -/// DataType::reference instead! -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* DataType::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const -{ - try { - return(p_reference(name, dataspace.getId(), ref_type)); - } - catch (IdComponentException E) { - throw DataTypeIException(inMemFunc("Reference"), E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: DataType::Reference -///\brief Important!!! - This functions may not work correctly, it -/// will be removed in the near future. Please use similar -/// DataType::reference instead! -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* DataType::Reference(const char* name) const -{ - try { - return(p_reference(name, -1, H5R_OBJECT)); - } - catch (IdComponentException E) { - throw DataTypeIException(inMemFunc("Reference"), E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: DataType::Reference -///\brief Important!!! - This functions may not work correctly, it -/// will be removed in the near future. Please use similar -/// DataType::reference instead! -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* DataType::Reference(const H5std_string& name) const -{ - return(Reference(name.c_str())); -} - #ifndef H5_NO_DEPRECATED_SYMBOLS //-------------------------------------------------------------------------- // Function: DataType::getObjType @@ -708,6 +679,47 @@ DataSpace DataType::getRegion(void *ref, H5R_type_t ref_type) const } //-------------------------------------------------------------------------- +// Function: DataType::getId +// Purpose: Get the id of this attribute +// Modification: +// May 2008 - BMR +// Class hierarchy is revised to address bugzilla 1068. Class +// AbstractDS and Attribute are moved out of H5Object. In +// addition, member IdComponent::id is moved into subclasses, and +// IdComponent::getId now becomes pure virtual function. +// Programmer Binh-Minh Ribler - May, 2008 +//-------------------------------------------------------------------------- +hid_t DataType::getId() const +{ + return(id); +} + +//-------------------------------------------------------------------------- +// Function: DataType::p_setId +///\brief Sets the identifier of this object to a new value. +/// +///\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. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +void DataType::p_setId(const hid_t new_id) +{ + // handling references to this old id + try { + close(); + } + catch (Exception close_error) { + throw DataTypeIException(inMemFunc("p_setId"), close_error.getDetailMsg()); + } + // reset object's id to the given id + id = new_id; +} + +//-------------------------------------------------------------------------- // Function: DataType::close ///\brief Closes the datatype if it is not a predefined type. /// @@ -723,8 +735,10 @@ void DataType::close() { throw DataTypeIException(inMemFunc("close"), "H5Tclose failed"); } - // reset the id because the datatype that it represents is now closed - id = 0; + // reset the id when the datatype that it represents is no longer + // referenced + if (getCounter() == 0) + id = 0; } } @@ -740,14 +754,12 @@ void DataType::close() //-------------------------------------------------------------------------- DataType::~DataType() { - try { - close(); - } - catch (Exception close_error) { - cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl; - } + try { + close(); + } catch (Exception close_error) { + cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl; + } } - #ifndef H5_NO_NAMESPACE } // end namespace #endif |