Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
define max only when not previously defined (win32 defines it); move xbt_abort to...
[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 /* Copyright (c) 2001,2002,2003,2004 Martin Quinson. All rights reserved.   */
8
9 /* This program is free software; you can redistribute it and/or modify it
10  * under the terms of the license (GNU LGPL) which comes with this package. */
11
12 #ifndef _XBT_CONFIG_H_
13 #define _XBT_CONFIG_H_
14
15 #include "xbt/dynar.h"
16
17 BEGIN_DECL
18   
19 /* For now, a config is only a special dynar. But don't rely on it, */
20 /* it may change in the future. */
21 typedef xbt_dynar_t xbt_cfg_t;
22
23 /* type of a typed hash cell */
24 typedef enum {
25   xbt_cfgelm_int=0, xbt_cfgelm_double, xbt_cfgelm_string, xbt_cfgelm_host,
26   xbt_cfgelm_type_count
27 } e_xbt_cfgelm_type_t;
28
29 /*----[ Memory management ]-----------------------------------------------*/
30 xbt_cfg_t xbt_cfg_new (void);
31 void xbt_cfg_cpy(xbt_cfg_t tocopy,
32         /* OUT */ xbt_cfg_t *whereto);
33 void xbt_cfg_free(xbt_cfg_t *cfg);
34 void xbt_cfg_dump(const char *name,const char*indent,xbt_cfg_t cfg);
35
36 /*----[ Registering stuff ]-----------------------------------------------*/
37 /* Register a possible cell */
38 void xbt_cfg_register(xbt_cfg_t cfg,
39                        const char *name, e_xbt_cfgelm_type_t type,
40                        int min, int max);
41 /* Unregister a possible cell */
42 xbt_error_t xbt_cfg_unregister(xbt_cfg_t cfg, const char *name);
43
44 /* Parse the configuration descriptor and register it */
45 /* Should be of the form "<name>:<min nb>_to_<max nb>_<type>", */
46 /*  with type being one of 'string','int', 'host' or 'double'  */
47 xbt_error_t xbt_cfg_register_str(xbt_cfg_t cfg, const char *entry);
48
49 /* Check that each cell have the right amount of elements */
50 xbt_error_t xbt_cfg_check(xbt_cfg_t cfg);
51
52 /* Get the type of this option in that repository */
53 xbt_error_t xbt_cfg_get_type(xbt_cfg_t cfg, const char *name, 
54                                /* OUT */ e_xbt_cfgelm_type_t *type);
55
56 /*----[ Setting ]---------------------------------------------------------
57  * xbt_cfg_set_* functions.
58  *
59  * If the registered maximum is equal to 1, those functions remplace the 
60  * current value with the provided one. If max>1, the provided value is 
61  * appended to the list.
62  *
63  * string values are strdup'ed before use, so you have to free your copy  */
64
65 xbt_error_t xbt_cfg_set_vargs(xbt_cfg_t cfg, va_list pa);
66 xbt_error_t xbt_cfg_set(xbt_cfg_t cfg, ...);
67
68 /*
69   Add the cells described in a string to a typed hash.
70  */
71 xbt_error_t xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options);
72
73
74 /*
75   Set the value of the cell @name in @cfg with the provided value.
76  */
77 xbt_error_t xbt_cfg_set_int   (xbt_cfg_t cfg, const char *name, 
78                                  int val);
79 xbt_error_t xbt_cfg_set_double(xbt_cfg_t cfg, const char *name, 
80                                  double val);
81 xbt_error_t xbt_cfg_set_string(xbt_cfg_t cfg, const char *name, 
82                                  const char *val);
83 xbt_error_t xbt_cfg_set_host  (xbt_cfg_t cfg, const char *name, 
84                                  const char *host,int port);
85
86 /*
87  Remove the provided value from the cell @name in @cfg.
88  */
89 xbt_error_t xbt_cfg_rm_int   (xbt_cfg_t cfg, const char *name, 
90                                 int val);
91 xbt_error_t xbt_cfg_rm_double(xbt_cfg_t cfg, const char *name, 
92                                 double val);
93 xbt_error_t xbt_cfg_rm_string(xbt_cfg_t cfg, const char *name, 
94                                 const char *val);
95 xbt_error_t xbt_cfg_rm_host  (xbt_cfg_t cfg, const char *name, 
96                                 const char *host,int port);
97
98 /* rm every values */
99 xbt_error_t xbt_cfg_empty(xbt_cfg_t cfg, const char *name);     
100
101 /*----[ Getting ]---------------------------------------------------------*/
102 /* Returns a pointer to the values actually stored in the cache. Do not   */
103 /* modify them unless you really know what you're doing.                  */
104 xbt_error_t xbt_cfg_get_int   (xbt_cfg_t  cfg,
105                                  const char *name,
106                                  int        *val);
107 xbt_error_t xbt_cfg_get_double(xbt_cfg_t  cfg,
108                                  const char *name,
109                                  double     *val);
110 xbt_error_t xbt_cfg_get_string(xbt_cfg_t  cfg,
111                                  const char *name, 
112                                  char      **val);
113 xbt_error_t xbt_cfg_get_host  (xbt_cfg_t  cfg, 
114                                  const char *name, 
115                                  char      **host,
116                                  int        *port);
117 xbt_error_t xbt_cfg_get_dynar (xbt_cfg_t    cfg,
118                                  const char   *name,
119                        /* OUT */ xbt_dynar_t *dynar);
120
121 END_DECL
122   
123 #endif /* _XBT_CONFIG_H_ */