X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9f091df92f0ee7966a3a75ff8461a134c93214a9..14c1a28fbdd2bde4f727adfbd4745cc60995c8a3:/src/xbt/dict.c diff --git a/src/xbt/dict.c b/src/xbt/dict.c index 2f4e3a8ab5..37bc17511d 100644 --- a/src/xbt/dict.c +++ b/src/xbt/dict.c @@ -7,14 +7,9 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "xbt/ex.h" #include "dict_private.h" -#include /* malloc() */ -#include /* strlen() */ - -#include - - XBT_LOG_NEW_DEFAULT_SUBCATEGORY(dict,xbt, "Dictionaries provide the same functionnalities than hash tables"); /*####[ Private prototypes ]#################################################*/ @@ -46,7 +41,7 @@ xbt_dict_free(xbt_dict_t *dict) { xbt_dictelm_free( &( (*dict)->head ) ); (*dict)->head = NULL; } - xbt_free(*dict); + free(*dict); *dict=NULL; } } @@ -105,20 +100,18 @@ xbt_dict_set(xbt_dict_t dict, * \param dict the dealer of data * \param key the key to find data * \param key_len the size of the \a key - * \param data the data that we are looking for - * \return xbt_error + * \returns the data that we are looking for * - * Search the given \a key. mismatch_error when not found. + * Search the given \a key. throws not_found_error when not found. */ -xbt_error_t -xbt_dict_get_ext(xbt_dict_t dict, - const char *key, - int key_len, - /* OUT */void **data) { +void * +xbt_dict_get_ext(xbt_dict_t dict, + const char *key, + int key_len) { xbt_assert(dict); - return xbt_dictelm_get_ext(dict->head, key, key_len, data); + return xbt_dictelm_get_ext(dict->head, key, key_len); } /** @@ -126,18 +119,37 @@ xbt_dict_get_ext(xbt_dict_t dict, * * \param dict the dealer of data * \param key the key to find data - * \param data the data that we are looking for - * \return xbt_error + * \returns the data that we are looking for * - * Search the given \a key. mismatch_error when not found. + * Search the given \a key. THROWs mismatch_error when not found. + * Check xbt_dict_get_or_null() for a version returning NULL without exception when + * not found. */ -xbt_error_t +void * xbt_dict_get(xbt_dict_t dict, - const char *key, - /* OUT */void **data) { + const char *key) { xbt_assert(dict); - return xbt_dictelm_get(dict->head, key, data); + return xbt_dictelm_get(dict->head, key); +} + +/** + * \brief like xbt_dict_get(), but returning NULL when not found + */ +void * +xbt_dict_get_or_null(xbt_dict_t dict, + const char *key) { + xbt_ex_t e; + void *res; + TRY { + res = xbt_dictelm_get(dict->head, key); + } CATCH(e) { + if (e.category != not_found_error) + RETHROW; + xbt_ex_free(e); + res=NULL; + } + return res; } @@ -147,17 +159,17 @@ xbt_dict_get(xbt_dict_t dict, * \param dict the trash can * \param key the key of the data to be removed * \param key_len the size of the \a key - * \return xbt_error_t + * * - * Remove the entry associated with the given \a key + * Remove the entry associated with the given \a key (throws not_found) */ -xbt_error_t +void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, int key_len) { xbt_assert(dict); - return xbt_dictelm_remove_ext(dict->head, key, key_len); + xbt_dictelm_remove_ext(dict->head, key, key_len); } /** @@ -168,13 +180,13 @@ xbt_dict_remove_ext(xbt_dict_t dict, * * Remove the entry associated with the given \a key */ -xbt_error_t +void xbt_dict_remove(xbt_dict_t dict, const char *key) { - if (!dict) - RAISE1(mismatch_error,"Asked to remove key %s from NULL dict",key); + if (!dict) + THROW1(arg_error,0,"Asked to remove key %s from NULL dict",key); - return xbt_dictelm_remove(dict->head, key); + xbt_dictelm_remove(dict->head, key); }