summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5T.c59
-rw-r--r--src/H5Tpublic.h1
2 files changed, 60 insertions, 0 deletions
diff --git a/src/H5T.c b/src/H5T.c
index 50d67e4..c74cb29 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -4075,6 +4075,65 @@ H5Tget_member_name(hid_t type_id, int membno)
/*-------------------------------------------------------------------------
+ * Function: H5Tget_member_index
+ *
+ * Purpose: Returns the index of a member in a compound or enumeration
+ * data type by given name.Members are stored in no particular
+ * order with numbers 0 through N-1 where N is the value
+ * returned by H5Tget_nmembers().
+ *
+ * Return: Success: index of the member if exists.
+ * Failure: -1.
+ *
+ * Programmer: Raymond Lu
+ * Thursday, April 4, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+H5Tget_member_index(hid_t type_id, const char *name)
+{
+ H5T_t *dt = NULL;
+ int ret_value = FAIL;
+ int nmembs, i;
+
+ FUNC_ENTER(H5Tget_member_index, NULL);
+ H5TRACE2("Is","is",type_id,name);
+
+ /* Check arguments */
+ assert(name);
+ if(H5I_DATATYPE!=H5I_get_type(type_id) || NULL==(dt=H5I_object(type_id)))
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+
+ /* Locate member by name */
+ switch (dt->type) {
+ case H5T_COMPOUND:
+ nmembs = dt->u.compnd.nmembs;
+ for(i=0; i<nmembs; i++) {
+ if(!HDstrcmp(dt->u.compnd.memb[i].name, name))
+ HGOTO_DONE(i);
+ }
+ break;
+ case H5T_ENUM:
+ nmembs = dt->u.enumer.nmembs;
+ for(i=0; i<nmembs; i++) {
+ if(!HDstrcmp(dt->u.enumer.name[i], name))
+ HGOTO_DONE(i);
+ }
+ break;
+ default:
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL,
+ "operation not supported for this type");
+ }
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
* Function: H5Tget_member_offset
*
* Purpose: Returns the byte offset of the beginning of a member with
diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h
index 06ef8bf..458340c 100644
--- a/src/H5Tpublic.h
+++ b/src/H5Tpublic.h
@@ -500,6 +500,7 @@ __DLL__ H5T_pad_t H5Tget_inpad(hid_t type_id);
__DLL__ H5T_str_t H5Tget_strpad(hid_t type_id);
__DLL__ int H5Tget_nmembers(hid_t type_id);
__DLL__ char *H5Tget_member_name(hid_t type_id, int membno);
+__DLL__ int H5Tget_member_index(hid_t type_id, const char *name);
__DLL__ size_t H5Tget_member_offset(hid_t type_id, int membno);
__DLL__ H5T_class_t H5Tget_member_class(hid_t type_id, int membno);
__DLL__ hid_t H5Tget_member_type(hid_t type_id, int membno);