summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2014-03-27 04:36:53 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2014-03-27 04:36:53 (GMT)
commite79b0dece508bbc9cb9710625f60ec95e6ea6f27 (patch)
treea820cb427822a79380680ad64e02e91056b2c7cd
parent448e1e05f15326581db9795e92ffd04eae69aa91 (diff)
downloadhdf5-e79b0dece508bbc9cb9710625f60ec95e6ea6f27.zip
hdf5-e79b0dece508bbc9cb9710625f60ec95e6ea6f27.tar.gz
hdf5-e79b0dece508bbc9cb9710625f60ec95e6ea6f27.tar.bz2
[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)
-rw-r--r--c++/src/H5CompType.cpp19
-rw-r--r--c++/src/H5CompType.h3
-rw-r--r--c++/test/tcompound.cpp90
-rw-r--r--c++/test/ttypes.cpp12
4 files changed, 118 insertions, 6 deletions
diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp
index df73d9b..1846846 100644
--- a/c++/src/H5CompType.cpp
+++ b/c++/src/H5CompType.cpp
@@ -451,6 +451,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.
// Programmer Binh-Minh Ribler - 2000
diff --git a/c++/src/H5CompType.h b/c++/src/H5CompType.h
index 3d6a62f..bd6d76c 100644
--- a/c++/src/H5CompType.h
+++ b/c++/src/H5CompType.h
@@ -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"); }
diff --git a/c++/test/tcompound.cpp b/c++/test/tcompound.cpp
index 6ae3f82..60d44b2 100644
--- a/c++/test/tcompound.cpp
+++ b/c++/test/tcompound.cpp
@@ -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()
diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp
index c10cf6d..933181c 100644
--- a/c++/test/ttypes.cpp
+++ b/c++/test/ttypes.cpp
@@ -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));