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
free(entrycpy); /* strdup'ed by dict mechanism, but cannot be const */
}
+static int strcmp_voidp(const void *pa, const void *pb)
+{
+ return strcmp(*(const char **)pa, *(const char **)pb);
+}
+
/** @brief Displays the declared options and their description */
void xbt_cfg_help(xbt_cfg_t cfg)
{
- xbt_dict_cursor_t cursor;
+ xbt_dict_cursor_t dict_cursor;
+ unsigned int dynar_cursor;
xbt_cfgelm_t variable;
char *name;
+ xbt_dynar_t names = xbt_dynar_new(sizeof(char *), NULL);
- int i;
- int size;
+ xbt_dict_foreach((xbt_dict_t )cfg, dict_cursor, name, variable) {
+ xbt_dynar_push(names, &name);
+ }
+ xbt_dynar_sort(names, strcmp_voidp);
+
+ xbt_dynar_foreach(names, dynar_cursor, name) {
+ int i;
+ int size;
+ variable = xbt_dict_get((xbt_dict_t )cfg, name);
- xbt_dict_foreach((xbt_dict_t) cfg, cursor, name, variable) {
printf(" %s: %s\n", name, variable->desc);
printf(" Type: %s; ", xbt_cfgelm_type_name[variable->type]);
if (variable->min != 1 || variable->max != 1) {
}
}
+
+ xbt_dynar_free(&names);
}
/** @brief Check that each variable have the right amount of values */
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)
{
}
*(val++) = '\0';
- if(strcmp(name,"simix/context"))
- INFO2("Configuration change: Set '%s' to '%s'", name, val);
+ if (strcmp(name,"contexts/factory"))
+ INFO2("Configuration change: Set '%s' to '%s'", name, val);
TRY {
variable = xbt_dict_get((xbt_dict_t) cfg, 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 ]---------------------------------------------------------*/