summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2010-08-19 15:27:56 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2010-08-19 15:27:56 (GMT)
commite56b6f6c4019ad7dddf2325c91b134646fcb55e6 (patch)
treef18d1e2dbe3005e3359cf2eefd02c2d69b201213 /src
parentee251b8395c98300e2c3b43fbddc7fe4461e6086 (diff)
downloadhdf5-e56b6f6c4019ad7dddf2325c91b134646fcb55e6.zip
hdf5-e56b6f6c4019ad7dddf2325c91b134646fcb55e6.tar.gz
hdf5-e56b6f6c4019ad7dddf2325c91b134646fcb55e6.tar.bz2
[svn-r19251] New feature(bug #1934): I made H5Tset_order support all data types with some restictions:
1. For enum type, members shouldn't be defined yet. 2. H5T_ORDER_NONE only works for reference and fixed-length string. 3. For opaque type, the order will be ignored. 4. For compound type, all restrictions above apply to the members. I'll change H5Tget_order and do another commit. There is no change to configure.in, config, and Makefile.am. There is some property change for these files when I did a merge from 1.8. Tested on jam. But I tested the 1.8 on heiwa, and amani.
Diffstat (limited to 'src')
-rw-r--r--src/H5Torder.c82
-rw-r--r--src/H5Tprivate.h1
2 files changed, 71 insertions, 12 deletions
diff --git a/src/H5Torder.c b/src/H5Torder.c
index 6c0667b..86a725b 100644
--- a/src/H5Torder.c
+++ b/src/H5Torder.c
@@ -63,6 +63,7 @@ H5T_init_order_interface(void)
*
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
+s
*
*-------------------------------------------------------------------------
*/
@@ -136,6 +137,14 @@ done:
* Robb Matzke, 22 Dec 1998
* Also works for derived datatypes.
*
+ * Raymond Lu, 18 Aug 2010
+ * Now it works for all data types with some restrictions:
+ * 1. For enum type, members shouldn't be defined yet.
+ * 2. H5T_ORDER_NONE only works for reference and fixed-length
+ * string.
+ * 3. For opaque type, the order will be ignored.
+ * 4. For compound type, all restrictions above apply to the
+ * members.
*-------------------------------------------------------------------------
*/
herr_t
@@ -150,23 +159,72 @@ H5Tset_order(hid_t type_id, H5T_order_t order)
/* Check args */
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
- if (H5T_STATE_TRANSIENT!=dt->shared->state)
- HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "datatype is read-only")
if (order < H5T_ORDER_LE || order > H5T_ORDER_NONE)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal byte order")
- if (H5T_ENUM==dt->shared->type && dt->shared->u.enumer.nmembs>0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined")
- while (dt->shared->parent)
- dt = dt->shared->parent; /*defer to parent*/
- if (order == H5T_ORDER_NONE && !(H5T_REFERENCE == dt->shared->type || H5T_IS_FIXED_STRING(dt->shared)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal byte order")
- if (!H5T_IS_ATOMIC(dt->shared))
- HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "operation not defined for specified datatype")
+ if (H5T_STATE_TRANSIENT!=dt->shared->state)
+ HGOTO_ERROR(H5E_ARGS, H5E_CANTINIT, FAIL, "datatype is read-only")
- /* Commit */
- dt->shared->u.atomic.order = order;
+ if (H5T_set_order(dt, order) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "can't set order")
done:
FUNC_LEAVE_API(ret_value)
}
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_set_order
+ *
+ * Purpose: Private function to set the byte order for a datatype.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Raymond Lu
+ * 13 August 2010
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5T_set_order(H5T_t *dtype, H5T_order_t order)
+{
+ H5T_t *memb_type; /* Datatype of compound members */
+ int nmemb; /* Number of members in compound & enum types */
+ int i; /* Local index variable */
+ herr_t ret_value=SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5T_set_order, FAIL)
+
+ if (H5T_ENUM==dtype->shared->type && dtype->shared->u.enumer.nmembs>0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after enum members are defined")
+
+ /* For derived data type, defer to parent */
+ while (dtype->shared->parent)
+ dtype = dtype->shared->parent;
+
+ if (order == H5T_ORDER_NONE && !(H5T_REFERENCE == dtype->shared->type ||
+ H5T_OPAQUE == dtype->shared->type || H5T_IS_FIXED_STRING(dtype->shared)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "illegal byte order")
+
+ /* For atomic data type */
+ if (H5T_IS_ATOMIC(dtype->shared)) {
+ dtype->shared->u.atomic.order = order;
+ HGOTO_DONE(ret_value)
+ }
+
+ /* Loop through all fields of compound type */
+ if(H5T_COMPOUND == dtype->shared->type) {
+ if((nmemb = H5T_get_nmembers(dtype)) < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get number of members from compound data type")
+
+ /* Set order for each compound member type. */
+ for(i=0; i<nmemb; i++) {
+ if(H5T_set_order(dtype->shared->u.compnd.memb[i].type, order) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "can't set order for compound member")
+ }
+ }
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+}
diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h
index c70eea0..8dac972 100644
--- a/src/H5Tprivate.h
+++ b/src/H5Tprivate.h
@@ -110,6 +110,7 @@ H5_DLL H5T_t *H5T_copy(const H5T_t *old_dt, H5T_copy_t method);
H5_DLL herr_t H5T_lock(H5T_t *dt, hbool_t immutable);
H5_DLL herr_t H5T_close(H5T_t *dt);
H5_DLL H5T_t *H5T_get_super(const H5T_t *dt);
+H5_DLL herr_t H5T_set_order(H5T_t *dtype, H5T_order_t order);
H5_DLL H5T_class_t H5T_get_class(const H5T_t *dt, htri_t internal);
H5_DLL htri_t H5T_detect_class(const H5T_t *dt, H5T_class_t cls, hbool_t from_api);
H5_DLL size_t H5T_get_size(const H5T_t *dt);