Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement H5Fget_obj_ids #61

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 69 additions & 2 deletions src/rest_vol_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

#include "rest_vol_file.h"

herr_t RV_iterate_copy_hid_cb(hid_t obj_id, void *udata);

struct object_id_list {
hid_t *obj_id_list;
size_t obj_count;
} typedef object_id_list;

/*-------------------------------------------------------------------------
* Function: RV_file_create
*
Expand Down Expand Up @@ -544,9 +551,44 @@ RV_file_get(void *obj, H5VL_file_get_args_t *args, hid_t dxpl_id, void **req)

/* H5Fget_obj_ids */
case H5VL_FILE_GET_OBJ_IDS:
FUNC_GOTO_ERROR(H5E_FILE, H5E_UNSUPPORTED, FAIL, "H5Fget_obj_ids is unsupported");
break;

if (args->args.get_obj_ids.max_objs <= 0)
mattjala marked this conversation as resolved.
Show resolved Hide resolved
FUNC_GOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "invalid max object parameter");

if (args->args.get_obj_ids.oid_list == NULL)
FUNC_GOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "given object id list buffer is NULL");

if (args->args.get_obj_ids.count == NULL)
FUNC_GOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "given object id count buffer is NULL");

*args->args.get_obj_ids.count = 0;
unsigned int requested_types = args->args.get_obj_ids.types;

object_id_list id_list;
id_list.obj_id_list = args->args.get_obj_ids.oid_list;
id_list.obj_count = 0;

if (args->args.get_obj_ids.types & H5F_OBJ_FILE)
mattjala marked this conversation as resolved.
Show resolved Hide resolved
if (H5Iiterate(H5I_FILE, RV_iterate_copy_hid_cb, &id_list) < 0)
FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over file ids");

if (args->args.get_obj_ids.types & H5F_OBJ_GROUP)
if (H5Iiterate(H5I_GROUP, RV_iterate_copy_hid_cb, &id_list) < 0)
FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over group ids");

if (args->args.get_obj_ids.types & H5F_OBJ_DATATYPE)
if (H5Iiterate(H5I_DATATYPE, RV_iterate_copy_hid_cb, &id_list) < 0)
FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over datatype ids");

if (args->args.get_obj_ids.types & H5F_OBJ_DATASET)
if (H5Iiterate(H5I_DATASET, RV_iterate_copy_hid_cb, &id_list) < 0)
FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over dataset ids");

if (args->args.get_obj_ids.types & H5F_OBJ_ATTR)
if (H5Iiterate(H5I_ATTR, RV_iterate_copy_hid_cb, &id_list) < 0)
FUNC_GOTO_ERROR(H5E_FILE, H5E_OBJECTITERERROR, FAIL, "can't iterate over attribute ids");
mattjala marked this conversation as resolved.
Show resolved Hide resolved

break;
default:
FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't get this type of information from file");
} /* end switch */
Expand Down Expand Up @@ -755,3 +797,28 @@ RV_file_close(void *file, hid_t dxpl_id, void **req)

return ret_value;
} /* end RV_file_close() */

/*-------------------------------------------------------------------------
* Function: RV_iterate_copy_hid_cb
*
* Purpose: Callback for H5Iiterate() that copies the hid_t
* of each library object into a list.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Matthew Larson
* August, 2023
*/
herr_t
RV_iterate_copy_hid_cb(hid_t obj_id, void *udata)
mattjala marked this conversation as resolved.
Show resolved Hide resolved
{
herr_t ret_value = SUCCEED;
object_id_list *id_list = (object_id_list *)udata;

id_list->obj_id_list[id_list->obj_count] = obj_id;

id_list->obj_count++;

done:
return ret_value;
}