X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a21c6f99b54f0893807db95245ba0a05a5afc1c3..9788cd051f72b982ec571c96e84577e9749188b1:/src/xbt/lib.c diff --git a/src/xbt/lib.c b/src/xbt/lib.c index 1141f8d6a0..cc6f9e6163 100644 --- a/src/xbt/lib.c +++ b/src/xbt/lib.c @@ -1,6 +1,6 @@ /* lib - a generic library, variation over dictionary */ -/* Copyright (c) 2011. The SimGrid Team. +/* Copyright (c) 2011, 2013. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -17,7 +17,7 @@ xbt_lib_t xbt_lib_new(void) { xbt_lib_t lib; lib = xbt_new(s_xbt_lib_t, 1); - lib->dict = xbt_dict_new(); + lib->dict = xbt_dict_new_homogeneous(xbt_free); lib->levels = 0; lib->free_f = NULL; return lib; @@ -60,7 +60,7 @@ void xbt_lib_set(xbt_lib_t lib, const char *key, int level, void *obj) void **elts = xbt_dict_get_or_null(lib->dict, key); if (!elts) { elts = xbt_new0(void *, lib->levels); - xbt_dict_set(lib->dict, key, elts, xbt_free); + xbt_dict_set(lib->dict, key, elts, NULL); } if (elts[level]) { XBT_DEBUG("Replace %p by %p element under key '%s:%d'", @@ -75,3 +75,13 @@ void *xbt_lib_get_or_null(xbt_lib_t lib, const char *key, int level) void **elts = xbt_dict_get_or_null(lib->dict, key); return elts ? elts[level] : NULL; } + +xbt_dictelm_t xbt_lib_get_elm_or_null(xbt_lib_t lib, const char *key) +{ + return xbt_dict_get_elm_or_null(lib->dict, key); +} + +void *xbt_lib_get_level(xbt_dictelm_t elm, int level){ + void **elts = elm->content; + return elts ? elts[level] : NULL; +}