Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add the set, continue to mess with datadesc
[simgrid.git] / include / set.h
1 /* $Id$ */
2
3 /* gras/set.h -- api to a generic dictionary                                */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2004 the OURAGAN project.                                  */
7
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. */
10
11
12 #ifndef _GRAS_SET_H
13 #define _GRAS_SET_H
14
15 #ifdef  __cplusplus
16 extern "C" 
17 #endif
18
19 /*####[ Type definition ]####################################################*/
20 typedef struct gras_set_ gras_set_t;
21 typedef struct gras_set_elm_ {
22   unsigned int ID;
23   char        *name;
24   unsigned int name_len;
25 } gras_set_elm_t;
26
27 /*####[ Functions ]##########################################################*/
28
29 gras_error_t gras_set_new (gras_set_t **dst);
30 void         gras_set_free(gras_set_t **set);
31
32
33 gras_error_t gras_set_add    (gras_set_t     *set,
34                               gras_set_elm_t *elm,
35                               void_f_pvoid_t *free_func);
36
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,
41                                       const char     *key,
42                                       /* OUT */gras_set_elm_t **dst);
43 gras_error_t gras_set_get_by_name_ext(gras_set_t     *set,
44                                       const char     *name,
45                                       int             name_len,
46                                       /* OUT */gras_set_elm_t **dst);
47 gras_error_t gras_set_get_by_id      (gras_set_t     *set,
48                                       int             id,
49                                       /* OUT */gras_set_elm_t **dst);
50                                       
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);
62
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) )
67
68 #ifdef  __cplusplus
69 }
70 #endif
71
72 #endif /* _GRAS_SET_H */