3 /* gras/set.h -- api to a generic dictionary */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2004 the OURAGAN project. */
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. */
19 /*####[ Type definition ]####################################################*/
20 typedef struct gras_set_ gras_set_t;
21 typedef struct gras_set_elm_ {
24 unsigned int name_len;
27 /*####[ Functions ]##########################################################*/
29 gras_error_t gras_set_new (gras_set_t **dst);
30 void gras_set_free(gras_set_t **set);
33 gras_error_t gras_set_add (gras_set_t *set,
35 void_f_pvoid_t *free_func);
37 /*----[ gras_set_retrieve ]-------------------------------------------------*/
38 /* Search the given #key#. data=NULL when not found. */
39 /*---------------------------------------------------------------------------*/
40 gras_error_t gras_set_get_by_name (gras_set_t *set,
42 /* OUT */gras_set_elm_t **dst);
43 gras_error_t gras_set_get_by_name_ext(gras_set_t *set,
46 /* OUT */gras_set_elm_t **dst);
47 gras_error_t gras_set_get_by_id (gras_set_t *set,
49 /* OUT */gras_set_elm_t **dst);
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 gras_set_cursor_ gras_set_cursor_t;
56 /* creator/destructor */
57 void gras_set_cursor_first (gras_set_t *set,
58 gras_set_cursor_t **cursor);
59 void gras_set_cursor_step (gras_set_cursor_t *cursor);
60 int gras_set_cursor_get_or_free (gras_set_cursor_t **cursor,
61 gras_set_elm_t **elm);
63 #define gras_set_foreach(set,cursor,elm) \
64 for (cursor=NULL, gras_set_cursor_first((set),&(cursor)) ; \
65 gras_set_cursor_get_or_free(&(cursor),(gras_set_elm_t**)&(elm)); \
66 gras_set_cursor_step(cursor) )
72 #endif /* _GRAS_SET_H */