diff options
author | Vailin Choi <vchoi@hdfgroup.org> | 2015-04-22 22:31:12 (GMT) |
---|---|---|
committer | Vailin Choi <vchoi@hdfgroup.org> | 2015-04-22 22:31:12 (GMT) |
commit | e0e28a7aae2fabf3ae9d03a1bd5809176935466a (patch) | |
tree | a6b840f4c13522aecdd504d16ee5a265e2abad27 /c++/src/H5DataType.cpp | |
parent | 65b3bc2a937337239ceede5e39261c6b2ba4dc69 (diff) | |
download | hdf5-e0e28a7aae2fabf3ae9d03a1bd5809176935466a.zip hdf5-e0e28a7aae2fabf3ae9d03a1bd5809176935466a.tar.gz hdf5-e0e28a7aae2fabf3ae9d03a1bd5809176935466a.tar.bz2 |
[svn-r26894] Bring revisions #26459 - #26785 from trunk to revise_chunks.
h5committested.
Diffstat (limited to 'c++/src/H5DataType.cpp')
-rw-r--r-- | c++/src/H5DataType.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index c4b1694..cdcd1e6 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -71,6 +71,7 @@ DataType::DataType() : H5Object(), id(H5I_INVALID_HID) {} DataType::DataType(const hid_t existing_id) : H5Object() { id = existing_id; + incRefCount(); // increment number of references to this id } //-------------------------------------------------------------------------- @@ -105,7 +106,7 @@ DataType::DataType( const H5T_class_t type_class, size_t size ) : H5Object() // Jul, 2008 // Added for application convenience. //-------------------------------------------------------------------------- -DataType::DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), id(H5I_INVALID_HID) +DataType::DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object() { id = H5Location::p_dereference(loc.getId(), ref, ref_type, plist, "constructor - by dereference"); } @@ -141,6 +142,27 @@ DataType::DataType(const DataType& original) : H5Object() } //-------------------------------------------------------------------------- +// Function: DataType overloaded constructor +///\brief Creates a integer type using a predefined type +///\param pred_type - IN: Predefined datatype +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - 2000 +// Description +// Copying the type so that when a predefined type is passed in, +// a copy of it is made, not just a duplicate of the HDF5 id. +// Note: calling DataType::copy will invoke DataType::close() +// unnecessarily and will produce undefined behavior. +// -BMR, Apr 2015 +//-------------------------------------------------------------------------- +DataType::DataType(const PredType& pred_type) : H5Object() +{ + // call C routine to copy the datatype + id = H5Tcopy( pred_type.getId() ); + if (id < 0) + throw DataTypeIException("DataType constructor", "H5Tcopy failed"); +} + +//-------------------------------------------------------------------------- // Function: DataType::copy ///\brief Copies an existing datatype to this datatype object ///\param like_type - IN: Datatype to be copied @@ -203,11 +225,22 @@ void DataType::copy(const DataSet& dset) // Makes a copy of the type on the right hand side and stores // the new id in the left hand side object. // Programmer Binh-Minh Ribler - 2000 +// Modification +// Changed operator= to simply copy the id of rhs instead of +// calling H5Tcopy because, when the operator= is invoked, a +// different datatype id is created and it won't have the same +// characteristics as the original one, specifically, if the +// rhs represents a named datatype, "this" would still be a +// transient datatype. +// BMR - Mar, 2015 //-------------------------------------------------------------------------- DataType& DataType::operator=( const DataType& rhs ) { if (this != &rhs) - copy(rhs); + { + id = rhs.id; + incRefCount(); // increment number of references to this id + } return(*this); } @@ -463,8 +496,9 @@ DataType DataType::getSuper() const // the base type, otherwise, raise exception if( base_type_id > 0 ) { - DataType base_type( base_type_id ); - return( base_type ); + DataType base_type; + base_type.p_setId(base_type_id); + return(base_type); } else { |