X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/eaaf15df4b2bd557800632665a9dee66378c192a..d96d4efee79291d1cef76c1c230e5dad1a138fb9:/src/xbt/config.cpp diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index 5ca3c34908..9e896f35eb 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -19,18 +19,18 @@ #include #include -#include -#include -#include +#include "simgrid/sg_config.hpp" +#include "xbt/dynar.h" +#include "xbt/log.h" #include "xbt/misc.h" #include "xbt/sysdep.h" -#include "xbt/log.h" -#include "xbt/dynar.h" +#include +#include +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support"); XBT_EXPORT_NO_IMPORT xbt_cfg_t simgrid_config = nullptr; -extern "C" XBT_PUBLIC void sg_config_finalize(); namespace simgrid { namespace config { @@ -263,7 +263,7 @@ private: bool warn_for_aliases = true; public: - Config() = default; + Config(); ~Config(); // No copy: @@ -297,6 +297,10 @@ protected: ConfigurationElement* getDictElement(const char* name); }; +Config::Config() +{ + atexit(&sg_config_finalize); +} Config::~Config() { XBT_DEBUG("Frees cfg set %p", this); @@ -399,10 +403,8 @@ void alias(const char* realname, const char* aliasname) template XBT_PUBLIC void declareFlag(const char* name, const char* description, T value, std::function callback) { - if (simgrid_config == nullptr) { + if (simgrid_config == nullptr) simgrid_config = xbt_cfg_new(); - atexit(sg_config_finalize); - } simgrid_config->registerOption( name, description, std::move(value), std::move(callback)); } @@ -420,7 +422,10 @@ template XBT_PUBLIC void declareFlag(const char* name, const char* description, // ***** C bindings ***** -xbt_cfg_t xbt_cfg_new() { return new simgrid::config::Config(); } +xbt_cfg_t xbt_cfg_new() +{ + return new simgrid::config::Config(); +} void xbt_cfg_free(xbt_cfg_t * cfg) { delete *cfg; } void xbt_cfg_dump(const char *name, const char *indent, xbt_cfg_t cfg) @@ -440,37 +445,29 @@ void xbt_cfg_register_double(const char *name, double default_value, void xbt_cfg_register_int(const char *name, int default_value,xbt_cfg_cb_t cb_set, const char *desc) { - if (simgrid_config == nullptr) { + if (simgrid_config == nullptr) simgrid_config = xbt_cfg_new(); - atexit(&sg_config_finalize); - } simgrid_config->registerOption(name, desc, default_value, cb_set); } void xbt_cfg_register_string(const char *name, const char *default_value, xbt_cfg_cb_t cb_set, const char *desc) { - if (simgrid_config == nullptr) { + if (simgrid_config == nullptr) simgrid_config = xbt_cfg_new(); - atexit(sg_config_finalize); - } simgrid_config->registerOption(name, desc, default_value ? default_value : "", cb_set); } void xbt_cfg_register_boolean(const char *name, const char*default_value,xbt_cfg_cb_t cb_set, const char *desc) { - if (simgrid_config == nullptr) { + if (simgrid_config == nullptr) simgrid_config = xbt_cfg_new(); - atexit(sg_config_finalize); - } simgrid_config->registerOption(name, desc, simgrid::config::parseBool(default_value), cb_set); } void xbt_cfg_register_alias(const char *realname, const char *aliasname) { - if (simgrid_config == nullptr) { + if (simgrid_config == nullptr) simgrid_config = xbt_cfg_new(); - atexit(sg_config_finalize); - } simgrid_config->alias(realname, aliasname); }