-/*----[ Registering stuff ]-----------------------------------------------*/
-/** @brief Register an element within a config set
- *
- * @param cfg the config set
- * @param name the name of the config element
- * @param desc a description for this item (used by xbt_cfg_help())
- * @param type the type of the config element
- * @param cb_set callback function called when a value is set
- */
-static simgrid::config::ConfigurationElement* xbt_cfg_register(
- xbt_cfg_t * cfg, const char *name, const char *desc, e_xbt_cfgelm_type_t type, xbt_cfg_cb_t cb_set)
-{
- if (*cfg == NULL)
- *cfg = xbt_cfg_new();
- xbt_assert(type >= xbt_cfgelm_int && type <= xbt_cfgelm_boolean,
- "type of %s not valid (%d should be between %d and %d)",
- name, (int)type, xbt_cfgelm_int, xbt_cfgelm_boolean);
-
- simgrid::config::ConfigurationElement* res = (simgrid::config::ConfigurationElement*) xbt_dict_get_or_null((*cfg)->options, name);
- xbt_assert(NULL == res, "Refusing to register the config element '%s' twice.", name);
-
- res = new simgrid::config::ConfigurationElement();
- XBT_DEBUG("Register cfg elm %s (%s) (%s (=%d) @%p in set %p)",
- name, desc, xbt_cfgelm_type_name[type], (int)type, res, *cfg);
- res->type = type;
- res->cb_set = cb_set;
- if (desc)
- res->desc = desc;
-
- // Set a default default value:
- switch (type) {
- case xbt_cfgelm_int:
- res->int_content = 0;
- break;
- case xbt_cfgelm_double:
- res->double_content = 0.0;
- break;
- case xbt_cfgelm_string:
- res->string_content = nullptr;
- break;
- case xbt_cfgelm_boolean:
- res->boolean_content = false;
- break;
- default:
- XBT_ERROR("%d is an invalid type code", (int)type);
- break;
- }
-
- xbt_dict_set((*cfg)->options, name, res, NULL);
- return res;
-}
-
-void xbt_cfg_register_double(const char *name, double default_value,xbt_cfg_cb_t cb_set, const char *desc)
-{
- xbt_cfg_register(&simgrid_config, name, desc, xbt_cfgelm_double, cb_set);
- xbt_cfg_setdefault_double(name, default_value);
-}
-void xbt_cfg_register_int(const char *name, int default_value,xbt_cfg_cb_t cb_set, const char *desc)
-{
- xbt_cfg_register(&simgrid_config, name, desc, xbt_cfgelm_int, cb_set);
- xbt_cfg_setdefault_int(name, default_value);
-}
-void xbt_cfg_register_string(const char *name, const char *default_value, xbt_cfg_cb_t cb_set, const char *desc)
-{
- xbt_cfg_register(&simgrid_config,name,desc,xbt_cfgelm_string,cb_set);
- xbt_cfg_setdefault_string(name, default_value);
-}
-void xbt_cfg_register_boolean(const char *name, const char*default_value,xbt_cfg_cb_t cb_set, const char *desc)
-{
- xbt_cfg_register(&simgrid_config,name,desc,xbt_cfgelm_boolean,cb_set);
- xbt_cfg_setdefault_boolean(name, default_value);
-}
-
-void xbt_cfg_register_alias(const char *newname, const char *oldname)
-{
- if (simgrid_config == NULL)
- simgrid_config = xbt_cfg_new();
-
- simgrid::config::ConfigurationElement* res = (simgrid::config::ConfigurationElement*) xbt_dict_get_or_null(simgrid_config->options, oldname);
- xbt_assert(NULL == res, "Refusing to register the option '%s' twice.", oldname);
-
- res = (simgrid::config::ConfigurationElement*) xbt_dict_get_or_null(simgrid_config->options, newname);
- xbt_assert(res, "Cannot define an alias to the non-existing option '%s'.", newname);
-
- res = new simgrid::config::ConfigurationElement();
- XBT_DEBUG("Register cfg alias %s -> %s)",oldname,newname);
-
- res->desc = std::string("Deprecated alias for ")+std::string(newname);
- res->type = xbt_cfgelm_alias;
- res->string_content = xbt_strdup(newname);
-
- xbt_dict_set(simgrid_config->options, oldname, res, NULL);
-}
-
-/**
- * @brief Parse a string and register the stuff described.
- *
- * @param cfg the config set
- * @param entry a string describing the element to register
- *
- * The string may consist in several variable descriptions separated by a space.
- * Each of them must use the following syntax: \<name\>:\<type\>
- * with type being one of 'string','int','bool' or 'double'.
- *
- * Note that this does not allow to set the description, so you should prefer the other interface
- */
-void xbt_cfg_register_str(xbt_cfg_t * cfg, const char *entry)
-{
- char *entrycpy = xbt_strdup(entry);
- char *tok;
-
- e_xbt_cfgelm_type_t type;
- XBT_DEBUG("Register string '%s'", entry);
-
- tok = strchr(entrycpy, ':');
- xbt_assert(tok, "Invalid config element descriptor: %s; Should be <name>:<type>", entry);
- *(tok++) = '\0';
-
- for (type = (e_xbt_cfgelm_type_t)0; type < xbt_cfgelm_type_count && strcmp(tok, xbt_cfgelm_type_name[type]); increment(type));
- xbt_assert(type < xbt_cfgelm_type_count,
- "Invalid type in config element descriptor: %s; Should be one of 'string', 'int' or 'double'.", entry);
-
- xbt_cfg_register(cfg, entrycpy, NULL, type, NULL);
-
- free(entrycpy); /* strdup'ed by dict mechanism, but cannot be const */
-}
-