-/*----[ 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 void 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,
- std::function<void(const char* value)> callback = std::function<void(const char* value)>())
-{
- 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);
-
- xbt_cfgelm_t res = (xbt_cfgelm_t) xbt_dict_get_or_null((xbt_dict_t) * cfg, name);
- xbt_assert(NULL == res, "Refusing to register the config element '%s' twice.", name);
-
- res = new s_xbt_cfgelm_t();
- 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;
- if (desc)
- res->desc = desc;
- res->cb_set = cb_set;
- res->callback = std::move(callback);
-
- switch (type) {
- case xbt_cfgelm_int:
- res->content = xbt_dynar_new(sizeof(int), NULL);
- break;
- case xbt_cfgelm_double:
- res->content = xbt_dynar_new(sizeof(double), NULL);
- break;
- case xbt_cfgelm_string:
- res->content = xbt_dynar_new(sizeof(char *), xbt_free_ref);
- break;
- case xbt_cfgelm_boolean:
- res->content = xbt_dynar_new(sizeof(int), NULL);
- break;
- default:
- XBT_ERROR("%d is an invalid type code", (int)type);
- break;
+ template<class T, class... A>
+ simgrid::config::TypedConfigurationElement<T>*
+ registerOption(const char* name, A&&... a)
+ {
+ xbt_assert(xbt_dict_get_or_null(this->options, name) == nullptr,
+ "Refusing to register the config element '%s' twice.", name);
+ TypedConfigurationElement<T>* variable =
+ new TypedConfigurationElement<T>(name, std::forward<A>(a)...);
+ XBT_DEBUG("Register cfg elm %s (%s) of type %s @%p in set %p)",
+ name,
+ variable->getDescription().c_str(),
+ variable->getTypeName(), variable, this);
+ xbt_dict_set(this->options, name, variable, nullptr);
+ variable->update();
+ return variable;