From 83a986331633ba19391ce14e6605a5b423311ad7 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 19 Apr 2018 17:39:07 +0200 Subject: [PATCH 1/1] Convert last bits from the xbt/config C interface. --- include/xbt.h | 3 +++ include/xbt/config.h | 11 +++++---- include/xbt/config.hpp | 6 ++++- src/include/simgrid/sg_config.hpp | 2 -- src/instr/instr_paje_containers.cpp | 2 -- src/instr/instr_paje_events.cpp | 2 -- src/mc/mc_config.cpp | 2 +- src/s4u/s4u_engine.cpp | 1 - src/simgrid/sg_config.cpp | 7 +++--- src/simix/smx_environment.cpp | 2 +- src/xbt/config.cpp | 36 +++++++++++++++++++++-------- src/xbt/xbt_main.cpp | 2 +- 12 files changed, 46 insertions(+), 30 deletions(-) diff --git a/include/xbt.h b/include/xbt.h index 073344b2c1..96c0bddea2 100644 --- a/include/xbt.h +++ b/include/xbt.h @@ -24,6 +24,9 @@ #include #include +#ifdef __cplusplus +#include +#endif #include #include diff --git a/include/xbt/config.h b/include/xbt/config.h index df1cedb43a..18d17ce9e8 100644 --- a/include/xbt/config.h +++ b/include/xbt/config.h @@ -110,9 +110,10 @@ XBT_ATTRIB_DEPRECATED_v323("Please use simgrid::config::is_default") XBT_PUBLIC /** \brief Callback types. They get the name of the modified entry, and the position of the changed value */ typedef void (*xbt_cfg_cb_t)(const char* name); -XBT_PUBLIC xbt_cfg_t xbt_cfg_new(); -XBT_PUBLIC void xbt_cfg_free(xbt_cfg_t* cfg); -XBT_PUBLIC void xbt_cfg_dump(const char* name, const char* indent, xbt_cfg_t cfg); +XBT_ATTRIB_DEPRECATED_v323("Please don't use it") XBT_PUBLIC xbt_cfg_t xbt_cfg_new(); +XBT_ATTRIB_DEPRECATED_v323("Please don't use it") XBT_PUBLIC void xbt_cfg_free(xbt_cfg_t* cfg); +XBT_ATTRIB_DEPRECATED_v323("Please don't use it") XBT_PUBLIC + void xbt_cfg_dump(const char* name, const char* indent, xbt_cfg_t cfg); /** @} */ @@ -134,8 +135,8 @@ XBT_ATTRIB_DEPRECATED_v323("Please use simgrid::config::declare_flag") XBT XBT_ATTRIB_DEPRECATED_v323("Please use simgrid::config::alias") XBT_PUBLIC void xbt_cfg_register_alias(const char* newname, const char* oldname); -XBT_PUBLIC void xbt_cfg_aliases(); -XBT_PUBLIC void xbt_cfg_help(); +XBT_ATTRIB_DEPRECATED_v323("Please use simgrid::config::show_aliases") XBT_PUBLIC void xbt_cfg_aliases(); +XBT_ATTRIB_DEPRECATED_v323("Please use simgrid::config::help") XBT_PUBLIC void xbt_cfg_help(); /* @} */ /** @defgroup XBT_cfg_get Getting the stored values diff --git a/include/xbt/config.hpp b/include/xbt/config.hpp index 48fd59fec7..10cdc39aa4 100644 --- a/include/xbt/config.hpp +++ b/include/xbt/config.hpp @@ -19,12 +19,13 @@ #include #include -#include #include namespace simgrid { namespace config { +class Config; + template inline std::string to_string(T&& value) { @@ -279,6 +280,9 @@ public: bool operator>=(U const& that) const { return value_ >= that; } }; +XBT_PUBLIC void finalize(); +XBT_PUBLIC void show_aliases(); +XBT_PUBLIC void help(); } } XBT_ATTRIB_DEPRECATED_v323("Please use simgrid::config::get_value") XBT_PUBLIC std::string diff --git a/src/include/simgrid/sg_config.hpp b/src/include/simgrid/sg_config.hpp index a11602fc29..998d72491d 100644 --- a/src/include/simgrid/sg_config.hpp +++ b/src/include/simgrid/sg_config.hpp @@ -6,12 +6,10 @@ #ifndef SIMGRID_CONFIG_HPP #define SIMGRID_CONFIG_HPP -#include "xbt/config.h" #include "xbt/config.hpp" /** Config Globals */ -XBT_PUBLIC_DATA xbt_cfg_t simgrid_config; XBT_PUBLIC_DATA int _sg_cfg_init_status; XBT_PUBLIC_DATA int _sg_cfg_exit_asap; diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 9ecaa544fd..8b29f80e8e 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -3,8 +3,6 @@ /* 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. */ -#include - #include "simgrid/s4u/Engine.hpp" #include "simgrid/s4u/Host.hpp" #include "src/instr/instr_private.hpp" diff --git a/src/instr/instr_paje_events.cpp b/src/instr/instr_paje_events.cpp index 267c16da00..6373f40d06 100644 --- a/src/instr/instr_paje_events.cpp +++ b/src/instr/instr_paje_events.cpp @@ -3,8 +3,6 @@ /* 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. */ -#include - #include "src/instr/instr_private.hpp" #include "src/instr/instr_smpi.hpp" #include "src/smpi/include/private.hpp" diff --git a/src/mc/mc_config.cpp b/src/mc/mc_config.cpp index 4aebb9bd62..3aa17e3526 100644 --- a/src/mc/mc_config.cpp +++ b/src/mc/mc_config.cpp @@ -3,7 +3,7 @@ /* 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. */ -#include "xbt/config.h" +#include "xbt/config.hpp" #include "xbt/log.h" #include diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index f928ff7949..0510bbb5a1 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -18,7 +18,6 @@ #include "src/kernel/EngineImpl.hpp" #include "src/surf/network_interface.hpp" #include "surf/surf.hpp" // routing_platf. FIXME:KILLME. SOON -#include "xbt/config.hpp" XBT_LOG_NEW_CATEGORY(s4u,"Log channels of the S4U (Simgrid for you) interface"); diff --git a/src/simgrid/sg_config.cpp b/src/simgrid/sg_config.cpp index 86c1a6f439..c16b0c630f 100644 --- a/src/simgrid/sg_config.cpp +++ b/src/simgrid/sg_config.cpp @@ -14,7 +14,6 @@ #include "src/mc/mc_replay.hpp" #include "src/surf/surf_interface.hpp" #include "surf/surf.hpp" -#include "xbt/config.h" #include "xbt/config.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf, "About the configuration of SimGrid"); @@ -51,7 +50,7 @@ static void sg_config_cmd_line(int *argc, char **argv) shall_exit = 1; } else if (not strcmp(argv[i], "--cfg-help") || not strcmp(argv[i], "--help")) { printf("Description of the configuration accepted by this simulator:\n"); - xbt_cfg_help(); + simgrid::config::help(); printf( "\n" "Each of these configurations can be used by adding\n" @@ -69,7 +68,7 @@ static void sg_config_cmd_line(int *argc, char **argv) shall_exit = 1; } else if (not strcmp(argv[i], "--help-aliases")) { printf("Here is a list of all deprecated option names, with their replacement.\n"); - xbt_cfg_aliases(); + simgrid::config::show_aliases(); printf("Please consider using the recent names\n"); shall_exit = 1; } else if (not strcmp(argv[i], "--help-models")) { @@ -472,6 +471,6 @@ void sg_config_finalize() if (not _sg_cfg_init_status) return; /* Not initialized yet. Nothing to do */ - xbt_cfg_free(&simgrid_config); + simgrid::config::finalize(); _sg_cfg_init_status = 0; } diff --git a/src/simix/smx_environment.cpp b/src/simix/smx_environment.cpp index eb475f5631..3a97ce8a73 100644 --- a/src/simix/smx_environment.cpp +++ b/src/simix/smx_environment.cpp @@ -5,7 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "smx_private.hpp" -#include "xbt/config.h" +#include "xbt/config.hpp" #include "xbt/log.h" #include "xbt/sysdep.h" #include "xbt/xbt_os_time.h" diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index 92f041272b..4c3b69eba1 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -459,7 +459,7 @@ template XBT_PUBLIC void declare_flag(const char* name, const char* description, T value, std::function callback) { if (simgrid_config == nullptr) - simgrid_config = xbt_cfg_new(); + simgrid_config = new simgrid::config::Config(); simgrid_config->register_option(name, description, std::move(value), std::move(callback)); } @@ -471,6 +471,22 @@ template XBT_PUBLIC void declare_flag(const char* name, const char* description, std::function callback); template XBT_PUBLIC void declare_flag(const char* name, const char* description, std::string value, std::function callback); + +void finalize() +{ + delete simgrid_config; + simgrid_config = nullptr; +} + +void show_aliases() +{ + simgrid_config->show_aliases(); +} + +void help() +{ + simgrid_config->help(); +} } } @@ -493,35 +509,35 @@ void xbt_cfg_register_double(const char *name, double default_value, xbt_cfg_cb_t cb_set, const char *desc) { if (simgrid_config == nullptr) - simgrid_config = xbt_cfg_new(); + simgrid_config = new simgrid::config::Config(); simgrid_config->register_option(name, desc, default_value, cb_set); } void xbt_cfg_register_int(const char *name, int default_value,xbt_cfg_cb_t cb_set, const char *desc) { if (simgrid_config == nullptr) - simgrid_config = xbt_cfg_new(); + simgrid_config = new simgrid::config::Config(); simgrid_config->register_option(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) - simgrid_config = xbt_cfg_new(); + simgrid_config = new simgrid::config::Config(); simgrid_config->register_option(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) - simgrid_config = xbt_cfg_new(); + simgrid_config = new simgrid::config::Config(); simgrid_config->register_option(name, desc, simgrid::config::parse_bool(default_value), cb_set); } void xbt_cfg_register_alias(const char *realname, const char *aliasname) { if (simgrid_config == nullptr) - simgrid_config = xbt_cfg_new(); + simgrid_config = new simgrid::config::Config(); simgrid_config->alias(realname, aliasname); } @@ -713,7 +729,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 simgrid::config::Config* simgrid_config; static void make_set() { @@ -730,7 +746,7 @@ XBT_TEST_UNIT("memuse", test_config_memuse, "Alloc and free a config set") make_set(); xbt_test_add("Alloc and free a config set"); simgrid::config::set_parse("peername:veloce user:bidule"); - xbt_cfg_free(&simgrid_config); + simgrid::config::finalize(); simgrid_config = temp; } @@ -756,7 +772,7 @@ XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests") xbt_test_exception(e); } } - xbt_cfg_free(&simgrid_config); + simgrid::config::finalize(); simgrid_config = temp; } @@ -780,7 +796,7 @@ XBT_TEST_UNIT("c++flags", test_config_cxx_flags, "C++ flags") xbt_test_assert(bool_flag1, "Check bool1 flag"); xbt_test_assert(not bool_flag2, "Check bool2 flag"); - xbt_cfg_free(&simgrid_config); + simgrid::config::finalize(); simgrid_config = temp; } diff --git a/src/xbt/xbt_main.cpp b/src/xbt/xbt_main.cpp index 20be974e6d..3faed87abc 100644 --- a/src/xbt/xbt_main.cpp +++ b/src/xbt/xbt_main.cpp @@ -8,7 +8,7 @@ #define XBT_LOG_LOCALLY_DEFINE_XBT_CHANNEL /* MSVC don't want it to be declared extern in headers and local here */ #include "simgrid_config.h" -#include "xbt/config.h" +#include "xbt/config.hpp" #include "xbt/dynar.h" #include "xbt/log.h" #include "xbt/log.hpp" -- 2.20.1