summaryrefslogtreecommitdiffstats
path: root/src/H5Pint.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2012-09-25 15:47:25 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2012-09-25 15:47:25 (GMT)
commit6a89177036b5808ed0ce06ce0aab3af056b56984 (patch)
tree43367eb16716e1a2f074e2af07121e2723eae8d8 /src/H5Pint.c
parent50e3990f2a9e3bba421460d8d5cb21bb6f6e98fe (diff)
downloadhdf5-6a89177036b5808ed0ce06ce0aab3af056b56984.zip
hdf5-6a89177036b5808ed0ce06ce0aab3af056b56984.tar.gz
hdf5-6a89177036b5808ed0ce06ce0aab3af056b56984.tar.bz2
[svn-r22807] Description:
Add encode/decode API routines for property lists: H5Pencode/H5Pdecode. Tested on: FreeBSD/32 8.2 (loyalty) w/gcc4.6, w/C++ & FORTRAN, in debug mode FreeBSD/64 8.2 (freedom) w/gcc4.6, w/C++ & FORTRAN, in debug mode Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (koala) w/Intel compilers, w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, w/threadsafe, in production mode Linux/PPC 2.6 (ostrich) w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-ia64 2.6 (ember) w/Intel compilers, w/parallel, C++ & FORTRAN, in production mode Mac OS X/32 10.7.3 (amazon) in debug mode Mac OS X/32 10.7.3 (amazon) w/C++ & FORTRAN, w/threadsafe, in production mode Mac OS X/32 10.7.3 (amazon) w/parallel, in debug mode
Diffstat (limited to 'src/H5Pint.c')
-rw-r--r--src/H5Pint.c262
1 files changed, 247 insertions, 15 deletions
diff --git a/src/H5Pint.c b/src/H5Pint.c
index 57fe001..88c3247 100644
--- a/src/H5Pint.c
+++ b/src/H5Pint.c
@@ -970,7 +970,7 @@ done:
Internal routine to create a new property
USAGE
H5P_genprop_t *H5P_create_prop(name,size,type,value,prp_create,prp_set,
- prp_get,prp_delete,prp_close)
+ prp_get,prp_delete,prp_close, prp_encode, prp_decode)
const char *name; IN: Name of property to register
size_t size; IN: Size of property in bytes
H5P_prop_within_t type; IN: Type of object the property will be inserted into
@@ -979,6 +979,8 @@ done:
creation callback
H5P_prp_set_func_t prp_set; IN: Function pointer to property set callback
H5P_prp_get_func_t prp_get; IN: Function pointer to property get callback
+ H5P_prp_encode_func_t prp_encode; IN: Function pointer to property encode
+ H5P_prp_decode_func_t prp_decode; IN: Function pointer to property decode
H5P_prp_delete_func_t prp_delete; IN: Function pointer to property delete callback
H5P_prp_copy_func_t prp_copy; IN: Function pointer to property copy callback
H5P_prp_compare_func_t prp_cmp; IN: Function pointer to property compare callback
@@ -996,9 +998,10 @@ done:
--------------------------------------------------------------------------*/
static H5P_genprop_t *
H5P_create_prop(const char *name, size_t size, H5P_prop_within_t type,
- const void *value,
- H5P_prp_create_func_t prp_create, H5P_prp_set_func_t prp_set,
- H5P_prp_get_func_t prp_get, H5P_prp_delete_func_t prp_delete,
+ const void *value, H5P_prp_create_func_t prp_create,
+ H5P_prp_set_func_t prp_set, H5P_prp_get_func_t prp_get,
+ H5P_prp_encode_func_t prp_encode, H5P_prp_decode_func_t prp_decode,
+ H5P_prp_delete_func_t prp_delete,
H5P_prp_copy_func_t prp_copy, H5P_prp_compare_func_t prp_cmp,
H5P_prp_close_func_t prp_close)
{
@@ -1034,6 +1037,8 @@ H5P_create_prop(const char *name, size_t size, H5P_prop_within_t type,
prop->create = prp_create;
prop->set = prp_set;
prop->get = prp_get;
+ prop->encode = prp_encode;
+ prop->decode = prp_decode;
prop->del = prp_delete;
prop->copy = prp_copy;
/* Use custom comparison routine if available, otherwise default to memcmp() */
@@ -1782,7 +1787,8 @@ done:
PURPOSE
Internal routine to register a new property in a property list class.
USAGE
- herr_t H5P_register_real(class, name, size, default, prp_create, prp_set, prp_get, prp_close)
+ herr_t H5P_register_real(class, name, size, default, prp_create, prp_set,
+ prp_get, prp_close, prp_encode, prp_decode)
H5P_genclass_t *class; IN: Property list class to modify
const char *name; IN: Name of property to register
size_t size; IN: Size of property in bytes
@@ -1792,6 +1798,8 @@ done:
creation callback
H5P_prp_set_func_t prp_set; IN: Function pointer to property set callback
H5P_prp_get_func_t prp_get; IN: Function pointer to property get callback
+ H5P_prp_encode_func_t prp_encode; IN: Function pointer to property encode
+ H5P_prp_decode_func_t prp_decode; IN: Function pointer to property decode
H5P_prp_delete_func_t prp_delete; IN: Function pointer to property delete callback
H5P_prp_copy_func_t prp_copy; IN: Function pointer to property copy callback
H5P_prp_compare_func_t prp_cmp; IN: Function pointer to property compare callback
@@ -1911,6 +1919,33 @@ done:
'close' routine returns a negative value, the property list close
routine returns an error value but the property list is still closed.
+ The 'encode' callback is called when a property list with this
+ property is being encoded. H5P_prp_encode_func_t is defined as:
+ typedef herr_t (*H5P_prp_encode_func_t)(void *f, size_t *size,
+ void *value, void *plist, uint8_t **buf);
+ where the parameters to the callback function are:
+ void *f; IN: A fake file structure used to encode.
+ size_t *size; IN/OUT: The size of the buffer to encode the property.
+ void *value; IN: The value of the property being encoded.
+ void *plist; IN: The property list structure.
+ uint8_t **buf; OUT: The buffer that holds the encoded property;
+ The 'encode' routine returns the size needed to encode the property value
+ if the buffer passed in is NULL or the size is zero. Otherwise it encodes
+ the property value into binary in buf.
+
+ The 'decode' callback is called when a property list with this
+ property is being decoded. H5P_prp_encode_func_t is defined as:
+ typedef herr_t (*H5P_prp_encode_func_t)(void *f, size_t *size,
+ void *value, void *plist, uint8_t **buf);
+ where the parameters to the callback function are:
+ void *f; IN: A fake file structure used to decode.
+ size_t *size; IN: UNUSED
+ void *value; IN: UNUSED
+ void *plist; IN: The property list structure.
+ uint8_t **buf; IN: The buffer that holds the binary encoded property;
+ The 'decode' routine decodes the binary buffer passed in and transforms it into
+ corresponding property values that are set in the property list passed in.
+
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
The 'set' callback function may be useful to range check the value being
@@ -1932,8 +1967,10 @@ done:
--------------------------------------------------------------------------*/
herr_t
H5P_register_real(H5P_genclass_t *pclass, const char *name, size_t size,
- const void *def_value, H5P_prp_create_func_t prp_create, H5P_prp_set_func_t prp_set,
- H5P_prp_get_func_t prp_get, H5P_prp_delete_func_t prp_delete,
+ const void *def_value, H5P_prp_create_func_t prp_create,
+ H5P_prp_set_func_t prp_set, H5P_prp_get_func_t prp_get,
+ H5P_prp_encode_func_t prp_encode, H5P_prp_decode_func_t prp_decode,
+ H5P_prp_delete_func_t prp_delete,
H5P_prp_copy_func_t prp_copy, H5P_prp_compare_func_t prp_cmp,
H5P_prp_close_func_t prp_close)
{
@@ -1953,7 +1990,9 @@ H5P_register_real(H5P_genclass_t *pclass, const char *name, size_t size,
HGOTO_ERROR(H5E_PLIST, H5E_EXISTS, FAIL, "property already exists")
/* Create property object from parameters */
- if(NULL == (new_prop = H5P_create_prop(name, size, H5P_PROP_WITHIN_CLASS, def_value, prp_create, prp_set, prp_get, prp_delete, prp_copy, prp_cmp, prp_close)))
+ if(NULL == (new_prop = H5P_create_prop(name, size, H5P_PROP_WITHIN_CLASS,
+ def_value, prp_create, prp_set, prp_get, prp_encode, prp_decode,
+ prp_delete, prp_copy, prp_cmp, prp_close)))
HGOTO_ERROR(H5E_PLIST, H5E_CANTCREATE, FAIL,"Can't create property")
/* Insert property into property list class */
@@ -1991,6 +2030,8 @@ done:
creation callback
H5P_prp_set_func_t prp_set; IN: Function pointer to property set callback
H5P_prp_get_func_t prp_get; IN: Function pointer to property get callback
+ H5P_prp_encode_func_t prp_encode; IN: Function pointer to property encode
+ H5P_prp_decode_func_t prp_decode; IN: Function pointer to property decode
H5P_prp_delete_func_t prp_delete; IN: Function pointer to property delete callback
H5P_prp_copy_func_t prp_copy; IN: Function pointer to property copy callback
H5P_prp_compare_func_t prp_cmp; IN: Function pointer to property compare callback
@@ -2056,6 +2097,33 @@ done:
negative value, the property value is returned and the property list get
routine returns an error value.
+ The 'encode' callback is called when a property list with this
+ property is being encoded. H5P_prp_encode_func_t is defined as:
+ typedef herr_t (*H5P_prp_encode_func_t)(void *f, size_t *size,
+ void *value, void *plist, uint8_t **buf);
+ where the parameters to the callback function are:
+ void *f; IN: A fake file structure used to encode.
+ size_t *size; IN/OUT: The size of the buffer to encode the property.
+ void *value; IN: The value of the property being encoded.
+ void *plist; IN: The property list structure.
+ uint8_t **buf; OUT: The buffer that holds the encoded property;
+ The 'encode' routine returns the size needed to encode the property value
+ if the buffer passed in is NULL or the size is zero. Otherwise it encodes
+ the property value into binary in buf.
+
+ The 'decode' callback is called when a property list with this
+ property is being decoded. H5P_prp_encode_func_t is defined as:
+ typedef herr_t (*H5P_prp_encode_func_t)(void *f, size_t *size,
+ void *value, void *plist, uint8_t **buf);
+ where the parameters to the callback function are:
+ void *f; IN: A fake file structure used to decode.
+ size_t *size; IN: UNUSED
+ void *value; IN: UNUSED
+ void *plist; IN: The property list structure.
+ uint8_t **buf; IN: The buffer that holds the binary encoded property;
+ The 'decode' routine decodes the binary buffer passed in and transforms it into
+ corresponding property values that are set in the property list passed in.
+
The 'delete' callback is called when a property is deleted from a
property list. H5P_prp_del_func_t is defined as:
typedef herr_t (*H5P_prp_del_func_t)(hid_t prop_id, const char *name,
@@ -2131,8 +2199,10 @@ done:
--------------------------------------------------------------------------*/
herr_t
H5P_register(H5P_genclass_t **ppclass, const char *name, size_t size,
- const void *def_value, H5P_prp_create_func_t prp_create, H5P_prp_set_func_t prp_set,
- H5P_prp_get_func_t prp_get, H5P_prp_delete_func_t prp_delete,
+ const void *def_value, H5P_prp_create_func_t prp_create,
+ H5P_prp_set_func_t prp_set, H5P_prp_get_func_t prp_get,
+ H5P_prp_encode_func_t prp_encode, H5P_prp_decode_func_t prp_decode,
+ H5P_prp_delete_func_t prp_delete,
H5P_prp_copy_func_t prp_copy, H5P_prp_compare_func_t prp_cmp,
H5P_prp_close_func_t prp_close)
{
@@ -2186,7 +2256,8 @@ H5P_register(H5P_genclass_t **ppclass, const char *name, size_t size,
} /* end if */
/* Really register the property in the class */
- if(H5P_register_real(pclass, name, size, def_value, prp_create, prp_set, prp_get, prp_delete, prp_copy, prp_cmp, prp_close) < 0)
+ if(H5P_register_real(pclass, name, size, def_value, prp_create, prp_set, prp_get,
+ prp_encode, prp_decode, prp_delete, prp_copy, prp_cmp, prp_close) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTCREATE, FAIL, "can't register property")
/* Update pointer to pointer to class, if a new one was generated */
@@ -2208,13 +2279,16 @@ done:
PURPOSE
Internal routine to insert a new property in a property list.
USAGE
- herr_t H5P_insert(plist, name, size, value, prp_set, prp_get, prp_close)
+ herr_t H5P_insert(plist, name, size, value, prp_set, prp_get, prp_close,
+ prp_encode, prp_decode)
H5P_genplist_t *plist; IN: Property list to add property to
const char *name; IN: Name of property to add
size_t size; IN: Size of property in bytes
void *value; IN: Pointer to the value for the property
H5P_prp_set_func_t prp_set; IN: Function pointer to property set callback
H5P_prp_get_func_t prp_get; IN: Function pointer to property get callback
+ H5P_prp_encode_func_t prp_encode; IN: Function pointer to property encode
+ H5P_prp_decode_func_t prp_decode; IN: Function pointer to property decode
H5P_prp_delete_func_t prp_delete; IN: Function pointer to property delete callback
H5P_prp_copy_func_t prp_copy; IN: Function pointer to property copy callback
H5P_prp_compare_func_t prp_cmp; IN: Function pointer to property compare callback
@@ -2264,6 +2338,33 @@ done:
negative value, the property value is returned and the property list get
routine returns an error value.
+ The 'encode' callback is called when a property list with this
+ property is being encoded. H5P_prp_encode_func_t is defined as:
+ typedef herr_t (*H5P_prp_encode_func_t)(void *f, size_t *size,
+ void *value, void *plist, uint8_t **buf);
+ where the parameters to the callback function are:
+ void *f; IN: A fake file structure used to encode.
+ size_t *size; IN/OUT: The size of the buffer to encode the property.
+ void *value; IN: The value of the property being encoded.
+ void *plist; IN: The property list structure.
+ uint8_t **buf; OUT: The buffer that holds the encoded property;
+ The 'encode' routine returns the size needed to encode the property value
+ if the buffer passed in is NULL or the size is zero. Otherwise it encodes
+ the property value into binary in buf.
+
+ The 'decode' callback is called when a property list with this
+ property is being decoded. H5P_prp_encode_func_t is defined as:
+ typedef herr_t (*H5P_prp_encode_func_t)(void *f, size_t *size,
+ void *value, void *plist, uint8_t **buf);
+ where the parameters to the callback function are:
+ void *f; IN: A fake file structure used to decode.
+ size_t *size; IN: UNUSED
+ void *value; IN: UNUSED
+ void *plist; IN: The property list structure.
+ uint8_t **buf; IN: The buffer that holds the binary encoded property;
+ The 'decode' routine decodes the binary buffer passed in and transforms it into
+ corresponding property values that are set in the property list passed in.
+
The 'delete' callback is called when a property is deleted from a
property list. H5P_prp_del_func_t is defined as:
typedef herr_t (*H5P_prp_del_func_t)(hid_t prop_id, const char *name,
@@ -2344,6 +2445,7 @@ done:
herr_t
H5P_insert(H5P_genplist_t *plist, const char *name, size_t size,
void *value, H5P_prp_set_func_t prp_set, H5P_prp_get_func_t prp_get,
+ H5P_prp_encode_func_t prp_encode, H5P_prp_decode_func_t prp_decode,
H5P_prp_delete_func_t prp_delete, H5P_prp_copy_func_t prp_copy,
H5P_prp_compare_func_t prp_cmp, H5P_prp_close_func_t prp_close)
{
@@ -2391,7 +2493,9 @@ H5P_insert(H5P_genplist_t *plist, const char *name, size_t size,
/* Ok to add to property list */
/* Create property object from parameters */
- if(NULL == (new_prop = H5P_create_prop(name, size, H5P_PROP_WITHIN_LIST, value, NULL, prp_set, prp_get, prp_delete, prp_copy, prp_cmp, prp_close)))
+ if(NULL == (new_prop = H5P_create_prop(name, size, H5P_PROP_WITHIN_LIST, value, NULL,
+ prp_set, prp_get, prp_encode, prp_decode, prp_delete, prp_copy,
+ prp_cmp, prp_close)))
HGOTO_ERROR(H5E_PLIST, H5E_CANTCREATE, FAIL, "Can't create property")
/* Insert property into property list class */
@@ -2950,6 +3054,16 @@ H5P_cmp_prop(const H5P_genprop_t *prop1, const H5P_genprop_t *prop2)
if(prop1->get != NULL && prop2->get == NULL) HGOTO_DONE(1);
if(prop1->get != prop2->get) HGOTO_DONE(-1);
+ /* Check if they both have the same 'encode' callback */
+ if(prop1->encode == NULL && prop2->encode != NULL) HGOTO_DONE(-1);
+ if(prop1->encode != NULL && prop2->encode == NULL) HGOTO_DONE(1);
+ if(prop1->encode != prop2->encode) HGOTO_DONE(-1);
+
+ /* Check if they both have the same 'decode' callback */
+ if(prop1->decode == NULL && prop2->decode != NULL) HGOTO_DONE(-1);
+ if(prop1->decode != NULL && prop2->decode == NULL) HGOTO_DONE(1);
+ if(prop1->decode != prop2->decode) HGOTO_DONE(-1);
+
/* Check if they both have the same 'delete' callback */
if(prop1->del == NULL && prop2->del != NULL) HGOTO_DONE(-1);
if(prop1->del != NULL && prop2->del == NULL) HGOTO_DONE(1);
@@ -4270,7 +4384,7 @@ H5P_copy_prop_plist(hid_t dst_id, hid_t src_id, const char *name)
/* Create property object from parameters */
if(NULL == (new_prop = H5P_create_prop(prop->name, prop->size, H5P_PROP_WITHIN_LIST, prop->value,
- prop->create, prop->set, prop->get,
+ prop->create, prop->set, prop->get, prop->encode, prop->decode,
prop->del, prop->copy, prop->cmp, prop->close)))
HGOTO_ERROR(H5E_PLIST, H5E_CANTCREATE, FAIL,"Can't create property")
@@ -4362,7 +4476,7 @@ H5P_copy_prop_pclass(hid_t dst_id, hid_t src_id, const char *name)
/* Register the property into the destination */
orig_dst_pclass = dst_pclass;
if(H5P_register(&dst_pclass, name, prop->size, prop->value, prop->create, prop->set, prop->get,
- prop->del, prop->copy, prop->cmp, prop->close) < 0)
+ prop->encode, prop->decode, prop->del, prop->copy, prop->cmp, prop->close) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTDELETE, FAIL, "unable to remove property")
/* Check if the property class changed and needs to be substituted in the ID */
@@ -4871,3 +4985,121 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5P_close_class() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5P__new_plist_of_type
+ *
+ * Purpose: Create a new property list, of a given type
+ *
+ * Return: Success: ID of new property list
+ * Failure: Negative
+ *
+ * Programmer: Quincey Koziol
+ * Thursday, August 2, 2012
+ *
+ *-------------------------------------------------------------------------
+ */
+hid_t
+H5P__new_plist_of_type(H5P_plist_type_t type)
+{
+ H5P_genclass_t *pclass; /* Class of property list to create */
+ hid_t class_id; /* ID of class to create */
+ hid_t ret_value; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ /* Sanity checks */
+ HDcompile_assert(H5P_TYPE_LINK_ACCESS == (H5P_TYPE_MAX_TYPE - 1));
+ HDassert(type >= H5P_TYPE_USER && type <= H5P_TYPE_LINK_ACCESS);
+
+ /* Check arguments */
+ if(type == H5P_TYPE_USER)
+ HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "can't create user property list");
+ if(type == H5P_TYPE_ROOT)
+ HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "shouldn't be creating root class property list");
+
+ /* Instantiate a property list of the proper type */
+ switch(type) {
+ case H5P_TYPE_OBJECT_CREATE:
+ class_id = H5P_CLS_OBJECT_CREATE_g;
+ break;
+
+ case H5P_TYPE_FILE_CREATE:
+ class_id = H5P_CLS_FILE_CREATE_g;
+ break;
+
+ case H5P_TYPE_FILE_ACCESS:
+ class_id = H5P_CLS_FILE_ACCESS_g;
+ break;
+
+ case H5P_TYPE_DATASET_CREATE:
+ class_id = H5P_CLS_DATASET_CREATE_g;
+ break;
+
+ case H5P_TYPE_DATASET_ACCESS:
+ class_id = H5P_CLS_DATASET_ACCESS_g;
+ break;
+
+ case H5P_TYPE_DATASET_XFER:
+ class_id = H5P_CLS_DATASET_XFER_g;
+ break;
+
+ case H5P_TYPE_FILE_MOUNT:
+ class_id = H5P_CLS_FILE_MOUNT_g;
+ break;
+
+ case H5P_TYPE_GROUP_CREATE:
+ class_id = H5P_CLS_GROUP_CREATE_g;
+ break;
+
+ case H5P_TYPE_GROUP_ACCESS:
+ class_id = H5P_CLS_GROUP_ACCESS_g;
+ break;
+
+ case H5P_TYPE_DATATYPE_CREATE:
+ class_id = H5P_CLS_DATATYPE_CREATE_g;
+ break;
+
+ case H5P_TYPE_DATATYPE_ACCESS:
+ class_id = H5P_CLS_DATATYPE_ACCESS_g;
+ break;
+
+ case H5P_TYPE_STRING_CREATE:
+ class_id = H5P_CLS_STRING_CREATE_g;
+ break;
+
+ case H5P_TYPE_ATTRIBUTE_CREATE:
+ class_id = H5P_CLS_ATTRIBUTE_CREATE_g;
+ break;
+
+ case H5P_TYPE_OBJECT_COPY:
+ class_id = H5P_CLS_OBJECT_COPY_g;
+ break;
+
+ case H5P_TYPE_LINK_CREATE:
+ class_id = H5P_CLS_LINK_CREATE_g;
+ break;
+
+ case H5P_TYPE_LINK_ACCESS:
+ class_id = H5P_CLS_LINK_ACCESS_g;
+ break;
+
+ case H5P_TYPE_USER: /* shut compiler warnings up */
+ case H5P_TYPE_ROOT:
+ case H5P_TYPE_MAX_TYPE:
+ default:
+ HGOTO_ERROR(H5E_PLIST, H5E_BADRANGE, FAIL, "invalid property list type: %u\n", (unsigned)type);
+ } /* end switch */
+
+ /* Get the class object */
+ if(NULL == (pclass = (H5P_genclass_t *)H5I_object(class_id)))
+ HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a property class")
+
+ /* Create the new property list */
+ if((ret_value = H5P_create_id(pclass, TRUE)) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTCREATE, FAIL, "unable to create property list")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5P__new_plist_of_type() */
+