Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make simgrid::xbt::action_fs a std::unique_ptr.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 23 Nov 2020 11:00:22 +0000 (12:00 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 23 Nov 2020 11:00:22 +0000 (12:00 +0100)
examples/s4u/replay-comm/s4u-replay-comm.cpp
examples/s4u/replay-io/s4u-replay-io.cpp
include/xbt/replay.hpp
src/xbt/xbt_replay.cpp

index 5d3a430..cb33f3f 100644 (file)
@@ -8,6 +8,7 @@
 #include "xbt/str.h"
 #include <boost/algorithm/string/join.hpp>
 #include <cinttypes>
+#include <memory>
 #include <string>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(replay_comm, "Messages specific for this msg example");
@@ -101,16 +102,11 @@ int main(int argc, char* argv[])
   xbt_replay_action_register("recv", Replayer::recv);
 
   if (argv[3]) {
-    simgrid::xbt::action_fs = new std::ifstream(argv[3], std::ifstream::in);
+    simgrid::xbt::action_fs = std::make_unique<std::ifstream>(argv[3], std::ifstream::in);
   }
 
   e.run();
 
-  if (argv[3]) {
-    delete simgrid::xbt::action_fs;
-    simgrid::xbt::action_fs = nullptr;
-  }
-
   XBT_INFO("Simulation time %g", e.get_clock());
 
   return 0;
index c5fb26b..70327db 100644 (file)
@@ -115,16 +115,11 @@ int main(int argc, char* argv[])
   xbt_replay_action_register("close", Replayer::close);
 
   if (argv[3]) {
-    simgrid::xbt::action_fs = new std::ifstream(argv[3], std::ifstream::in);
+    simgrid::xbt::action_fs = std::make_unique<std::ifstream>(argv[3], std::ifstream::in);
   }
 
   e.run();
 
-  if (argv[3]) {
-    delete simgrid::xbt::action_fs;
-    simgrid::xbt::action_fs = nullptr;
-  }
-
   XBT_INFO("Simulation time %g", e.get_clock());
 
   return 0;
index d1596e5..94ce2e0 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <fstream>
 #include <functional>
+#include <memory>
 #include <queue>
 #include <unordered_map>
 
@@ -20,7 +21,7 @@ namespace xbt {
 /* To split the file if a unique one is given (specific variable for the other case live in runner()) */
 using ReplayAction = std::vector<std::string>;
 
-XBT_PUBLIC_DATA std::ifstream* action_fs;
+XBT_PUBLIC_DATA std::unique_ptr<std::ifstream> action_fs;
 XBT_PUBLIC int replay_runner(const char* actor_name, const char* trace_filename);
 }
 }
index c75acf1..254de60 100644 (file)
@@ -14,7 +14,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(replay,xbt,"Replay trace reader");
 namespace simgrid {
 namespace xbt {
 
-std::ifstream* action_fs = nullptr;
+std::unique_ptr<std::ifstream> action_fs = nullptr;
 std::unordered_map<std::string, action_fun> action_funs;
 static std::unordered_map<std::string, std::queue<ReplayAction*>*> action_queues;