[svn-r26640] Purpose: Fix bugs

Description:
    - Changed DataType::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
      rhs', specifically, if the rhs represents a named datatype, "this"
      would still be a transient datatype.
    - Added a DataType constructor that takes a PredType object, and this
      constructor will cause H5Tcopy to generate another datatype id, from a
      predefined datatype.
    - Fixed various mistakes in tests.
Platforms tested:
    Linux/64 (platypus)
    Linux/32 2.6 (jam/gnu and jam/icc 15)
    SunOS 5.11 (emu development/production)
This commit is contained in:
Binh-Minh Ribler 2015-03-27 23:15:43 -05:00
parent 6f75afd15e
commit 72d896f709
5 changed files with 54 additions and 7 deletions

View File

@ -140,6 +140,22 @@ DataType::DataType(const DataType& original) : H5Object()
incRefCount(); // increment number of references to this id
}
//--------------------------------------------------------------------------
// 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
// This is so that when a predefined type is passed in, a
// copy of it is made, not just a duplicate of the HDF5 id.
//--------------------------------------------------------------------------
DataType::DataType(const PredType& pred_type) : H5Object()
{
// use DataType::copy to make a copy of this predefined type
copy(pred_type);
}
//--------------------------------------------------------------------------
// Function: DataType::copy
///\brief Copies an existing datatype to this datatype object
@ -203,11 +219,21 @@ 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.
//--------------------------------------------------------------------------
DataType& DataType::operator=( const DataType& rhs )
{
if (this != &rhs)
copy(rhs);
{
id = rhs.id;
incRefCount(); // increment number of references to this id
}
return(*this);
}

View File

@ -36,6 +36,9 @@ class H5_DLLCPP DataType : public H5Object {
// Copy constructor: makes a copy of the original object
DataType( const DataType& original );
// Creates a copy of a predefined type
DataType(const PredType& pred_type);
// Creates a datatype by way of dereference.
DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT);
DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT);

View File

@ -24,7 +24,7 @@ namespace H5 {
//! Class IntType operates on HDF5 integer datatype.
class H5_DLLCPP IntType : public AtomType {
public:
// Creates a integer type using a predefined type
// Creates an integer type using a predefined type
IntType(const PredType& pred_type);
// Gets the integer datatype of the specified dataset

View File

@ -780,7 +780,7 @@ static void test_compound_set_size()
CompType dtype_tmp = file.openCompType("dtype");
// Make a copy of the data type
dtype = dtype_tmp;
dtype.copy(dtype_tmp);
// Verify that the compound is not packed
// packed = dtype_tmp.packed(); // not until C library provides API

View File

@ -182,20 +182,38 @@ static void test_get_objname_ontypes()
// Create a datatype and save it
IntType inttype(PredType::STD_B8LE);
inttype.commit(file, "INT type of STD_B8LE");
// Close the type then open it again to test getting its name
inttype.close();
inttype = file.openIntType("INT type of STD_B8LE");
// Get and verify its name
H5std_string inttype_name = inttype.getObjName();
verify_val(inttype_name, "/INT type of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__);
// Make copy of a predefined type and save it
DataType dtype(PredType::STD_B8LE);
dtype.commit(file, "STD_B8LE");
// Close the data type and file
dtype.close();
file.close();
// Re-open the file and the data type to test getting its name
file.openFile(FILE_OBJECTS, H5F_ACC_RDWR);
dtype = file.openDataType("STD_B8LE");
// Get and verify its name
H5std_string type_name = dtype.getObjName();
verify_val(type_name, "/STD_B8LE", "DataSet::getObjName", __LINE__, __FILE__);
verify_val(type_name, "/STD_B8LE", "DataType::getObjName", __LINE__, __FILE__);
// Test getting type's name from copied type
DataType copied_type;
copied_type.copy(dtype);
copied_type.commit(file, "copy of STD_B8LE");
type_name = copied_type.getObjName();
verify_val(type_name, "/copy of STD_B8LE", "DataSet::getObjName", __LINE__, __FILE__);
verify_val(type_name, "/copy of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__);
// Test copying an integer predefined type
IntType new_int_type(PredType::NATIVE_INT);
@ -203,8 +221,8 @@ static void test_get_objname_ontypes()
// Name this datatype
new_int_type.commit(grp, "IntType NATIVE_INT");
ssize_t name_len = new_int_type.getObjName(type_name); // default len
verify_val(name_len, (ssize_t)HDstrlen("/typetests/IntType NATIVE_INT"), "DataSet::getObjName", __LINE__, __FILE__);
verify_val(type_name, "/typetests/IntType NATIVE_INT", "DataSet::getObjName", __LINE__, __FILE__);
verify_val(name_len, (ssize_t)HDstrlen("/typetests/IntType NATIVE_INT"), "DataType::getObjName", __LINE__, __FILE__);
verify_val(type_name, "/typetests/IntType NATIVE_INT", "DataType::getObjName", __LINE__, __FILE__);
// Close everything or they can be closed when objects go out of scope
dtype.close();