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 * The elements stored in such a data structure can be retrieve both by
21 * name and by ID. For this to work, the first fields of the structures
22 * stored must begin with:
23 * \verbatim unsigned int ID;
25 unsigned int name_len;\endverbatim
27 * It is impossible to remove an element from such a data structure.
30 * Such a datastructure was necessary/useful to store the GRAS type
31 * descriptions, but it should be reworked to become generic.
36 /** @defgroup XBT_set_cons Set and set elements, constructor/destructor
41 /** \brief Opaque type representing a set */
42 typedef struct xbt_set_ *xbt_set_t;
43 /** \brief It must be possible to cast set elements to this type */
45 unsigned int ID; /**< Identificator (system assigned) */
46 char *name; /**< Name (user assigned) */
47 unsigned int name_len;/**< Length of the name */
50 /*####[ Functions ]##########################################################*/
51 xbt_set_t xbt_set_new (void);
52 void xbt_set_free(xbt_set_t *set);
55 typedef struct xbt_set_elm_ s_xbt_set_elm_t;
56 typedef struct xbt_set_elm_ * xbt_set_elm_t;
57 /** @defgroup XBT_set_basic Sets basic usage
63 void xbt_set_add (xbt_set_t set, xbt_set_elm_t elm, void_f_pvoid_t *free_func);
65 xbt_set_elm_t xbt_set_get_by_name (xbt_set_t set, const char *key);
66 xbt_set_elm_t xbt_set_get_by_name_ext(xbt_set_t set, const char *key, int key_len);
67 xbt_set_elm_t xbt_set_get_by_id (xbt_set_t set, int id);
70 /** @defgroup XBT_set_curs Sets cursors
73 * \warning Don't add or remove entries to the cache while traversing
78 /** @brief Cursor type */
79 typedef struct xbt_set_cursor_ *xbt_set_cursor_t;
81 void xbt_set_cursor_first (xbt_set_t set,
82 xbt_set_cursor_t *cursor);
83 void xbt_set_cursor_step (xbt_set_cursor_t cursor);
84 int xbt_set_cursor_get_or_free (xbt_set_cursor_t *cursor,
87 /** @brief Iterates over the whole set
90 #define xbt_set_foreach(set,cursor,elm) \
91 for ((cursor) = NULL, xbt_set_cursor_first((set),&(cursor)) ; \
92 xbt_set_cursor_get_or_free(&(cursor),(xbt_set_elm_t*)&(elm)); \
93 xbt_set_cursor_step(cursor) )
98 #endif /* _XBT_SET_H */