Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Acknoledge that some datasets are not regenerated yet, and deal with it
[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 /** \name Set and set elements
19     \ingroup XBT_set
20     generic dictionary
21 */
22 /*@{*/
23 typedef struct xbt_set_ *xbt_set_t; /**< Set */
24 typedef struct xbt_set_elm_ {
25   unsigned int ID;
26   char        *name;
27   unsigned int name_len;
28 } s_xbt_set_elm_t,*xbt_set_elm_t;   /**< Set element */
29
30 /*####[ Functions ]##########################################################*/
31
32 xbt_set_t xbt_set_new (void);
33 void xbt_set_free(xbt_set_t *set);
34
35
36 void xbt_set_add (xbt_set_t      set,
37                    xbt_set_elm_t  elm,
38                    void_f_pvoid_t *free_func);
39
40 /*----[ xbt_set_retrieve ]-------------------------------------------------*/
41 /* Search the given #key#. data=NULL when not found.                         */
42 /*---------------------------------------------------------------------------*/
43 xbt_error_t xbt_set_get_by_name    (xbt_set_t      set,
44                                       const char     *key,
45                                       /* OUT */xbt_set_elm_t *dst);
46 xbt_error_t xbt_set_get_by_name_ext(xbt_set_t      set,
47                                       const char     *name,
48                                       int             name_len,
49                                       /* OUT */xbt_set_elm_t *dst);
50 xbt_error_t xbt_set_get_by_id      (xbt_set_t      set,
51                                       int             id,
52                                       /* OUT */xbt_set_elm_t *dst);
53                                       
54 /*####[ Cache cursor functions ]#############################################*/
55 /* To traverse (simple) caches                                               */
56 /* Don't add or remove entries to the cache while traversing !!!             */
57 /*###########################################################################*/
58 typedef struct xbt_set_cursor_ *xbt_set_cursor_t;  /**< Set cursor */
59 /*@}*/
60
61 void         xbt_set_cursor_first       (xbt_set_t         set,
62                                           xbt_set_cursor_t *cursor);
63 void         xbt_set_cursor_step        (xbt_set_cursor_t  cursor);
64 int          xbt_set_cursor_get_or_free (xbt_set_cursor_t *cursor,
65                                           xbt_set_elm_t    *elm);
66
67 /**
68  \brief Set iterator
69  \ingroup XBT_set
70  * \param set what to iterate over
71  * \param cursor a #xbt_set_cursor_t used as cursor
72  * \param elm  a #xbt_set_elm_t
73  *
74  * Iterates over the whole set. 
75  */
76 #define xbt_set_foreach(set,cursor,elm)                       \
77   for ((cursor) = NULL, xbt_set_cursor_first((set),&(cursor)) ;   \
78        xbt_set_cursor_get_or_free(&(cursor),(xbt_set_elm_t*)&(elm));          \
79        xbt_set_cursor_step(cursor) )
80
81 END_DECL()
82
83 #endif /* _XBT_SET_H */