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" /* SG_BEGIN_DECL */
17 /** @addtogroup XBT_set
18 * @brief A data container consisting in \ref XBT_dict and \ref XBT_dynar
20 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref XBT_API]
21 * <tr><td><b>Prev</b> <td> [\ref XBT_dict]
22 * <tr><td><b>Next</b> <td> [\ref XBT_fifo]
23 * <tr><td><b>Down</b> <td> [\ref XBT_set_cons] </table></center>
25 * The elements stored in such a data structure can be retrieve both by
26 * name and by ID. For this to work, the first fields of the structures
27 * stored must begin with:
28 * \verbatim unsigned int ID;
30 unsigned int name_len;\endverbatim
32 * It is impossible to remove an element from such a data structure.
35 * Such a datastructure was necessary/useful to store the GRAS type
36 * descriptions, but it should be reworked to become generic.
41 /** @defgroup XBT_set_cons Set and set elements, constructor/destructor
44 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref XBT_API]::[\ref XBT_set]
46 * <tr><td><b>Next</b> <td> [\ref XBT_set_basic] </table></center>
50 /** \brief Opaque type representing a set */
51 typedef struct xbt_set_ *xbt_set_t;
52 /** \brief It must be possible to cast set elements to this type */
54 unsigned int ID; /**< Identificator (system assigned) */
55 char *name; /**< Name (user assigned) */
56 unsigned int name_len;/**< Length of the name */
59 /*####[ Functions ]##########################################################*/
60 xbt_set_t xbt_set_new (void);
61 void xbt_set_free(xbt_set_t *set);
64 typedef struct xbt_set_elm_ s_xbt_set_elm_t;
65 typedef struct xbt_set_elm_ * xbt_set_elm_t;
66 /** @defgroup XBT_set_basic Sets basic usage
69 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref XBT_API]::[\ref XBT_set]
70 * <tr><td><b>Prev</b> <td> [\ref XBT_set_cons]
71 * <tr><td><b>Next</b> <td> [\ref XBT_set_curs] </table></center>
76 void xbt_set_add (xbt_set_t set, xbt_set_elm_t elm, void_f_pvoid_t *free_func);
78 xbt_set_elm_t xbt_set_get_by_name (xbt_set_t set, const char *key);
79 xbt_set_elm_t xbt_set_get_by_name_ext(xbt_set_t set, const char *key, int key_len);
80 xbt_set_elm_t xbt_set_get_by_id (xbt_set_t set, int id);
83 /** @defgroup XBT_set_curs Sets cursors
86 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref XBT_API]::[\ref XBT_set]
87 * <tr><td><b>Prev</b> <td> [\ref XBT_set_basic]
88 * <tr><td> Next <td> </table></center>
90 * \warning Don't add or remove entries to the cache while traversing
95 /** @brief Cursor type */
96 typedef struct xbt_set_cursor_ *xbt_set_cursor_t;
98 void xbt_set_cursor_first (xbt_set_t set,
99 xbt_set_cursor_t *cursor);
100 void xbt_set_cursor_step (xbt_set_cursor_t cursor);
101 int xbt_set_cursor_get_or_free (xbt_set_cursor_t *cursor,
104 /** @brief Iterates over the whole set
107 #define xbt_set_foreach(set,cursor,elm) \
108 for ((cursor) = NULL, xbt_set_cursor_first((set),&(cursor)) ; \
109 xbt_set_cursor_get_or_free(&(cursor),(xbt_set_elm_t*)&(elm)); \
110 xbt_set_cursor_step(cursor) )
115 #endif /* _XBT_SET_H */