summaryrefslogtreecommitdiffstats
path: root/src/H5Tenum.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-10-01 16:47:45 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-10-01 16:47:45 (GMT)
commit1ba1f2f3222cbe8df0bf601929a4bffd478d7e02 (patch)
treeae51dfc33cf40432dad25a5088767115a98f195e /src/H5Tenum.c
parent8eef7d295cc3dd134aef0a826f1de4287629996d (diff)
downloadhdf5-1ba1f2f3222cbe8df0bf601929a4bffd478d7e02.zip
hdf5-1ba1f2f3222cbe8df0bf601929a4bffd478d7e02.tar.gz
hdf5-1ba1f2f3222cbe8df0bf601929a4bffd478d7e02.tar.bz2
Source formatted
Diffstat (limited to 'src/H5Tenum.c')
-rw-r--r--src/H5Tenum.c306
1 files changed, 147 insertions, 159 deletions
diff --git a/src/H5Tenum.c b/src/H5Tenum.c
index b2b978a..115e56d 100644
--- a/src/H5Tenum.c
+++ b/src/H5Tenum.c
@@ -16,25 +16,21 @@
* in the H5T interface.
*/
-#define H5T_PACKAGE /*suppress error about including H5Tpkg */
+#define H5T_PACKAGE /*suppress error about including H5Tpkg */
/* Interface initialization */
-#define H5_INTERFACE_INIT_FUNC H5T_init_enum_interface
+#define H5_INTERFACE_INIT_FUNC H5T_init_enum_interface
-
-#include "H5private.h" /*generic functions */
-#include "H5Eprivate.h" /*error handling */
-#include "H5Iprivate.h" /*ID functions */
-#include "H5MMprivate.h" /*memory management */
-#include "H5Tpkg.h" /*data-type functions */
+#include "H5private.h" /*generic functions */
+#include "H5Eprivate.h" /*error handling */
+#include "H5Iprivate.h" /*ID functions */
+#include "H5MMprivate.h" /*memory management */
+#include "H5Tpkg.h" /*data-type functions */
/* Static local functions */
-static char *H5T_enum_nameof(const H5T_t *dt, const void *value, char *name/*out*/,
- size_t size);
-static herr_t H5T_enum_valueof(const H5T_t *dt, const char *name,
- void *value/*out*/);
+static char * H5T_enum_nameof(const H5T_t *dt, const void *value, char *name /*out*/, size_t size);
+static herr_t H5T_enum_valueof(const H5T_t *dt, const char *name, void *value /*out*/);
-
/*--------------------------------------------------------------------------
NAME
H5T_init_enum_interface -- Initialize interface-specific information
@@ -56,7 +52,6 @@ H5T_init_enum_interface(void)
FUNC_LEAVE_NOAPI(H5T_init())
} /* H5T_init_enum_interface() */
-
/*-------------------------------------------------------------------------
* Function: H5Tenum_create
*
@@ -77,29 +72,29 @@ H5T_init_enum_interface(void)
hid_t
H5Tenum_create(hid_t parent_id)
{
- H5T_t *parent = NULL; /*base integer data type */
- H5T_t *dt = NULL; /*new enumeration data type */
- hid_t ret_value; /*return value */
+ H5T_t *parent = NULL; /*base integer data type */
+ H5T_t *dt = NULL; /*new enumeration data type */
+ hid_t ret_value; /*return value */
FUNC_ENTER_API(FAIL)
H5TRACE1("i", "i", parent_id);
/* Check args */
- if(NULL == (parent = (H5T_t *)H5I_object_verify(parent_id, H5I_DATATYPE)) || H5T_INTEGER != parent->shared->type)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an integer data type")
+ if (NULL == (parent = (H5T_t *)H5I_object_verify(parent_id, H5I_DATATYPE)) ||
+ H5T_INTEGER != parent->shared->type)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an integer data type")
/* Build new type */
- if(NULL == (dt = H5T__enum_create(parent)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot create enum type")
+ if (NULL == (dt = H5T__enum_create(parent)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot create enum type")
/* Atomize the type */
- if ((ret_value=H5I_register(H5I_DATATYPE, dt, TRUE))<0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register data type atom")
+ if ((ret_value = H5I_register(H5I_DATATYPE, dt, TRUE)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register data type atom")
done:
FUNC_LEAVE_API(ret_value)
}
-
/*-------------------------------------------------------------------------
* Function: H5T__enum_create
*
@@ -121,16 +116,16 @@ done:
H5T_t *
H5T__enum_create(const H5T_t *parent)
{
- H5T_t *ret_value; /*new enumeration data type */
+ H5T_t *ret_value; /*new enumeration data type */
FUNC_ENTER_PACKAGE
HDassert(parent);
/* Build new type */
- if(NULL == (ret_value = H5T__alloc()))
+ if (NULL == (ret_value = H5T__alloc()))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
- ret_value->shared->type = H5T_ENUM;
+ ret_value->shared->type = H5T_ENUM;
ret_value->shared->parent = H5T_copy(parent, H5T_COPY_ALL);
HDassert(ret_value->shared->parent);
ret_value->shared->size = ret_value->shared->parent->shared->size;
@@ -139,7 +134,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
}
-
/*-------------------------------------------------------------------------
* Function: H5Tenum_insert
*
@@ -164,31 +158,30 @@ done:
herr_t
H5Tenum_insert(hid_t type, const char *name, const void *value)
{
- H5T_t *dt=NULL;
- herr_t ret_value=SUCCEED; /* Return value */
+ H5T_t *dt = NULL;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE3("e", "i*s*x", type, name, value);
/* Check args */
- if(NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
- if(H5T_ENUM != dt->shared->type)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
+ if (NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
+ if (H5T_ENUM != dt->shared->type)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
if (!name || !*name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name specified")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name specified")
if (!value)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value specified")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value specified")
/* Do work */
- if(H5T__enum_insert(dt, name, value) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to insert new enumeration member")
+ if (H5T__enum_insert(dt, name, value) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to insert new enumeration member")
done:
FUNC_LEAVE_API(ret_value)
}
-
/*-------------------------------------------------------------------------
* Function: H5T__enum_insert
*
@@ -211,10 +204,10 @@ done:
herr_t
H5T__enum_insert(const H5T_t *dt, const char *name, const void *value)
{
- unsigned i;
- char **names=NULL;
- uint8_t *values=NULL;
- herr_t ret_value=SUCCEED; /* Return value */
+ unsigned i;
+ char ** names = NULL;
+ uint8_t *values = NULL;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
@@ -223,38 +216,37 @@ H5T__enum_insert(const H5T_t *dt, const char *name, const void *value)
HDassert(value);
/* The name and value had better not already exist */
- for (i=0; i<dt->shared->u.enumer.nmembs; i++) {
- if (!HDstrcmp(dt->shared->u.enumer.name[i], name))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "name redefinition")
- if (!HDmemcmp(dt->shared->u.enumer.value+i*dt->shared->size, value, dt->shared->size))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "value redefinition")
+ for (i = 0; i < dt->shared->u.enumer.nmembs; i++) {
+ if (!HDstrcmp(dt->shared->u.enumer.name[i], name))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "name redefinition")
+ if (!HDmemcmp(dt->shared->u.enumer.value + i * dt->shared->size, value, dt->shared->size))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "value redefinition")
}
/* Increase table sizes */
- if(dt->shared->u.enumer.nmembs >= dt->shared->u.enumer.nalloc) {
- unsigned n = MAX(32, 2*dt->shared->u.enumer.nalloc);
+ if (dt->shared->u.enumer.nmembs >= dt->shared->u.enumer.nalloc) {
+ unsigned n = MAX(32, 2 * dt->shared->u.enumer.nalloc);
- if(NULL == (names = (char **)H5MM_realloc(dt->shared->u.enumer.name, n * sizeof(char *))))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
- dt->shared->u.enumer.name = names;
+ if (NULL == (names = (char **)H5MM_realloc(dt->shared->u.enumer.name, n * sizeof(char *))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ dt->shared->u.enumer.name = names;
- if(NULL == (values = (uint8_t *)H5MM_realloc(dt->shared->u.enumer.value, n * dt->shared->size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
- dt->shared->u.enumer.value = values;
- dt->shared->u.enumer.nalloc = n;
+ if (NULL == (values = (uint8_t *)H5MM_realloc(dt->shared->u.enumer.value, n * dt->shared->size)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ dt->shared->u.enumer.value = values;
+ dt->shared->u.enumer.nalloc = n;
}
/* Insert new member at end of member arrays */
- dt->shared->u.enumer.sorted = H5T_SORT_NONE;
- i = dt->shared->u.enumer.nmembs++;
+ dt->shared->u.enumer.sorted = H5T_SORT_NONE;
+ i = dt->shared->u.enumer.nmembs++;
dt->shared->u.enumer.name[i] = H5MM_xstrdup(name);
- HDmemcpy(dt->shared->u.enumer.value+i*dt->shared->size, value, dt->shared->size);
+ HDmemcpy(dt->shared->u.enumer.value + i * dt->shared->size, value, dt->shared->size);
done:
FUNC_LEAVE_NOAPI(ret_value)
}
-
/*-------------------------------------------------------------------------
* Function: H5Tget_member_value
*
@@ -273,30 +265,29 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5Tget_member_value(hid_t type, unsigned membno, void *value/*out*/)
+H5Tget_member_value(hid_t type, unsigned membno, void *value /*out*/)
{
- H5T_t *dt=NULL;
- herr_t ret_value=SUCCEED; /* Return value */
+ H5T_t *dt = NULL;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE3("e", "iIux", type, membno, value);
- if(NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
- if(H5T_ENUM != dt->shared->type)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for data type class")
- if (membno>=dt->shared->u.enumer.nmembs)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid member number")
+ if (NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
+ if (H5T_ENUM != dt->shared->type)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for data type class")
+ if (membno >= dt->shared->u.enumer.nmembs)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid member number")
if (!value)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "null value buffer")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "null value buffer")
- if(H5T__get_member_value(dt, membno, value) < 0)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get member value")
+ if (H5T__get_member_value(dt, membno, value) < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get member value")
done:
FUNC_LEAVE_API(ret_value)
}
-
/*-------------------------------------------------------------------------
* Function: H5T__get_member_value
*
@@ -316,20 +307,18 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5T__get_member_value(const H5T_t *dt, unsigned membno, void *value/*out*/)
+H5T__get_member_value(const H5T_t *dt, unsigned membno, void *value /*out*/)
{
FUNC_ENTER_PACKAGE_NOERR
HDassert(dt);
HDassert(value);
- HDmemcpy(value, dt->shared->u.enumer.value + membno*dt->shared->size, dt->shared->size);
+ HDmemcpy(value, dt->shared->u.enumer.value + membno * dt->shared->size, dt->shared->size);
FUNC_LEAVE_NOAPI(SUCCEED)
}
-
-
/*-------------------------------------------------------------------------
* Function: H5Tenum_nameof
*
@@ -353,32 +342,31 @@ H5T__get_member_value(const H5T_t *dt, unsigned membno, void *value/*out*/)
*-------------------------------------------------------------------------
*/
herr_t
-H5Tenum_nameof(hid_t type, const void *value, char *name/*out*/, size_t size)
+H5Tenum_nameof(hid_t type, const void *value, char *name /*out*/, size_t size)
{
- H5T_t *dt = NULL;
- herr_t ret_value=SUCCEED; /* Return value */
+ H5T_t *dt = NULL;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE4("e", "i*xxz", type, value, name, size);
/* Check args */
- if(NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
- if(H5T_ENUM != dt->shared->type)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
+ if (NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
+ if (H5T_ENUM != dt->shared->type)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
if (!value)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value supplied")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value supplied")
if (!name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name buffer supplied")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name buffer supplied")
- if (NULL==H5T_enum_nameof(dt, value, name, size))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "nameof query failed")
+ if (NULL == H5T_enum_nameof(dt, value, name, size))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "nameof query failed")
done:
FUNC_LEAVE_API(ret_value)
}
-
/*-------------------------------------------------------------------------
* Function: H5T_enum_nameof
*
@@ -408,13 +396,13 @@ done:
*-------------------------------------------------------------------------
*/
static char *
-H5T_enum_nameof(const H5T_t *dt, const void *value, char *name/*out*/, size_t size)
+H5T_enum_nameof(const H5T_t *dt, const void *value, char *name /*out*/, size_t size)
{
- H5T_t *copied_dt = NULL; /* Do sorting in copied datatype */
- unsigned lt, md = 0, rt; /* Indices for binary search */
- int cmp = (-1); /* Comparison result */
- hbool_t alloc_name = FALSE; /* Whether name has been allocated */
- char *ret_value; /* Return value */
+ H5T_t * copied_dt = NULL; /* Do sorting in copied datatype */
+ unsigned lt, md = 0, rt; /* Indices for binary search */
+ int cmp = (-1); /* Comparison result */
+ hbool_t alloc_name = FALSE; /* Whether name has been allocated */
+ char * ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -423,62 +411,61 @@ H5T_enum_nameof(const H5T_t *dt, const void *value, char *name/*out*/, size_t si
HDassert(value);
HDassert(name || 0 == size);
- if(name && size > 0)
+ if (name && size > 0)
*name = '\0';
/* Sanity check */
- if(dt->shared->u.enumer.nmembs == 0)
+ if (dt->shared->u.enumer.nmembs == 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "datatype has no members")
/* Do a binary search over the values to find the correct one. Do sorting
* and search on the copied datatype to protect the original order. */
- if(NULL == (copied_dt = H5T_copy(dt, H5T_COPY_ALL)))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy data type")
- if(H5T__sort_value(copied_dt, NULL) < 0)
+ if (NULL == (copied_dt = H5T_copy(dt, H5T_COPY_ALL)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy data type")
+ if (H5T__sort_value(copied_dt, NULL) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOMPARE, NULL, "value sort failed")
lt = 0;
rt = copied_dt->shared->u.enumer.nmembs;
- while(lt < rt) {
- md = (lt + rt) / 2;
- cmp = HDmemcmp(value, copied_dt->shared->u.enumer.value + md * copied_dt->shared->size, copied_dt->shared->size);
- if(cmp < 0)
- rt = md;
- else if(cmp > 0)
- lt = md + 1;
- else
- break;
+ while (lt < rt) {
+ md = (lt + rt) / 2;
+ cmp = HDmemcmp(value, copied_dt->shared->u.enumer.value + md * copied_dt->shared->size,
+ copied_dt->shared->size);
+ if (cmp < 0)
+ rt = md;
+ else if (cmp > 0)
+ lt = md + 1;
+ else
+ break;
} /* end while */
/* Value was not yet defined. This fixes bug # 774, 2002/06/05 EIP */
- if(cmp != 0)
+ if (cmp != 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "value is currently not defined")
/* Save result name */
- if(!name) {
- if(NULL == (name = (char *)H5MM_malloc(
- HDstrlen(copied_dt->shared->u.enumer.name[md]) + 1)))
+ if (!name) {
+ if (NULL == (name = (char *)H5MM_malloc(HDstrlen(copied_dt->shared->u.enumer.name[md]) + 1)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
alloc_name = TRUE;
} /* end if */
HDstrncpy(name, copied_dt->shared->u.enumer.name[md], size);
- if(HDstrlen(copied_dt->shared->u.enumer.name[md]) >= size)
- HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, NULL, "name has been truncated")
+ if (HDstrlen(copied_dt->shared->u.enumer.name[md]) >= size)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, NULL, "name has been truncated")
/* Set return value */
ret_value = name;
done:
- if(copied_dt)
- if(H5T_close(copied_dt) < 0)
+ if (copied_dt)
+ if (H5T_close(copied_dt) < 0)
HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, NULL, "unable to close data type");
- if(!ret_value && alloc_name)
+ if (!ret_value && alloc_name)
H5MM_free(name);
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T_enum_nameof() */
-
/*-------------------------------------------------------------------------
* Function: H5Tenum_valueof
*
@@ -502,32 +489,31 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5Tenum_valueof(hid_t type, const char *name, void *value/*out*/)
+H5Tenum_valueof(hid_t type, const char *name, void *value /*out*/)
{
- H5T_t *dt;
- herr_t ret_value = SUCCEED; /* Return value */
+ H5T_t *dt;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE3("e", "i*sx", type, name, value);
/* Check args */
- if(NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
- if(H5T_ENUM != dt->shared->type)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
- if(!name || !*name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
- if(!value)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value buffer")
-
- if(H5T_enum_valueof(dt, name, value) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "valueof query failed")
+ if (NULL == (dt = (H5T_t *)H5I_object_verify(type, H5I_DATATYPE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type")
+ if (H5T_ENUM != dt->shared->type)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an enumeration data type")
+ if (!name || !*name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
+ if (!value)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no value buffer")
+
+ if (H5T_enum_valueof(dt, name, value) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "valueof query failed")
done:
FUNC_LEAVE_API(ret_value)
} /* H5Tenum_valueof() */
-
/*-------------------------------------------------------------------------
* Function: H5T_enum_valueof
*
@@ -551,17 +537,17 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5T_enum_valueof(const H5T_t *dt, const char *name, void *value/*out*/)
+H5T_enum_valueof(const H5T_t *dt, const char *name, void *value /*out*/)
{
- unsigned lt, md=0, rt; /*indices for binary search */
- int cmp=(-1); /*comparison result */
- H5T_t *copied_dt = NULL; /*do sorting in copied datatype */
- herr_t ret_value=SUCCEED; /* Return value */
+ unsigned lt, md = 0, rt; /*indices for binary search */
+ int cmp = (-1); /*comparison result */
+ H5T_t * copied_dt = NULL; /*do sorting in copied datatype */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/* Check args */
- HDassert(dt && H5T_ENUM==dt->shared->type);
+ HDassert(dt && H5T_ENUM == dt->shared->type);
HDassert(name && *name);
HDassert(value);
@@ -571,36 +557,38 @@ H5T_enum_valueof(const H5T_t *dt, const char *name, void *value/*out*/)
/* Do a binary search over the names to find the correct one. Do sorting
* and search on the copied datatype to protect the original order. */
- if (NULL==(copied_dt=H5T_copy(dt, H5T_COPY_ALL)))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy data type");
- if(H5T__sort_name(copied_dt, NULL) < 0)
+ if (NULL == (copied_dt = H5T_copy(dt, H5T_COPY_ALL)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy data type");
+ if (H5T__sort_name(copied_dt, NULL) < 0)
HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOMPARE, FAIL, "value sort failed")
lt = 0;
rt = copied_dt->shared->u.enumer.nmembs;
- while (lt<rt) {
- md = (lt+rt)/2;
- cmp = HDstrcmp(name, copied_dt->shared->u.enumer.name[md]);
- if (cmp<0) {
- rt = md;
- } else if (cmp>0) {
- lt = md+1;
- } else {
- break;
- }
+ while (lt < rt) {
+ md = (lt + rt) / 2;
+ cmp = HDstrcmp(name, copied_dt->shared->u.enumer.name[md]);
+ if (cmp < 0) {
+ rt = md;
+ }
+ else if (cmp > 0) {
+ lt = md + 1;
+ }
+ else {
+ break;
+ }
}
/* Value was not yet defined. This fixes bug # 774, 2002/06/05 EIP */
- if (cmp!=0)
+ if (cmp != 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, FAIL, "string doesn't exist in the enumeration type")
- HDmemcpy(value, copied_dt->shared->u.enumer.value+md*copied_dt->shared->size, copied_dt->shared->size);
+ HDmemcpy(value, copied_dt->shared->u.enumer.value + md * copied_dt->shared->size,
+ copied_dt->shared->size);
done:
- if(copied_dt)
- if(H5T_close(copied_dt) < 0)
+ if (copied_dt)
+ if (H5T_close(copied_dt) < 0)
HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "unable to close data type")
FUNC_LEAVE_NOAPI(ret_value)
}
-