3 /* xbt/set.h -- api to a generic dictionary */
5 /* Copyright (c) 2004 Martin Quinson. All rights reserved. */
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. */
13 #include "xbt/misc.h" /* BEGIN_DECL */
17 /*####[ Type definition ]####################################################*/
18 /** \name Set and set elements
23 typedef struct xbt_set_ *xbt_set_t; /**< Set */
24 typedef struct xbt_set_elm_ {
27 unsigned int name_len;
28 } s_xbt_set_elm_t,*xbt_set_elm_t; /**< Set element */
30 /*####[ Functions ]##########################################################*/
32 xbt_set_t xbt_set_new (void);
33 void xbt_set_free(xbt_set_t *set);
36 void xbt_set_add (xbt_set_t set,
38 void_f_pvoid_t *free_func);
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,
45 /* OUT */xbt_set_elm_t *dst);
46 xbt_error_t xbt_set_get_by_name_ext(xbt_set_t set,
49 /* OUT */xbt_set_elm_t *dst);
50 xbt_error_t xbt_set_get_by_id (xbt_set_t set,
52 /* OUT */xbt_set_elm_t *dst);
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 */
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,
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
74 * Iterates over the whole set.
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) )
83 #endif /* _XBT_SET_H */