Logo AND Algorithmique Numérique Distribuée

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