Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Modifying the API so as to prevent a use of the context that would make valgrind...
[simgrid.git] / include / xbt / set.h
1 /* $Id$ */
2
3 /* xbt/set.h -- api to a generic dictionary                                 */
4
5 /* Copyright (c) 2004 Martin Quinson. All rights reserved.                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #ifndef _XBT_SET_H
11 #define _XBT_SET_H
12
13 #include "xbt/misc.h" /* BEGIN_DECL */
14
15 BEGIN_DECL
16
17 /*####[ Type definition ]####################################################*/
18 typedef struct xbt_set_ *xbt_set_t;
19 typedef struct xbt_set_elm_ {
20   unsigned int ID;
21   char        *name;
22   unsigned int name_len;
23 } s_xbt_set_elm_t,*xbt_set_elm_t;
24
25 /*####[ Functions ]##########################################################*/
26
27 xbt_set_t xbt_set_new (void);
28 void xbt_set_free(xbt_set_t *set);
29
30
31 void xbt_set_add (xbt_set_t      set,
32                    xbt_set_elm_t  elm,
33                    void_f_pvoid_t *free_func);
34
35 /*----[ xbt_set_retrieve ]-------------------------------------------------*/
36 /* Search the given #key#. data=NULL when not found.                         */
37 /*---------------------------------------------------------------------------*/
38 xbt_error_t xbt_set_get_by_name    (xbt_set_t      set,
39                                       const char     *key,
40                                       /* OUT */xbt_set_elm_t *dst);
41 xbt_error_t xbt_set_get_by_name_ext(xbt_set_t      set,
42                                       const char     *name,
43                                       int             name_len,
44                                       /* OUT */xbt_set_elm_t *dst);
45 xbt_error_t xbt_set_get_by_id      (xbt_set_t      set,
46                                       int             id,
47                                       /* OUT */xbt_set_elm_t *dst);
48                                       
49 /*####[ Cache cursor functions ]#############################################*/
50 /* To traverse (simple) caches                                               */
51 /* Don't add or remove entries to the cache while traversing !!!             */
52 /*###########################################################################*/
53 typedef struct xbt_set_cursor_ *xbt_set_cursor_t;
54
55 void         xbt_set_cursor_first       (xbt_set_t         set,
56                                           xbt_set_cursor_t *cursor);
57 void         xbt_set_cursor_step        (xbt_set_cursor_t  cursor);
58 int          xbt_set_cursor_get_or_free (xbt_set_cursor_t *cursor,
59                                           xbt_set_elm_t    *elm);
60
61 #define xbt_set_foreach(set,cursor,elm)                       \
62   for ((cursor) = NULL, xbt_set_cursor_first((set),&(cursor)) ;   \
63        xbt_set_cursor_get_or_free(&(cursor),(xbt_set_elm_t*)&(elm));          \
64        xbt_set_cursor_step(cursor) )
65
66 END_DECL
67
68 #endif /* _XBT_SET_H */