Logo AND Algorithmique Numérique Distribuée

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