mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-03-01 16:28:09 +08:00
[svn-r24912] Purpose: Fix HDFFV-8642
Description: Added CompType::setSize(size_t size) to set size for compound data type as H5Tset_size had been changed. Platforms tested: Linux/ppc64 (ostrich) Linux/32 2.6 (jam) SunOS 5.11 (emu)
This commit is contained in:
parent
448e1e05f1
commit
e79b0dece5
@ -450,6 +450,25 @@ void CompType::pack() const
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Function: CompType::setSize
|
||||
///\brief Sets the total size for this compound datatype.
|
||||
///\param size - IN: Size to set
|
||||
///\exception H5::DataTypeIException
|
||||
// Note
|
||||
// H5Tset_size works on atom datatypes and compound datatypes only
|
||||
// Programmer Binh-Minh Ribler - 2014
|
||||
//--------------------------------------------------------------------------
|
||||
void CompType::setSize(size_t size) const
|
||||
{
|
||||
// Call C routine H5Tset_size to set the total size
|
||||
herr_t ret_value = H5Tset_size(id, size);
|
||||
if (ret_value < 0)
|
||||
{
|
||||
throw DataTypeIException("CompType::setSize", "H5Tset_size failed");
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Function: CompType destructor
|
||||
///\brief Properly terminates access to this compound datatype.
|
||||
|
@ -98,6 +98,9 @@ class H5_DLLCPP CompType : public DataType {
|
||||
// Recursively removes padding from within this compound datatype.
|
||||
void pack() const;
|
||||
|
||||
// Sets the total size for this compound datatype.
|
||||
void setSize(size_t size) const;
|
||||
|
||||
///\brief Returns this class name.
|
||||
virtual H5std_string fromClass () const { return("CompType"); }
|
||||
|
||||
|
@ -727,7 +727,96 @@ cerr << "test_compound_7 in catch" << endl;
|
||||
issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
|
||||
}
|
||||
} // test_compound_7()
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: test_compound_set_size
|
||||
*
|
||||
* Purpose: Tests member function setSize() on compound datatype
|
||||
*
|
||||
* Return: None
|
||||
*
|
||||
* Programmer: Binh-Minh Ribler (use partial C version test_ooo_order)
|
||||
* March, 2014
|
||||
*
|
||||
* Modifications:
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#define COMPFILE "tcompound_types.h5"
|
||||
static void test_compound_set_size()
|
||||
{
|
||||
typedef struct {
|
||||
int a, b, c[4], d, e;
|
||||
} src_typ_t;
|
||||
src_typ_t *s_ptr;
|
||||
|
||||
// Output message about test being performed
|
||||
SUBTEST("Setting Size on Compound Datatype");
|
||||
try {
|
||||
// Create File
|
||||
H5File file(COMPFILE, H5F_ACC_TRUNC);
|
||||
|
||||
// Create a compound datatype
|
||||
CompType dtype(sizeof(src_typ_t));
|
||||
|
||||
dtype.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT);
|
||||
dtype.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_FLOAT);
|
||||
dtype.insertMember("c", HOFFSET(src_typ_t, c), PredType::NATIVE_LONG);
|
||||
dtype.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_DOUBLE);
|
||||
|
||||
// Verify that the compound is not packed
|
||||
// bool packed = dtype.packed(); // not until C library provides API
|
||||
// verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__);
|
||||
|
||||
dtype.commit(file, "dtype");
|
||||
|
||||
// Close the type and file
|
||||
dtype.close();
|
||||
file.close();
|
||||
|
||||
// Open the file for read/write
|
||||
file.openFile(COMPFILE, H5F_ACC_RDWR);
|
||||
|
||||
// Open the data type "dtype"
|
||||
CompType dtype_tmp = file.openCompType("dtype");
|
||||
|
||||
// Make a copy of the data type
|
||||
dtype = dtype_tmp;
|
||||
|
||||
// Verify that the compound is not packed
|
||||
// packed = dtype_tmp.packed(); // not until C library provides API
|
||||
// verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__);
|
||||
|
||||
// Expand the type, and verify that it became unpacked
|
||||
dtype.setSize((size_t)33);
|
||||
// packed = dtype.packed(); // not until C library provides API
|
||||
// verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__);
|
||||
|
||||
// Verify setSize() actually set size
|
||||
size_t new_size = dtype.getSize();
|
||||
verify_val(new_size, 33, "DataType::getSize", __LINE__, __FILE__);
|
||||
|
||||
// Shrink the type, and verify that it became packed
|
||||
dtype.setSize((size_t)32);
|
||||
// packed = dtype.packed(); // not until C library provides API
|
||||
// verify_val(packed, TRUE, "DataType::packed", __LINE__, __FILE__);
|
||||
|
||||
// Verify setSize() actually set size again
|
||||
new_size = dtype.getSize();
|
||||
verify_val(new_size, 32, "DataType::getSize", __LINE__, __FILE__);
|
||||
|
||||
/* Close types and file */
|
||||
dtype_tmp.close();
|
||||
dtype.close();
|
||||
file.close();
|
||||
|
||||
PASSED();
|
||||
} // end of try block
|
||||
|
||||
catch (Exception E) {
|
||||
issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
|
||||
}
|
||||
} // test_compound_set_size()
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: test_compound
|
||||
@ -758,6 +847,7 @@ void test_compound()
|
||||
test_compound_5(); // optimized struct converter
|
||||
test_compound_6(); // compound element growing
|
||||
test_compound_7(); // compound element insertion
|
||||
test_compound_set_size(); // set size on compound data types
|
||||
} // test_compound()
|
||||
|
||||
|
||||
|
@ -213,7 +213,7 @@ static void test_query()
|
||||
float b;
|
||||
long c;
|
||||
double d;
|
||||
} s_type_t;
|
||||
} src_typ_t;
|
||||
short enum_val;
|
||||
|
||||
// Output message about test being performed
|
||||
@ -224,12 +224,12 @@ static void test_query()
|
||||
H5File file(FILENAME[2], H5F_ACC_TRUNC);
|
||||
|
||||
// Create a compound datatype
|
||||
CompType tid1(sizeof(s_type_t));
|
||||
CompType tid1(sizeof(src_typ_t));
|
||||
|
||||
tid1.insertMember("a", HOFFSET(s_type_t, a), PredType::NATIVE_INT);
|
||||
tid1.insertMember("b", HOFFSET(s_type_t, b), PredType::NATIVE_FLOAT);
|
||||
tid1.insertMember("c", HOFFSET(s_type_t, c), PredType::NATIVE_LONG);
|
||||
tid1.insertMember("d", HOFFSET(s_type_t, d), PredType::NATIVE_DOUBLE);
|
||||
tid1.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT);
|
||||
tid1.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_FLOAT);
|
||||
tid1.insertMember("c", HOFFSET(src_typ_t, c), PredType::NATIVE_LONG);
|
||||
tid1.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_DOUBLE);
|
||||
|
||||
// Create a enumerate datatype
|
||||
EnumType tid2(sizeof(short));
|
||||
|
Loading…
Reference in New Issue
Block a user