Currently, it does not do much more than its xbt_dict_t.
* @{
*/
/** @brief Configuration set's data type is opaque. */
* @{
*/
/** @brief Configuration set's data type is opaque. */
+#ifdef __cplusplus
+namespace simgrid {
+namespace config {
+class Config;
+}
+}
+typedef simgrid::config::Config* xbt_cfg_t;
+#else
XBT_PUBLIC(void) xbt_cfg_set(xbt_cfg_t cfg, const char *name, ...);
XBT_PUBLIC(void) xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa);
XBT_PUBLIC(void) xbt_cfg_set(xbt_cfg_t cfg, const char *name, ...);
XBT_PUBLIC(void) xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa);
+struct Config {
+ xbt_dict_t options;
+
+ Config();
+ ~Config();
+
+ // No copy:
+ Config(Config const&) = delete;
+ Config& operator=(Config const&) = delete;
+};
+
+/* Internal stuff used in cache to free a variable */
+static void xbt_cfgelm_free(void *data)
+{
+ if (data)
+ delete (simgrid::config::ConfigurationElement*) data;
+}
+
+Config::Config() :
+ options(xbt_dict_new_homogeneous(xbt_cfgelm_free))
+{}
+
+Config::~Config()
+{
+ XBT_DEBUG("Frees cfg set %p", this);
+ xbt_dict_free(&this->options);
+}
+
-/* Internal stuff used in cache to free a variable */
-static void xbt_cfgelm_free(void *data)
-{
- if (data)
- delete (simgrid::config::ConfigurationElement*) data;
-}
-
/* Retrieve the variable we'll modify */
static simgrid::config::ConfigurationElement* xbt_cfgelm_get(xbt_cfg_t cfg, const char *name, e_xbt_cfgelm_type_t type);
/* Retrieve the variable we'll modify */
static simgrid::config::ConfigurationElement* xbt_cfgelm_get(xbt_cfg_t cfg, const char *name, e_xbt_cfgelm_type_t type);
*/
xbt_cfg_t xbt_cfg_new(void)
{
*/
xbt_cfg_t xbt_cfg_new(void)
{
- return (xbt_cfg_t) xbt_dict_new_homogeneous(&xbt_cfgelm_free);
+ return new simgrid::config::Config();
}
/** @brief Destructor */
void xbt_cfg_free(xbt_cfg_t * cfg)
{
}
/** @brief Destructor */
void xbt_cfg_free(xbt_cfg_t * cfg)
{
- XBT_DEBUG("Frees cfg set %p", cfg);
- xbt_dict_free((xbt_dict_t *) cfg);
}
/** @brief Dump a config set for debuging purpose
}
/** @brief Dump a config set for debuging purpose
*/
void xbt_cfg_dump(const char *name, const char *indent, xbt_cfg_t cfg)
{
*/
void xbt_cfg_dump(const char *name, const char *indent, xbt_cfg_t cfg)
{
- xbt_dict_t dict = (xbt_dict_t) cfg;
+ xbt_dict_t dict = cfg->options;
xbt_dict_cursor_t cursor = NULL;
simgrid::config::ConfigurationElement* variable = NULL;
char *key = NULL;
xbt_dict_cursor_t cursor = NULL;
simgrid::config::ConfigurationElement* variable = NULL;
char *key = NULL;
"type of %s not valid (%d should be between %d and %d)",
name, (int)type, xbt_cfgelm_int, 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((xbt_dict_t) * cfg, name);
+ 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_assert(NULL == res, "Refusing to register the config element '%s' twice.", name);
res = new simgrid::config::ConfigurationElement();
- xbt_dict_set((xbt_dict_t) * cfg, name, res, NULL);
+ xbt_dict_set((*cfg)->options, name, res, NULL);
}
void xbt_cfg_register_double(const char *name, double default_value,xbt_cfg_cb_t cb_set, const char *desc){
}
void xbt_cfg_register_double(const char *name, double default_value,xbt_cfg_cb_t cb_set, const char *desc){
if (simgrid_config == NULL)
simgrid_config = xbt_cfg_new();
if (simgrid_config == NULL)
simgrid_config = xbt_cfg_new();
- simgrid::config::ConfigurationElement* res = (simgrid::config::ConfigurationElement*) xbt_dict_get_or_null((xbt_dict_t) simgrid_config, oldname);
+ 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);
xbt_assert(NULL == res, "Refusing to register the option '%s' twice.", oldname);
- res = (simgrid::config::ConfigurationElement*) xbt_dict_get_or_null((xbt_dict_t) simgrid_config, newname);
+ 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_assert(res, "Cannot define an alias to the non-existing option '%s'.", newname);
res = new simgrid::config::ConfigurationElement();
res->type = xbt_cfgelm_alias;
res->content = (xbt_dynar_t)newname;
res->type = xbt_cfgelm_alias;
res->content = (xbt_dynar_t)newname;
- xbt_dict_set((xbt_dict_t) simgrid_config, oldname, res, NULL);
+ xbt_dict_set(simgrid_config->options, oldname, res, NULL);
char *name;
xbt_dynar_t names = xbt_dynar_new(sizeof(char *), NULL);
char *name;
xbt_dynar_t names = xbt_dynar_new(sizeof(char *), NULL);
- xbt_dict_foreach((xbt_dict_t )simgrid_config, dict_cursor, name, variable)
+ xbt_dict_foreach(simgrid_config->options, dict_cursor, name, variable)
xbt_dynar_push(names, &name);
xbt_dynar_sort_strings(names);
xbt_dynar_foreach(names, dynar_cursor, name) {
xbt_dynar_push(names, &name);
xbt_dynar_sort_strings(names);
xbt_dynar_foreach(names, dynar_cursor, name) {
- variable = (simgrid::config::ConfigurationElement*) xbt_dict_get((xbt_dict_t )simgrid_config, name);
+ variable = (simgrid::config::ConfigurationElement*) xbt_dict_get(simgrid_config->options, name);
if (variable->type == xbt_cfgelm_alias)
printf(" %s: %s\n", name, variable->desc.c_str());
if (variable->type == xbt_cfgelm_alias)
printf(" %s: %s\n", name, variable->desc.c_str());
char *name;
xbt_dynar_t names = xbt_dynar_new(sizeof(char *), NULL);
char *name;
xbt_dynar_t names = xbt_dynar_new(sizeof(char *), NULL);
- xbt_dict_foreach((xbt_dict_t )simgrid_config, dict_cursor, name, variable)
+ xbt_dict_foreach(simgrid_config->options, dict_cursor, name, variable)
xbt_dynar_push(names, &name);
xbt_dynar_sort_strings(names);
xbt_dynar_foreach(names, dynar_cursor, name) {
int size;
xbt_dynar_push(names, &name);
xbt_dynar_sort_strings(names);
xbt_dynar_foreach(names, dynar_cursor, name) {
int size;
- variable = (simgrid::config::ConfigurationElement*) xbt_dict_get((xbt_dict_t )simgrid_config, name);
+ variable = (simgrid::config::ConfigurationElement*) xbt_dict_get(simgrid_config->options, name);
if (variable->type == xbt_cfgelm_alias)
continue;
if (variable->type == xbt_cfgelm_alias)
continue;
static simgrid::config::ConfigurationElement* xbt_cfgelm_get(xbt_cfg_t cfg, const char *name, e_xbt_cfgelm_type_t type)
{
static simgrid::config::ConfigurationElement* xbt_cfgelm_get(xbt_cfg_t cfg, const char *name, e_xbt_cfgelm_type_t type)
{
- simgrid::config::ConfigurationElement* res = (simgrid::config::ConfigurationElement*) xbt_dict_get_or_null((xbt_dict_t) cfg, name);
+ simgrid::config::ConfigurationElement* res = (simgrid::config::ConfigurationElement*) xbt_dict_get_or_null(cfg->options, name);
// The user used the old name. Switch to the new one after a short warning
while (res && res->type == xbt_cfgelm_alias) {
// The user used the old name. Switch to the new one after a short warning
while (res && res->type == xbt_cfgelm_alias) {
{
simgrid::config::ConfigurationElement* variable = NULL;
{
simgrid::config::ConfigurationElement* variable = NULL;
- variable = (simgrid::config::ConfigurationElement*) xbt_dict_get_or_null((xbt_dict_t) cfg, name);
+ variable = (simgrid::config::ConfigurationElement*) xbt_dict_get_or_null(cfg->options, name);
if (!variable)
THROWF(not_found_error, 0, "Can't get the type of '%s' since this variable does not exist", name);
if (!variable)
THROWF(not_found_error, 0, "Can't get the type of '%s' since this variable does not exist", name);
TRY {
while (variable == NULL) {
TRY {
while (variable == NULL) {
- variable = (simgrid::config::ConfigurationElement*) xbt_dict_get((xbt_dict_t) simgrid_config, key);
+ variable = (simgrid::config::ConfigurationElement*) xbt_dict_get(simgrid_config->options, key);
if (variable->type == xbt_cfgelm_alias) {
const char *newname = (const char*)variable->content;
XBT_INFO("Note: configuration '%s' is deprecated. Please use '%s' instead.", key, newname);
if (variable->type == xbt_cfgelm_alias) {
const char *newname = (const char*)variable->content;
XBT_INFO("Note: configuration '%s' is deprecated. Please use '%s' instead.", key, newname);