diff options
author | Neil Fortner <nfortne2@hdfgroup.org> | 2008-11-05 19:07:40 (GMT) |
---|---|---|
committer | Neil Fortner <nfortne2@hdfgroup.org> | 2008-11-05 19:07:40 (GMT) |
commit | e78909e53965b8365c4fb87b84f5f7852da9d36f (patch) | |
tree | b4d8f9eb88c78b8ca61a8d7d5c7888722575f9fb /src | |
parent | 2eefe0be2eee4ffd908d9575127d294f07ebbabe (diff) | |
download | hdf5-e78909e53965b8365c4fb87b84f5f7852da9d36f.zip hdf5-e78909e53965b8365c4fb87b84f5f7852da9d36f.tar.gz hdf5-e78909e53965b8365c4fb87b84f5f7852da9d36f.tar.bz2 |
[svn-r16036] Purpose: add H5Iis_valid function
Description: H5Iis_valid function added. This function checks if the id is
valid (i.e. it is currently registered and visible to the application), and
returns TRUE if it is valid, or FALSE otherwise. It should never return an
error.
Tested: kagiso, linew, smirom (h5committest)
Diffstat (limited to 'src')
-rw-r--r-- | src/H5I.c | 47 | ||||
-rw-r--r-- | src/H5Ipublic.h | 1 |
2 files changed, 48 insertions, 0 deletions
@@ -1844,6 +1844,53 @@ done: /*------------------------------------------------------------------------- + * Function: H5Iis_valid + * + * Purpose: Check if the given id is valid. And id is valid if it is in + * use and has an application reference count of at least 1. + * + * Return: Success: TRUE if the id is valid, FALSE otherwise. + * + * Failure: Negative (never fails currently) + * + * Programmer: Neil Fortner + * Friday, October 31, 2008 (boo) + * + *------------------------------------------------------------------------- + */ +htri_t +H5Iis_valid(hid_t id) +{ + H5I_id_type_t *type_ptr; /* ptr to ID's type */ + H5I_id_info_t *id_ptr; /* ptr to the ID */ + H5I_type_t type; /* ID's type */ + htri_t ret_value = TRUE; /* Return value */ + + FUNC_ENTER_API(H5Iis_valid, FAIL) + + type = H5I_TYPE(id); + /* Check for conditions that would cause H5I_find_id to throw an assertion */ + if (type <= H5I_BADID || type >= H5I_next_type) + HGOTO_DONE(FALSE); + + type_ptr = H5I_id_type_list_g[type]; + if (!type_ptr || type_ptr->count <= 0) + ret_value = FALSE; + + /* Find the ID */ + else if (NULL == (id_ptr = H5I_find_id(id))) + ret_value = FALSE; + + /* Check if the found id is an internal id */ + else if (!id_ptr->app_count) + ret_value = FALSE; + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Iis_valid() */ + + +/*------------------------------------------------------------------------- * Function: H5Isearch * * Purpose: Apply function FUNC to each member of type TYPE and return a diff --git a/src/H5Ipublic.h b/src/H5Ipublic.h index 108f040..608bc9c 100644 --- a/src/H5Ipublic.h +++ b/src/H5Ipublic.h @@ -95,6 +95,7 @@ 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 herr_t H5Inmembers(H5I_type_t type, hsize_t *num_members); H5_DLL htri_t H5Itype_exists(H5I_type_t type); +H5_DLL htri_t H5Iis_valid(hid_t id); #ifdef __cplusplus } |