Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define an Engine constructor taking only a name parameter.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 4 May 2021 08:57:09 +0000 (10:57 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 4 May 2021 12:18:15 +0000 (14:18 +0200)
It will by useful for unit tests.

include/simgrid/s4u/Engine.hpp
src/s4u/s4u_Engine.cpp

index a608f2e..2dfacd3 100644 (file)
@@ -27,6 +27,8 @@ class XBT_PUBLIC Engine {
   friend simgrid::kernel::EngineImpl;
 
 public:
+  /** Constructor, taking only the name of your main function */
+  explicit Engine(std::string name);
   /** Constructor, taking the command line parameters of your main function */
   explicit Engine(int* argc, char** argv);
   /* Currently, only one instance is allowed to exist. This is why you can't copy or move it */
@@ -199,6 +201,7 @@ public:
 private:
   kernel::EngineImpl* const pimpl;
   static Engine* instance_;
+  void initialize(int* argc, char** argv);
 };
 
 #ifndef DOXYGEN /* Internal use only, no need to expose it */
index 2d94c66..2d980c9 100644 (file)
@@ -37,15 +37,26 @@ xbt::signal<void(void)> Engine::on_deadlock;
 
 Engine* Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */
 
-Engine::Engine(int* argc, char** argv) : pimpl(new kernel::EngineImpl())
+void Engine::initialize(int* argc, char** argv)
 {
   xbt_assert(Engine::instance_ == nullptr, "It is currently forbidden to create more than one instance of s4u::Engine");
   instr::init();
   SIMIX_global_init(argc, argv);
-
   Engine::instance_ = this;
 }
 
+Engine::Engine(std::string name) : pimpl(new kernel::EngineImpl())
+{
+  int argc   = 1;
+  char* argv = &name[0];
+  initialize(&argc, &argv);
+}
+
+Engine::Engine(int* argc, char** argv) : pimpl(new kernel::EngineImpl())
+{
+  initialize(argc, argv);
+}
+
 Engine::~Engine()
 {
   delete pimpl;