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 /* Copyright (c) 2001,2002,2003,2004 Martin Quinson. All rights reserved. */
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. */
12 #ifndef _XBT_CONFIG_H_
13 #define _XBT_CONFIG_H_
15 #include "xbt/dynar.h"
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;
23 /* type of a typed hash cell */
25 xbt_cfgelm_int=0, xbt_cfgelm_double, xbt_cfgelm_string, xbt_cfgelm_host,
27 } e_xbt_cfgelm_type_t;
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);
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,
41 /* Unregister a possible cell */
42 xbt_error_t xbt_cfg_unregister(xbt_cfg_t cfg, const char *name);
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);
49 /* Check that each cell have the right amount of elements */
50 xbt_error_t xbt_cfg_check(xbt_cfg_t cfg);
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);
56 /*----[ Setting ]---------------------------------------------------------
57 * xbt_cfg_set_* functions.
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.
63 * string values are strdup'ed before use, so you have to free your copy */
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, ...);
69 Add the cells described in a string to a typed hash.
71 xbt_error_t xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options);
75 Set the value of the cell @name in @cfg with the provided value.
77 xbt_error_t xbt_cfg_set_int (xbt_cfg_t cfg, const char *name,
79 xbt_error_t xbt_cfg_set_double(xbt_cfg_t cfg, const char *name,
81 xbt_error_t xbt_cfg_set_string(xbt_cfg_t cfg, const char *name,
83 xbt_error_t xbt_cfg_set_host (xbt_cfg_t cfg, const char *name,
84 const char *host,int port);
87 Remove the provided value from the cell @name in @cfg.
89 xbt_error_t xbt_cfg_rm_int (xbt_cfg_t cfg, const char *name,
91 xbt_error_t xbt_cfg_rm_double(xbt_cfg_t cfg, const char *name,
93 xbt_error_t xbt_cfg_rm_string(xbt_cfg_t cfg, const char *name,
95 xbt_error_t xbt_cfg_rm_host (xbt_cfg_t cfg, const char *name,
96 const char *host,int port);
99 xbt_error_t xbt_cfg_empty(xbt_cfg_t cfg, const char *name);
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,
107 xbt_error_t xbt_cfg_get_double(xbt_cfg_t cfg,
110 xbt_error_t xbt_cfg_get_string(xbt_cfg_t cfg,
113 xbt_error_t xbt_cfg_get_host (xbt_cfg_t cfg,
117 xbt_error_t xbt_cfg_get_dynar (xbt_cfg_t cfg,
119 /* OUT */ xbt_dynar_t *dynar);
123 #endif /* _XBT_CONFIG_H_ */