X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a51412052680be35c70a5771242eb5a0a61b1dea..d96d4efee79291d1cef76c1c230e5dad1a138fb9:/src/xbt/config.cpp diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index cb26929e8c..9e896f35eb 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2004-2018. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -19,20 +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(); -} +XBT_EXPORT_NO_IMPORT xbt_cfg_t simgrid_config = nullptr; namespace simgrid { namespace config { @@ -265,7 +263,7 @@ private: bool warn_for_aliases = true; public: - Config() = default; + Config(); ~Config(); // No copy: @@ -299,6 +297,10 @@ protected: ConfigurationElement* getDictElement(const char* name); }; +Config::Config() +{ + atexit(&sg_config_finalize); +} Config::~Config() { XBT_DEBUG("Frees cfg set %p", this); @@ -379,16 +381,15 @@ void Config::help() // ***** getConfig ***** -template -XBT_PUBLIC(T const&) getConfig(const char* name) +template XBT_PUBLIC T const& getConfig(const char* name) { return (*simgrid_config)[name].getValue(); } -template XBT_PUBLIC(int const&) getConfig(const char* name); -template XBT_PUBLIC(double const&) getConfig(const char* name); -template XBT_PUBLIC(bool const&) getConfig(const char* name); -template XBT_PUBLIC(std::string const&) getConfig(const char* name); +template XBT_PUBLIC int const& getConfig(const char* name); +template XBT_PUBLIC double const& getConfig(const char* name); +template XBT_PUBLIC bool const& getConfig(const char* name); +template XBT_PUBLIC std::string const& getConfig(const char* name); // ***** alias ***** @@ -399,33 +400,32 @@ void alias(const char* realname, const char* aliasname) // ***** declareFlag ***** -template -XBT_PUBLIC(void) declareFlag(const char* name, const char* description, - T value, std::function callback) +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)); } -template XBT_PUBLIC(void) declareFlag(const char* name, - const char* description, int value, std::function callback); -template XBT_PUBLIC(void) declareFlag(const char* name, - const char* description, double value, std::function callback); -template XBT_PUBLIC(void) declareFlag(const char* name, - const char* description, bool value, std::function callback); -template XBT_PUBLIC(void) declareFlag(const char* name, - const char* description, std::string value, std::function callback); - +template XBT_PUBLIC void declareFlag(const char* name, const char* description, int value, + std::function callback); +template XBT_PUBLIC void declareFlag(const char* name, const char* description, double value, + std::function callback); +template XBT_PUBLIC void declareFlag(const char* name, const char* description, bool value, + std::function callback); +template XBT_PUBLIC void declareFlag(const char* name, const char* description, std::string value, + std::function callback); } } // ***** 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) @@ -445,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); } @@ -765,7 +757,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_cfg); XBT_TEST_SUITE("config", "Configuration support"); -XBT_PUBLIC_DATA(xbt_cfg_t) simgrid_config; +XBT_PUBLIC_DATA xbt_cfg_t simgrid_config; static void make_set() {