3 /* config - Dictionnary where the type of each cell is provided. */
5 /* This is useful to build named structs, like option or property sets. */
7 /* Authors: Martin Quinson */
8 /* Copyright (C) 2001,2002,2003,2004 da GRAS posse. */
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. */
13 #ifndef _XBT_CONFIG_H_
14 #define _XBT_CONFIG_H_
16 #include "xbt/dynar.h"
20 /* For now, a config is only a special dynar. But don't rely on it, */
21 /* it may change in the future. */
22 typedef xbt_dynar_t xbt_cfg_t;
24 /* type of a typed hash cell */
26 xbt_cfgelm_int=0, xbt_cfgelm_double, xbt_cfgelm_string, xbt_cfgelm_host,
28 } e_xbt_cfgelm_type_t;
30 /*----[ Memory management ]-----------------------------------------------*/
31 xbt_cfg_t xbt_cfg_new (void);
32 void xbt_cfg_cpy(xbt_cfg_t tocopy,
33 /* OUT */ xbt_cfg_t *whereto);
34 void xbt_cfg_free(xbt_cfg_t *cfg);
35 void xbt_cfg_dump(const char *name,const char*indent,xbt_cfg_t cfg);
37 /*----[ Registering stuff ]-----------------------------------------------*/
38 /* Register a possible cell */
39 void xbt_cfg_register(xbt_cfg_t cfg,
40 const char *name, e_xbt_cfgelm_type_t type,
42 /* Unregister a possible cell */
43 xbt_error_t xbt_cfg_unregister(xbt_cfg_t cfg, const char *name);
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 xbt_error_t xbt_cfg_register_str(xbt_cfg_t cfg, const char *entry);
50 /* Check that each cell have the right amount of elements */
51 xbt_error_t xbt_cfg_check(xbt_cfg_t cfg);
53 /* Get the type of this option in that repository */
54 xbt_error_t xbt_cfg_get_type(xbt_cfg_t cfg, const char *name,
55 /* OUT */ e_xbt_cfgelm_type_t *type);
57 /*----[ Setting ]---------------------------------------------------------
58 * xbt_cfg_set_* functions.
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.
64 * string values are strdup'ed before use, so you have to free your copy */
66 xbt_error_t xbt_cfg_set_vargs(xbt_cfg_t cfg, va_list pa);
67 xbt_error_t xbt_cfg_set(xbt_cfg_t cfg, ...);
70 Add the cells described in a string to a typed hash.
72 xbt_error_t xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options);
76 Set the value of the cell @name in @cfg with the provided value.
78 xbt_error_t xbt_cfg_set_int (xbt_cfg_t cfg, const char *name,
80 xbt_error_t xbt_cfg_set_double(xbt_cfg_t cfg, const char *name,
82 xbt_error_t xbt_cfg_set_string(xbt_cfg_t cfg, const char *name,
84 xbt_error_t xbt_cfg_set_host (xbt_cfg_t cfg, const char *name,
85 const char *host,int port);
88 Remove the provided value from the cell @name in @cfg.
90 xbt_error_t xbt_cfg_rm_int (xbt_cfg_t cfg, const char *name,
92 xbt_error_t xbt_cfg_rm_double(xbt_cfg_t cfg, const char *name,
94 xbt_error_t xbt_cfg_rm_string(xbt_cfg_t cfg, const char *name,
96 xbt_error_t xbt_cfg_rm_host (xbt_cfg_t cfg, const char *name,
97 const char *host,int port);
100 xbt_error_t xbt_cfg_empty(xbt_cfg_t cfg, const char *name);
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 xbt_error_t xbt_cfg_get_int (xbt_cfg_t cfg,
108 xbt_error_t xbt_cfg_get_double(xbt_cfg_t cfg,
111 xbt_error_t xbt_cfg_get_string(xbt_cfg_t cfg,
114 xbt_error_t xbt_cfg_get_host (xbt_cfg_t cfg,
118 xbt_error_t xbt_cfg_get_dynar (xbt_cfg_t cfg,
120 /* OUT */ xbt_dynar_t *dynar);
124 #endif /* _XBT_CONFIG_H_ */