Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
factorize the flags of models and plugins
[simgrid.git] / src / simgrid / module.cpp
index c160aea..45cf4a8 100644 (file)
@@ -6,6 +6,7 @@
 #include <xbt/asserts.h>
 #include <xbt/log.h>
 
+#include "simgrid/sg_config.hpp"
 #include "src/simgrid/module.hpp"
 #include "src/surf/surf_interface.hpp"
 
@@ -16,6 +17,32 @@ XBT_LOG_EXTERNAL_CATEGORY(xbt_help);
 
 using namespace simgrid;
 
+void ModuleGroup::create_flag(const std::string& opt_name, const std::string& descr, const std::string& default_value,
+                              bool init_now)
+{
+  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)";
+
+  simgrid::config::declare_flag<std::string>(
+      opt_name, description, default_value, [this, default_value, init_now](const std::string& value) {
+        xbt_assert(_sg_cfg_init_status < 2, "Cannot load a %s after the initialization", kind_.c_str());
+
+        if (value == default_value)
+          return;
+
+        if (value == "help") {
+          help();
+          exit(0);
+        }
+
+        if (init_now)
+          by_name(value).init();
+        else
+          by_name(value); // Simply ensure that this value exists, it will be picked up later
+      });
+}
+
 ModuleGroup& ModuleGroup::add(const char* id, const char* desc, std::function<void()> init)
 {
   table_.emplace_back(Module(id, desc, init));