Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a4ff04f5706cf60bb3503d140298d6e4f21d7f7a
[simgrid.git] / include / xbt / config.h
1 /* $Id$ */
2
3 /* config - Dictionnary where the type of each cell is provided.            */
4
5 /* This is useful to build named structs, like option or property sets.     */
6
7 /* Authors: Martin Quinson                                                  */
8 /* Copyright (C) 2001,2002,2003,2004 the OURAGAN project.                   */
9
10 /* This program is free software; you can redistribute it and/or modify it
11    under the terms of the license (GNU LGPL) which comes with this package. */
12
13 #ifndef _GRAS_CONFIG_H_
14 #define _GRAS_CONFIG_H_
15
16 /* For now, a config is only a special dynar. But don't rely on it, */
17 /* it may change in the future. */
18 typedef gras_dynar_t gras_cfg_t;
19
20 /* type of a typed hash cell */
21 typedef enum {
22   gras_cfgelm_int=0, gras_cfgelm_double, gras_cfgelm_string, gras_cfgelm_host,
23   gras_cfgelm_type_count
24 } gras_cfgelm_type_t;
25
26 /*----[ Memory management ]-----------------------------------------------*/
27 gras_cfg_t *gras_cfg_new (void);
28 void gras_cfg_cpy(gras_cfg_t **whereto, gras_cfg_t *tocopy);
29 void gras_cfg_free(gras_cfg_t **cfg);
30 void gras_cfg_dump(const char *name,const char*indent,gras_cfg_t *cfg);
31
32 /*----[ Registering stuff ]-----------------------------------------------*/
33 /* Register a possible cell */
34 void gras_cfg_register(gras_cfg_t *cfg,
35                        const char *name, gras_cfgelm_type_t type,
36                        int min, int max);
37 /* Unregister a possible cell */
38 gras_error_t gras_cfg_unregister(gras_cfg_t *cfg, const char *name);
39
40 /* Parse the configuration descriptor and register it */
41 /* Should be of the form "<name>:<min nb>_to_<max nb>_<type>", */
42 /*  with type being one of 'string','int', 'host' or 'double'  */
43 gras_error_t gras_cfg_register_str(gras_cfg_t *cfg, const char *entry);
44
45 /* Check that each cell have the right amount of elements */
46 gras_error_t gras_cfg_check(gras_cfg_t *cfg);
47
48 /* Get the type of this option in that repository */
49 gras_error_t gras_cfg_get_type(gras_cfg_t *cfg, const char *name, 
50                                /* OUT */ gras_cfgelm_type_t *type);
51
52 /*----[ Setting ]---------------------------------------------------------
53  * gras_cfg_set_* functions.
54  *
55  * If the registered maximum is equal to 1, those functions remplace the 
56  * current value with the provided one. If max>1, the provided value is 
57  * appended to the list.
58  *
59  * string values are strdup'ed before use, so you have to free your copy  */
60
61 gras_error_t gras_cfg_set_vargs(gras_cfg_t *cfg, va_list pa);
62 gras_error_t gras_cfg_set(gras_cfg_t *cfg, ...);
63
64 /*
65   Add the cells described in a string to a typed hash.
66  */
67 gras_error_t gras_cfg_set_parse(gras_cfg_t *cfg, const char *options);
68
69
70 /*
71   Set the value of the cell @name in @cfg with the provided value.
72  */
73 gras_error_t gras_cfg_set_int   (gras_cfg_t *cfg, const char *name, 
74                                  int val);
75 gras_error_t gras_cfg_set_double(gras_cfg_t *cfg, const char *name, 
76                                  double val);
77 gras_error_t gras_cfg_set_string(gras_cfg_t *cfg, const char *name, 
78                                  const char *val);
79 gras_error_t gras_cfg_set_host  (gras_cfg_t *cfg, const char *name, 
80                                  const char *host,int port);
81
82 /*
83  Remove the provided value from the cell @name in @cfg.
84  */
85 gras_error_t gras_cfg_rm_int   (gras_cfg_t *cfg, const char *name, 
86                                 int val);
87 gras_error_t gras_cfg_rm_double(gras_cfg_t *cfg, const char *name, 
88                                 double val);
89 gras_error_t gras_cfg_rm_string(gras_cfg_t *cfg, const char *name, 
90                                 const char *val);
91 gras_error_t gras_cfg_rm_host  (gras_cfg_t *cfg, const char *name, 
92                                 const char *host,int port);
93
94 /* rm every values */
95 gras_error_t gras_cfg_empty(gras_cfg_t *cfg, const char *name); 
96
97 /*----[ Getting ]---------------------------------------------------------*/
98 /* Returns a pointer to the values actually stored in the cache. Do not   */
99 /* modify them unless you really know what you're doing.                  */
100 gras_error_t gras_cfg_get_int   (gras_cfg_t *cfg,
101                                  const char *name,
102                                  int        *val);
103 gras_error_t gras_cfg_get_double(gras_cfg_t *cfg,
104                                  const char *name,
105                                  double     *val);
106 gras_error_t gras_cfg_get_string(gras_cfg_t *cfg,
107                                  const char *name, 
108                                  char      **val);
109 gras_error_t gras_cfg_get_host  (gras_cfg_t *cfg, 
110                                  const char *name, 
111                                  char      **host,
112                                  int        *port);
113 gras_error_t gras_cfg_get_dynar (gras_cfg_t    *cfg,
114                                  const char    *name,
115                                  gras_dynar_t **dynar);
116
117
118 #endif /* _GRAS_CONFIG_H_ */