Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make a function to know if the configuration is set by default or by command line.
authornavarrop <navarrop@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 20 Jan 2011 13:09:22 +0000 (13:09 +0000)
committernavarrop <navarrop@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 20 Jan 2011 13:09:22 +0000 (13:09 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9448 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/xbt/config.h
src/surf/surf_routing.c
src/xbt/config.c

index c652fcc..a352595 100644 (file)
@@ -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);
 
 /* 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
 /* @} */
 
 /** @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);
 
 /** \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);
 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);
 
 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
  /** @} */
 
 /** @defgroup XBT_cfg_register  Registering stuff
index b053b28..c3f9e79 100644 (file)
@@ -3251,14 +3251,12 @@ static void routing_parse_Sconfig(void)
 static void routing_parse_Econfig(void)
 {
   xbt_dict_cursor_t cursor = NULL;
 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);
   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);
                  xbt_cfg_set_parse(_surf_cfg_set, cfg);
          else
                  INFO1("The custom configuration '%s' is already define by user!",key);
index 56213d5..0585b49 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support");
 
 
 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);
 
 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
 /*----[ Memory management ]-----------------------------------------------*/
 
 /** @brief Constructor
@@ -407,7 +434,7 @@ void xbt_cfg_check(xbt_cfg_t cfg)
   xbt_dict_cursor_free(&cursor);
 }
 
   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)
 {
                                    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);
   }
 }
     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 ]---------------------------------------------------------*/
 
 
 /*----[ Getting ]---------------------------------------------------------*/