diff options
author | Nat Furrer <nfurrer@ncsa.uiuc.edu> | 2004-06-30 15:33:19 (GMT) |
---|---|---|
committer | Nat Furrer <nfurrer@ncsa.uiuc.edu> | 2004-06-30 15:33:19 (GMT) |
commit | 8e468d9dec965e575dd442d63af9e412fcb758e6 (patch) | |
tree | 4a31228176fe34c84079d0f0213ab1564412b76c | |
parent | 358b8545dd9e3baa4b63c88a0d28aa8d7afb065b (diff) | |
download | hdf5-8e468d9dec965e575dd442d63af9e412fcb758e6.zip hdf5-8e468d9dec965e575dd442d63af9e412fcb758e6.tar.gz hdf5-8e468d9dec965e575dd442d63af9e412fcb758e6.tar.bz2 |
[svn-r8766]
Purpose:
Small H5I API changes.
Description:
Changed public version of H5Inmembers to return the number of IDs in a
type by reference. This allows the user to differentiate between the
case when H5Inmembers has an error and when the ID type is just empty.
Added a new API function, H5Itype_exists, which allows the user to
find out whether an ID type exists or not, without throwing an error.
Solution:
Platforms tested:
Copper
Misc. update:
-rw-r--r-- | src/H5I.c | 80 | ||||
-rw-r--r-- | src/H5Ipublic.h | 3 | ||||
-rw-r--r-- | test/tid.c | 46 |
3 files changed, 102 insertions, 27 deletions
@@ -373,41 +373,95 @@ H5I_type_t H5I_register_type(H5I_type_t type_id, size_t hash_size, unsigned rese FUNC_LEAVE_NOAPI(ret_value); } +/*------------------------------------------------------------------------- + * Function: H5Itype_exists + * + * Purpose: Query function to inform the user if a given type is + * currently registered with the library. + * + * Return: Success: 1 if the type is registered, 0 if it is not + * + * Failure: Negative + * + * Programmer: James Laird + * Nathaniel Furrer + * Tuesday, June 29, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +htri_t H5Itype_exists(H5I_type_t type) +{ + htri_t ret_value = TRUE; /* Return value */ + + FUNC_ENTER_API(H5Itype_exists, FAIL); + + if (type<=H5I_BADID || type>=H5I_next_type) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid type number"); + + if (H5I_id_type_list_g[type] == NULL) + ret_value = FALSE; + +done: + FUNC_LEAVE_API(ret_value); +} + /*------------------------------------------------------------------------- * Function: H5Inmembers * * Purpose: Returns the number of members in a type. Public interface to - * H5I_nmembers. + * H5I_nmembers. The public interface throws an error if the + * supplied type does not exist. This is different than the + * private interface, which will just return 0. * - * Return: Success: Number of members; zero if the type is empty - * or has been deleted. + * Return: Success: Zero * * Failure: Negative * * Programmer: James Laird - * Nathaniel Furrer + * Nathaniel Furrer * Friday, April 23, 2004 * * Modifications: + * June 29, 2004 + * Nat Furrer and James Laird + * Changed function signature to return the number of members + * by reference. * *------------------------------------------------------------------------- */ -int H5Inmembers(H5I_type_t type) +herr_t H5Inmembers(H5I_type_t type, int *num_members) { - int ret_value; /* Return value */ + int ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Inmembers, FAIL); - if( H5I_IS_LIB_TYPE( type ) ) - { - HGOTO_ERROR(H5E_ATOM, H5E_BADGROUP, FAIL, "cannot call public function on library type"); - } + if( H5I_IS_LIB_TYPE( type ) ) + { + HGOTO_ERROR(H5E_ATOM, H5E_BADGROUP, FAIL, "cannot call public function on library type"); + } - ret_value = H5I_nmembers(type); + /* Validate parameters. This needs to be done here, instead of letting + * the private interface handle it, because the public interface throws + * an error when the supplied type does not exist. + */ + if (type<=H5I_BADID || type>=H5I_next_type) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid type number"); + if (NULL==H5I_id_type_list_g[type]) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "supplied type does not exist"); - done: - FUNC_LEAVE_API(ret_value); + if (num_members) + { + *num_members = H5I_nmembers(type); + + if (*num_members < 0) + ret_value = FAIL; + } + +done: + FUNC_LEAVE_API(ret_value); } diff --git a/src/H5Ipublic.h b/src/H5Ipublic.h index c8787c9..67357bb 100644 --- a/src/H5Ipublic.h +++ b/src/H5Ipublic.h @@ -93,7 +93,8 @@ H5_DLL int H5Iinc_type_ref(H5I_type_t type); H5_DLL int H5Idec_type_ref(H5I_type_t type); H5_DLL int H5Iget_type_ref(H5I_type_t type); H5_DLL void *H5Isearch(H5I_type_t type, H5I_search_func_t func, void *key); -H5_DLL int H5Inmembers(H5I_type_t type); +H5_DLL herr_t H5Inmembers(H5I_type_t type, int *num_members); +H5_DLL htri_t H5Itype_exists(H5I_type_t type); #ifdef __cplusplus @@ -17,7 +17,7 @@ int id_test() hid_t testID; ssize_t testSize = -1; herr_t err; - int num_ref; + int num_ref, num_members; testObj = malloc(7 * sizeof(int)); @@ -106,9 +106,15 @@ int id_test() VERIFY(err, 0, "H5Idestroy_type"); if( err != 0) goto out; - VERIFY(H5Inmembers(myType), 0, "H5Inmembers"); - if(H5Inmembers(myType) != 0) + VERIFY(H5Itype_exists(myType), 0, "H5Itype_exists"); + if(H5Itype_exists(myType) != 0) + goto out; + + H5E_BEGIN_TRY + VERIFY(H5Inmembers(myType, NULL), -1, "H5Inmembers"); + if(H5Inmembers(myType, NULL) != -1) goto out; + H5E_END_TRY /* Register another type and another object in that type */ myType = H5Iregister_type(64, 0, (H5I_free_t) free ); @@ -123,8 +129,12 @@ int id_test() CHECK(arrayID, H5I_INVALID_HID, "H5Iregister"); if(arrayID == H5I_INVALID_HID) goto out; - VERIFY(H5Inmembers(myType), 1, "H5Inmembers"); - if(H5Inmembers(myType) != 1) + err = H5Inmembers(myType, &num_members); + CHECK(err, -1, "H5Inmembers"); + if (err < 0) + goto out; + VERIFY(num_members, 1, "H5Inmembers"); + if(num_members != 1) goto out; /* Increment references to type and ensure that dec_type_ref @@ -137,8 +147,12 @@ int id_test() VERIFY(num_ref, 1, "H5Idec_type_ref"); if(num_ref != 1) goto out; - VERIFY(H5Inmembers(myType), 1, "H5Inmembers"); - if(H5Inmembers(myType) != 1) + err = H5Inmembers(myType, &num_members); + CHECK(err, -1, "H5Inmembers"); + if (err < 0) + goto out; + VERIFY(num_members, 1, "H5Inmembers"); + if(num_members != 1) goto out; /* This call to dec_type_ref should destroy the type */ @@ -146,9 +160,15 @@ int id_test() VERIFY(num_ref, 0, "H5Idec_type_ref"); if(num_ref != 0) goto out; - VERIFY(H5Inmembers(myType), 0, "H5Inmembers"); - if(H5Inmembers(myType) != 0) + VERIFY(H5Itype_exists(myType), 0, "H5Itype_exists"); + if (H5Itype_exists(myType) != 0) + goto out; + + H5E_BEGIN_TRY + err = H5Inmembers(myType, &num_members); + if(err >= 0) goto out; + H5E_END_TRY return 0; @@ -195,11 +215,11 @@ int id_predefined_test() goto out; H5E_BEGIN_TRY - testInt = H5Inmembers(H5I_ERROR_STACK); + testErr = H5Inmembers(H5I_ERROR_STACK, &testInt); H5E_END_TRY - VERIFY(testInt, -1, "H5Inmembers"); - if(testInt != -1) + VERIFY(testErr, -1, "H5Inmembers"); + if(testErr != -1) goto out; H5E_BEGIN_TRY @@ -341,4 +361,4 @@ void test_ids() id_test(); id_predefined_test(); test_id_type_list(); -}
\ No newline at end of file +} |