Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make static stuff member of class Replayer.
[simgrid.git] / examples / s4u / replay-io / s4u-replay-io.cpp
index f5205e4..c5fb26b 100644 (file)
@@ -12,8 +12,6 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(replay_io, "Messages specific for this example");
 
-static std::unordered_map<std::string, simgrid::s4u::File*> opened_files;
-
 #define ACT_DEBUG(...)                                                                                                 \
   if (XBT_LOG_ISENABLED(replay_io, xbt_log_priority_verbose)) {                                                        \
     std::string NAME = boost::algorithm::join(action, " ");                                                            \
@@ -21,22 +19,23 @@ static std::unordered_map<std::string, simgrid::s4u::File*> opened_files;
   } else                                                                                                               \
     ((void)0)
 
-static void log_action(const simgrid::xbt::ReplayAction& action, double date)
-{
-  if (XBT_LOG_ISENABLED(replay_io, xbt_log_priority_verbose)) {
-    std::string s = boost::algorithm::join(action, " ");
-    XBT_VERB("%s %f", s.c_str(), date);
-  }
-}
+class Replayer {
+  static std::unordered_map<std::string, simgrid::s4u::File*> opened_files;
 
-static simgrid::s4u::File* get_file_descriptor(const std::string& file_name)
-{
-  std::string full_name = simgrid::s4u::this_actor::get_name() + ":" + file_name;
+  static void log_action(const simgrid::xbt::ReplayAction& action, double date)
+  {
+    if (XBT_LOG_ISENABLED(replay_io, xbt_log_priority_verbose)) {
+      std::string s = boost::algorithm::join(action, " ");
+      XBT_VERB("%s %f", s.c_str(), date);
+    }
+  }
 
-  return opened_files.at(full_name);
-}
+  static simgrid::s4u::File* get_file_descriptor(const std::string& file_name)
+  {
+    std::string full_name = simgrid::s4u::this_actor::get_name() + ":" + file_name;
+    return opened_files.at(full_name);
+  }
 
-class Replayer {
 public:
   explicit Replayer(std::vector<std::string> args)
   {
@@ -44,7 +43,7 @@ public:
     simgrid::xbt::replay_runner(actor_name, nullptr);
   }
 
-  void operator()()
+  void operator()() const
   {
     // Nothing to do here
   }
@@ -57,7 +56,7 @@ public:
     std::string full_name = simgrid::s4u::this_actor::get_name() + ":" + file_name;
 
     ACT_DEBUG("Entering Open: %s (filename: %s)", NAME.c_str(), file_name.c_str());
-    simgrid::s4u::File* file = new simgrid::s4u::File(file_name, NULL);
+    auto* file = new simgrid::s4u::File(file_name, nullptr);
 
     opened_files.insert({full_name, file});
 
@@ -92,6 +91,8 @@ public:
   }
 };
 
+std::unordered_map<std::string, simgrid::s4u::File*> Replayer::opened_files;
+
 int main(int argc, char* argv[])
 {
   simgrid::s4u::Engine e(&argc, argv);