diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2020-10-01 15:29:53 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2020-10-01 15:29:53 (GMT) |
commit | ec8ad09125032c9c232878d02e90aa86df162841 (patch) | |
tree | 5d63105d3a0db7d5bbee41c5b74b097649a2115e /src/H5Tfields.c | |
parent | 453238e90e1574ef1c15e3c79f7fb3d77920e77c (diff) | |
download | hdf5-ec8ad09125032c9c232878d02e90aa86df162841.zip hdf5-ec8ad09125032c9c232878d02e90aa86df162841.tar.gz hdf5-ec8ad09125032c9c232878d02e90aa86df162841.tar.bz2 |
Source formatted
Diffstat (limited to 'src/H5Tfields.c')
-rw-r--r-- | src/H5Tfields.c | 350 |
1 files changed, 172 insertions, 178 deletions
diff --git a/src/H5Tfields.c b/src/H5Tfields.c index 8f5e202..99cb14c 100644 --- a/src/H5Tfields.c +++ b/src/H5Tfields.c @@ -16,16 +16,14 @@ * enumerated & compound datatypes in the H5T interface. */ -#include "H5Tmodule.h" /* This source code file is part of the H5T module */ +#include "H5Tmodule.h" /* This source code file is part of the H5T module */ +#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 */ - - /*------------------------------------------------------------------------- * Function: H5Tget_nmembers * @@ -46,24 +44,23 @@ int H5Tget_nmembers(hid_t type_id) { - H5T_t *dt; /* Datatype to query */ - int ret_value; /* Return value */ + H5T_t *dt; /* Datatype to query */ + int ret_value; /* Return value */ FUNC_ENTER_API(FAIL) H5TRACE1("Is", "i", type_id); /* Check args */ - if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") + if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") - if((ret_value = H5T_get_nmembers(dt)) < 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "cannot return member number") + if ((ret_value = H5T_get_nmembers(dt)) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "cannot return member number") done: FUNC_LEAVE_API(ret_value) } /* end H5Tget_nmembers() */ - /*------------------------------------------------------------------------- * Function: H5T_get_nmembers * @@ -85,24 +82,23 @@ done: int H5T_get_nmembers(const H5T_t *dt) { - int ret_value = -1; /* Return value */ + int ret_value = -1; /* Return value */ FUNC_ENTER_NOAPI(FAIL) HDassert(dt); - if(H5T_COMPOUND == dt->shared->type) - ret_value = (int)dt->shared->u.compnd.nmembs; - else if(H5T_ENUM == dt->shared->type) - ret_value = (int)dt->shared->u.enumer.nmembs; + if (H5T_COMPOUND == dt->shared->type) + ret_value = (int)dt->shared->u.compnd.nmembs; + else if (H5T_ENUM == dt->shared->type) + ret_value = (int)dt->shared->u.enumer.nmembs; else - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "operation not supported for type class") + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "operation not supported for type class") done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T_get_nmembers() */ - /*------------------------------------------------------------------------- * Function: H5Tget_member_name * @@ -124,24 +120,23 @@ done: char * H5Tget_member_name(hid_t type_id, unsigned membno) { - H5T_t *dt = NULL; - char *ret_value; + H5T_t *dt = NULL; + char * ret_value; FUNC_ENTER_API(NULL) H5TRACE2("*s", "iIu", type_id, membno); /* Check args */ - if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id,H5I_DATATYPE))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a datatype") + if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a datatype") - if(NULL == (ret_value = H5T__get_member_name(dt, membno))) + if (NULL == (ret_value = H5T__get_member_name(dt, membno))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "unable to get member name") done: FUNC_LEAVE_API(ret_value) } - /*------------------------------------------------------------------------- * Function: H5T__get_member_name * @@ -163,7 +158,7 @@ done: char * H5T__get_member_name(H5T_t const *dt, unsigned membno) { - char *ret_value = NULL; /* Return value */ + char *ret_value = NULL; /* Return value */ FUNC_ENTER_PACKAGE @@ -171,13 +166,13 @@ H5T__get_member_name(H5T_t const *dt, unsigned membno) switch (dt->shared->type) { case H5T_COMPOUND: - if (membno>=dt->shared->u.compnd.nmembs) + if (membno >= dt->shared->u.compnd.nmembs) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid member number") ret_value = H5MM_xstrdup(dt->shared->u.compnd.memb[membno].name); break; case H5T_ENUM: - if (membno>=dt->shared->u.enumer.nmembs) + if (membno >= dt->shared->u.enumer.nmembs) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid member number") ret_value = H5MM_xstrdup(dt->shared->u.enumer.name[membno]); break; @@ -201,7 +196,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } - /*------------------------------------------------------------------------- * Function: H5Tget_member_index * @@ -221,28 +215,28 @@ done: int H5Tget_member_index(hid_t type_id, const char *name) { - H5T_t *dt = NULL; - int ret_value=FAIL; - unsigned i; + H5T_t * dt = NULL; + int ret_value = FAIL; + unsigned i; FUNC_ENTER_API(FAIL) H5TRACE2("Is", "i*s", type_id, name); /* Check arguments */ HDassert(name); - if(NULL == (dt = (H5T_t*)H5I_object_verify(type_id, H5I_DATATYPE))) + if (NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") /* Locate member by name */ - switch(dt->shared->type) { + switch (dt->shared->type) { case H5T_COMPOUND: - for(i = 0; i < dt->shared->u.compnd.nmembs; i++) - if(!HDstrcmp(dt->shared->u.compnd.memb[i].name, name)) + for (i = 0; i < dt->shared->u.compnd.nmembs; i++) + if (!HDstrcmp(dt->shared->u.compnd.memb[i].name, name)) HGOTO_DONE((int)i) break; case H5T_ENUM: - for(i = 0; i < dt->shared->u.enumer.nmembs; i++) - if(!HDstrcmp(dt->shared->u.enumer.name[i], name)) + for (i = 0; i < dt->shared->u.enumer.nmembs; i++) + if (!HDstrcmp(dt->shared->u.enumer.name[i], name)) HGOTO_DONE((int)i) break; @@ -265,7 +259,6 @@ done: FUNC_LEAVE_API(ret_value) } /* end H5Tget_member_index() */ - /*------------------------------------------------------------------------- * Function: H5T__sort_value * @@ -285,12 +278,12 @@ done: herr_t H5T__sort_value(const H5T_t *dt, int *map) { - unsigned nmembs; /* Number of members for datatype */ - size_t size; - hbool_t swapped; /* Whether we've swapped fields */ - uint8_t tbuf[32]; - unsigned i, j; /* Local index variables */ - herr_t ret_value = SUCCEED; /* Return value */ + unsigned nmembs; /* Number of members for datatype */ + size_t size; + hbool_t swapped; /* Whether we've swapped fields */ + uint8_t tbuf[32]; + unsigned i, j; /* Local index variables */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE_NOERR @@ -299,76 +292,78 @@ H5T__sort_value(const H5T_t *dt, int *map) HDassert(H5T_COMPOUND == dt->shared->type || H5T_ENUM == dt->shared->type); /* Use a bubble sort because we can short circuit */ - if(H5T_COMPOUND == dt->shared->type) { - if(H5T_SORT_VALUE != dt->shared->u.compnd.sorted) { - dt->shared->u.compnd.sorted = H5T_SORT_VALUE; - nmembs = dt->shared->u.compnd.nmembs; - for(i = nmembs - 1, swapped = TRUE; i > 0 && swapped; --i) { - for(j = 0, swapped = FALSE; j < i; j++) { - if(dt->shared->u.compnd.memb[j].offset > dt->shared->u.compnd.memb[j + 1].offset) { - H5T_cmemb_t tmp = dt->shared->u.compnd.memb[j]; - dt->shared->u.compnd.memb[j] = dt->shared->u.compnd.memb[j + 1]; - dt->shared->u.compnd.memb[j + 1] = tmp; - if(map) { - int x = map[j]; - - map[j] = map[j + 1]; - map[j + 1] = x; - } /* end if */ - swapped = TRUE; - } /* end if */ - } /* end for */ - } /* end for */ + if (H5T_COMPOUND == dt->shared->type) { + if (H5T_SORT_VALUE != dt->shared->u.compnd.sorted) { + dt->shared->u.compnd.sorted = H5T_SORT_VALUE; + nmembs = dt->shared->u.compnd.nmembs; + for (i = nmembs - 1, swapped = TRUE; i > 0 && swapped; --i) { + for (j = 0, swapped = FALSE; j < i; j++) { + if (dt->shared->u.compnd.memb[j].offset > dt->shared->u.compnd.memb[j + 1].offset) { + H5T_cmemb_t tmp = dt->shared->u.compnd.memb[j]; + dt->shared->u.compnd.memb[j] = dt->shared->u.compnd.memb[j + 1]; + dt->shared->u.compnd.memb[j + 1] = tmp; + if (map) { + int x = map[j]; + + map[j] = map[j + 1]; + map[j + 1] = x; + } /* end if */ + swapped = TRUE; + } /* end if */ + } /* end for */ + } /* end for */ #ifndef NDEBUG - /* I never trust a sort :-) -RPM */ - for(i = 0; i < (nmembs - 1); i++) - HDassert(dt->shared->u.compnd.memb[i].offset < dt->shared->u.compnd.memb[i + 1].offset); + /* I never trust a sort :-) -RPM */ + for (i = 0; i < (nmembs - 1); i++) + HDassert(dt->shared->u.compnd.memb[i].offset < dt->shared->u.compnd.memb[i + 1].offset); #endif - } /* end if */ - } else if(H5T_ENUM == dt->shared->type) { - if(H5T_SORT_VALUE != dt->shared->u.enumer.sorted) { - dt->shared->u.enumer.sorted = H5T_SORT_VALUE; - nmembs = dt->shared->u.enumer.nmembs; - size = dt->shared->size; - HDassert(size <= sizeof(tbuf)); - for(i = (nmembs - 1), swapped = TRUE; i > 0 && swapped; --i) { - for(j = 0, swapped = FALSE; j < i; j++) { - if(HDmemcmp((uint8_t *)dt->shared->u.enumer.value + (j * size), (uint8_t *)dt->shared->u.enumer.value + ((j + 1) * size), size) > 0) { - /* Swap names */ - char *tmp = dt->shared->u.enumer.name[j]; - dt->shared->u.enumer.name[j] = dt->shared->u.enumer.name[j + 1]; - dt->shared->u.enumer.name[j + 1] = tmp; - - /* Swap values */ - H5MM_memcpy(tbuf, (uint8_t *)dt->shared->u.enumer.value + (j * size), size); - H5MM_memcpy((uint8_t *)dt->shared->u.enumer.value + (j * size), - (uint8_t *)dt->shared->u.enumer.value + ((j + 1) * size), size); - H5MM_memcpy((uint8_t *)dt->shared->u.enumer.value + ((j + 1) * size), tbuf, size); - - /* Swap map */ - if(map) { - int x = map[j]; - - map[j] = map[j + 1]; - map[j + 1] = x; - } /* end if */ - - swapped = TRUE; - } /* end if */ - } /* end for */ - } /* end for */ + } /* end if */ + } + else if (H5T_ENUM == dt->shared->type) { + if (H5T_SORT_VALUE != dt->shared->u.enumer.sorted) { + dt->shared->u.enumer.sorted = H5T_SORT_VALUE; + nmembs = dt->shared->u.enumer.nmembs; + size = dt->shared->size; + HDassert(size <= sizeof(tbuf)); + for (i = (nmembs - 1), swapped = TRUE; i > 0 && swapped; --i) { + for (j = 0, swapped = FALSE; j < i; j++) { + if (HDmemcmp((uint8_t *)dt->shared->u.enumer.value + (j * size), + (uint8_t *)dt->shared->u.enumer.value + ((j + 1) * size), size) > 0) { + /* Swap names */ + char *tmp = dt->shared->u.enumer.name[j]; + dt->shared->u.enumer.name[j] = dt->shared->u.enumer.name[j + 1]; + dt->shared->u.enumer.name[j + 1] = tmp; + + /* Swap values */ + H5MM_memcpy(tbuf, (uint8_t *)dt->shared->u.enumer.value + (j * size), size); + H5MM_memcpy((uint8_t *)dt->shared->u.enumer.value + (j * size), + (uint8_t *)dt->shared->u.enumer.value + ((j + 1) * size), size); + H5MM_memcpy((uint8_t *)dt->shared->u.enumer.value + ((j + 1) * size), tbuf, size); + + /* Swap map */ + if (map) { + int x = map[j]; + + map[j] = map[j + 1]; + map[j + 1] = x; + } /* end if */ + + swapped = TRUE; + } /* end if */ + } /* end for */ + } /* end for */ #ifndef NDEBUG - /* I never trust a sort :-) -RPM */ - for(i = 0; i < (nmembs - 1); i++) - HDassert(HDmemcmp((uint8_t *)dt->shared->u.enumer.value + (i * size), (uint8_t *)dt->shared->u.enumer.value + ((i + 1) * size), size) < 0); + /* I never trust a sort :-) -RPM */ + for (i = 0; i < (nmembs - 1); i++) + HDassert(HDmemcmp((uint8_t *)dt->shared->u.enumer.value + (i * size), + (uint8_t *)dt->shared->u.enumer.value + ((i + 1) * size), size) < 0); #endif - } /* end if */ - } /* end else */ + } /* end if */ + } /* end else */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__sort_value() */ - /*------------------------------------------------------------------------- * Function: H5T__sort_name * @@ -388,86 +383,85 @@ H5T__sort_value(const H5T_t *dt, int *map) herr_t H5T__sort_name(const H5T_t *dt, int *map) { - unsigned i, j, nmembs; - size_t size; - hbool_t swapped; - uint8_t tbuf[32]; + unsigned i, j, nmembs; + size_t size; + hbool_t swapped; + uint8_t tbuf[32]; FUNC_ENTER_PACKAGE_NOERR /* Check args */ HDassert(dt); - HDassert(H5T_COMPOUND==dt->shared->type || H5T_ENUM==dt->shared->type); + HDassert(H5T_COMPOUND == dt->shared->type || H5T_ENUM == dt->shared->type); /* Use a bubble sort because we can short circuit */ - if (H5T_COMPOUND==dt->shared->type) { - if (H5T_SORT_NAME!=dt->shared->u.compnd.sorted) { - dt->shared->u.compnd.sorted = H5T_SORT_NAME; - nmembs = dt->shared->u.compnd.nmembs; - for (i=nmembs-1, swapped=TRUE; i>0 && swapped; --i) { - for (j=0, swapped=FALSE; j<i; j++) { - if (HDstrcmp(dt->shared->u.compnd.memb[j].name, - dt->shared->u.compnd.memb[j+1].name)>0) { - H5T_cmemb_t tmp = dt->shared->u.compnd.memb[j]; - dt->shared->u.compnd.memb[j] = dt->shared->u.compnd.memb[j+1]; - dt->shared->u.compnd.memb[j+1] = tmp; - swapped = TRUE; - if (map) { - int x = map[j]; - map[j] = map[j+1]; - map[j+1] = x; - } - } - } - } + if (H5T_COMPOUND == dt->shared->type) { + if (H5T_SORT_NAME != dt->shared->u.compnd.sorted) { + dt->shared->u.compnd.sorted = H5T_SORT_NAME; + nmembs = dt->shared->u.compnd.nmembs; + for (i = nmembs - 1, swapped = TRUE; i > 0 && swapped; --i) { + for (j = 0, swapped = FALSE; j < i; j++) { + if (HDstrcmp(dt->shared->u.compnd.memb[j].name, dt->shared->u.compnd.memb[j + 1].name) > + 0) { + H5T_cmemb_t tmp = dt->shared->u.compnd.memb[j]; + dt->shared->u.compnd.memb[j] = dt->shared->u.compnd.memb[j + 1]; + dt->shared->u.compnd.memb[j + 1] = tmp; + swapped = TRUE; + if (map) { + int x = map[j]; + map[j] = map[j + 1]; + map[j + 1] = x; + } + } + } + } #ifndef NDEBUG - /* I never trust a sort :-) -RPM */ - for (i=0; i<nmembs-1; i++) { - HDassert(HDstrcmp(dt->shared->u.compnd.memb[i].name, - dt->shared->u.compnd.memb[i+1].name)<0); - } + /* I never trust a sort :-) -RPM */ + for (i = 0; i < nmembs - 1; i++) { + HDassert(HDstrcmp(dt->shared->u.compnd.memb[i].name, dt->shared->u.compnd.memb[i + 1].name) < + 0); + } #endif - } - } else if (H5T_ENUM==dt->shared->type) { - if (H5T_SORT_NAME!=dt->shared->u.enumer.sorted) { - dt->shared->u.enumer.sorted = H5T_SORT_NAME; - nmembs = dt->shared->u.enumer.nmembs; - size = dt->shared->size; - HDassert(size<=sizeof(tbuf)); - for (i=nmembs-1, swapped=TRUE; i>0 && swapped; --i) { - for (j=0, swapped=FALSE; j<i; j++) { - if (HDstrcmp(dt->shared->u.enumer.name[j], - dt->shared->u.enumer.name[j+1])>0) { - /* Swap names */ - char *tmp = dt->shared->u.enumer.name[j]; - dt->shared->u.enumer.name[j] = dt->shared->u.enumer.name[j+1]; - dt->shared->u.enumer.name[j+1] = tmp; - - /* Swap values */ - H5MM_memcpy(tbuf, (uint8_t *)dt->shared->u.enumer.value + (j * size), size); - H5MM_memcpy((uint8_t *)dt->shared->u.enumer.value + (j * size), - (uint8_t *)dt->shared->u.enumer.value + ((j + 1) * size), size); - H5MM_memcpy((uint8_t *)dt->shared->u.enumer.value + ((j + 1) * size), tbuf, size); - - /* Swap map */ - if (map) { - int x = map[j]; - map[j] = map[j+1]; - map[j+1] = x; - } - - swapped = TRUE; - } - } - } + } + } + else if (H5T_ENUM == dt->shared->type) { + if (H5T_SORT_NAME != dt->shared->u.enumer.sorted) { + dt->shared->u.enumer.sorted = H5T_SORT_NAME; + nmembs = dt->shared->u.enumer.nmembs; + size = dt->shared->size; + HDassert(size <= sizeof(tbuf)); + for (i = nmembs - 1, swapped = TRUE; i > 0 && swapped; --i) { + for (j = 0, swapped = FALSE; j < i; j++) { + if (HDstrcmp(dt->shared->u.enumer.name[j], dt->shared->u.enumer.name[j + 1]) > 0) { + /* Swap names */ + char *tmp = dt->shared->u.enumer.name[j]; + dt->shared->u.enumer.name[j] = dt->shared->u.enumer.name[j + 1]; + dt->shared->u.enumer.name[j + 1] = tmp; + + /* Swap values */ + H5MM_memcpy(tbuf, (uint8_t *)dt->shared->u.enumer.value + (j * size), size); + H5MM_memcpy((uint8_t *)dt->shared->u.enumer.value + (j * size), + (uint8_t *)dt->shared->u.enumer.value + ((j + 1) * size), size); + H5MM_memcpy((uint8_t *)dt->shared->u.enumer.value + ((j + 1) * size), tbuf, size); + + /* Swap map */ + if (map) { + int x = map[j]; + map[j] = map[j + 1]; + map[j + 1] = x; + } + + swapped = TRUE; + } + } + } #ifndef NDEBUG - /* I never trust a sort :-) -RPM */ - for (i=0; i<nmembs-1; i++) - HDassert(HDstrcmp(dt->shared->u.enumer.name[i], dt->shared->u.enumer.name[i+1])<0); + /* I never trust a sort :-) -RPM */ + for (i = 0; i < nmembs - 1; i++) + HDassert(HDstrcmp(dt->shared->u.enumer.name[i], dt->shared->u.enumer.name[i + 1]) < 0); #endif - } + } } FUNC_LEAVE_NOAPI(SUCCEED) } - |