From: Martin Quinson Date: Wed, 15 Feb 2023 23:21:52 +0000 (+0100) Subject: Further factorization: introduce ModuleGroup::init_from_flag_value() X-Git-Tag: v3.34~528 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/479eed15b29c7f0ae552932aec832e80b2f2bb0c Further factorization: introduce ModuleGroup::init_from_flag_value() --- diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 8791ad7a1a..404709eb59 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -27,9 +27,7 @@ namespace simgrid::kernel::routing { /* Pick the right models for CPU, net and host, and call their model_init_preparse */ static void surf_config_models_setup() { - std::string host_model_name = simgrid::config::get_value("host/model"); - - simgrid_host_models().by_name(host_model_name).init(); + simgrid_host_models().init_from_flag_value(); XBT_DEBUG("Call vm_model_init"); /* TODO: ideally we should get back the pointer to CpuModel from init(), but this diff --git a/src/simgrid/module.cpp b/src/simgrid/module.cpp index 70b857f3f2..28647f390b 100644 --- a/src/simgrid/module.cpp +++ b/src/simgrid/module.cpp @@ -20,6 +20,7 @@ using namespace simgrid; void ModuleGroup::create_flag(const std::string& opt_name, const std::string& descr, const std::string& default_value, bool init_now) { + opt_name_ = opt_name; std::string description = descr + ". Possible values (other compilation flags may activate more " + get_kind() + "s): " + existing_values() + ".\n (use 'help' as a value to see the long description of each one)"; @@ -42,6 +43,10 @@ void ModuleGroup::create_flag(const std::string& opt_name, const std::string& de by_name(value); // Simply ensure that this value exists, it will be picked up later }); } +void ModuleGroup::init_from_flag_value() +{ + by_name(simgrid::config::get_value(opt_name_)).init(); +} ModuleGroup& ModuleGroup::add(const char* id, const char* desc, std::function init) { diff --git a/src/simgrid/module.hpp b/src/simgrid/module.hpp index 148daf1e23..ab175add49 100644 --- a/src/simgrid/module.hpp +++ b/src/simgrid/module.hpp @@ -27,6 +27,8 @@ struct Module { class ModuleGroup { std::vector table_; const std::string kind_; // either 'plugin' or 'CPU model' or whatever. Used in error messages only + std::string opt_name_; + public: ModuleGroup(const std::string& kind) : kind_(kind) {} @@ -37,6 +39,7 @@ public: std::string existing_values() const; void create_flag(const std::string& opt_name, const std::string& descr, const std::string& default_value, bool init_now); + void init_from_flag_value(); }; }; // namespace simgrid diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index fd55f13cb1..5fc159498c 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -22,12 +22,9 @@ SIMGRID_REGISTER_HOST_MODEL( engine->add_model(host_model); engine->get_netzone_root()->set_host_model(host_model); - std::string network_model_name = simgrid::config::get_value("network/model"); - std::string cpu_model_name = simgrid::config::get_value("cpu/model"); - std::string disk_model_name = simgrid::config::get_value("disk/model"); - simgrid_cpu_models().by_name(cpu_model_name).init(); - simgrid_disk_models().by_name(disk_model_name).init(); - simgrid_network_models().by_name(network_model_name).init(); + simgrid_cpu_models().init_from_flag_value(); + simgrid_disk_models().init_from_flag_value(); + simgrid_network_models().init_from_flag_value(); }); namespace simgrid::kernel::resource {