From 44c4094c8c81f3d5c7f97c646432115b7a4debb2 Mon Sep 17 00:00:00 2001 From: navarrop Date: Thu, 20 Jan 2011 13:09:22 +0000 Subject: [PATCH] Make a function to know if the configuration is set by default or by command line. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9448 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/xbt/config.h | 29 +++-------------------------- src/surf/surf_routing.c | 4 +--- src/xbt/config.c | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/include/xbt/config.h b/include/xbt/config.h index c652fcc486..a3525950e3 100644 --- a/include/xbt/config.h +++ b/include/xbt/config.h @@ -141,6 +141,9 @@ XBT_PUBLIC(void) xbt_cfg_rm_at(xbt_cfg_t cfg, const char *name, int pos); /* rm every values */ XBT_PUBLIC(void) xbt_cfg_empty(xbt_cfg_t cfg, const char *name); +/* Return if configuration is set by default*/ +XBT_PUBLIC(int) xbt_cfg_is_default_value(xbt_cfg_t cfg, const char *name); + /* @} */ /** @defgroup XBT_cfg_decl Configuration type declaration and memory management @@ -166,29 +169,6 @@ typedef enum { /** \brief Callback types. They get the name of the modified entry, and the position of the changed value */ typedef void (*xbt_cfg_cb_t) (const char *, int); -/* xbt_cfgelm_t: the typedef corresponding to a config variable. - - Both data and DTD are mixed, but fixing it now would prevent me to ever - defend my thesis. */ - -typedef struct { - /* Description */ - char *desc; - - /* Allowed type of the variable */ - e_xbt_cfgelm_type_t type; - int min, max; - int isdefault:1; - - /* Callbacks */ - xbt_cfg_cb_t cb_set; - xbt_cfg_cb_t cb_rm; - - /* actual content - (cannot be an union because type peer uses both str and i) */ - xbt_dynar_t content; -} s_xbt_cfgelm_t, *xbt_cfgelm_t; - XBT_PUBLIC(xbt_cfg_t) xbt_cfg_new(void); XBT_PUBLIC(void) xbt_cfg_cpy(xbt_cfg_t tocopy, /* OUT */ xbt_cfg_t * whereto); @@ -196,9 +176,6 @@ XBT_PUBLIC(void) xbt_cfg_free(xbt_cfg_t * cfg); XBT_PUBLIC(void) xbt_cfg_dump(const char *name, const char *indent, xbt_cfg_t cfg); -/* Retrieve the variable we'll modify */ -XBT_PUBLIC(xbt_cfgelm_t) xbt_cfgelm_get(xbt_cfg_t cfg, const char *name, - e_xbt_cfgelm_type_t type); /** @} */ /** @defgroup XBT_cfg_register Registering stuff diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index b053b28ea9..c3f9e7916e 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -3251,14 +3251,12 @@ static void routing_parse_Sconfig(void) static void routing_parse_Econfig(void) { xbt_dict_cursor_t cursor = NULL; - xbt_cfgelm_t variable; char *key; char *elem; char *cfg; xbt_dict_foreach(current_property_set, cursor, key, elem) { cfg = bprintf("%s:%s",key,elem); - variable = xbt_cfgelm_get(_surf_cfg_set, key, xbt_cfgelm_any); - if(variable->isdefault) + if(xbt_cfg_is_default_value(_surf_cfg_set, key)) xbt_cfg_set_parse(_surf_cfg_set, cfg); else INFO1("The custom configuration '%s' is already define by user!",key); diff --git a/src/xbt/config.c b/src/xbt/config.c index 56213d5a16..0585b4955a 100644 --- a/src/xbt/config.c +++ b/src/xbt/config.c @@ -21,12 +21,39 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support"); +/* xbt_cfgelm_t: the typedef corresponding to a config variable. + + Both data and DTD are mixed, but fixing it now would prevent me to ever + defend my thesis. */ + +typedef struct { + /* Description */ + char *desc; + + /* Allowed type of the variable */ + e_xbt_cfgelm_type_t type; + int min, max; + int isdefault:1; + + /* Callbacks */ + xbt_cfg_cb_t cb_set; + xbt_cfg_cb_t cb_rm; + + /* actual content + (cannot be an union because type peer uses both str and i) */ + xbt_dynar_t content; +} s_xbt_cfgelm_t, *xbt_cfgelm_t; + static const char *xbt_cfgelm_type_name[xbt_cfgelm_type_count] = { "int", "double", "string", "peer", "any" }; /* Internal stuff used in cache to free a variable */ static void xbt_cfgelm_free(void *data); +/* Retrieve the variable we'll modify */ +static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg, const char *name, + e_xbt_cfgelm_type_t type); + /*----[ Memory management ]-----------------------------------------------*/ /** @brief Constructor @@ -407,7 +434,7 @@ void xbt_cfg_check(xbt_cfg_t cfg) xbt_dict_cursor_free(&cursor); } -xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg, +static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg, const char *name, e_xbt_cfgelm_type_t type) { @@ -1118,6 +1145,14 @@ void xbt_cfg_empty(xbt_cfg_t cfg, const char *name) xbt_dynar_reset(variable->content); } } +/* + * Say if the value is the default value + */ +int xbt_cfg_is_default_value(xbt_cfg_t cfg, const char *name) +{ + xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_any); + return variable->isdefault; +} /*----[ Getting ]---------------------------------------------------------*/ -- 2.20.1