Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use std::invalid_argument instead of std::runtime_error (Sonar).
[simgrid.git] / examples / smpi / replay_multiple_manual_deploy / replay_multiple_manual.cpp
index 1b7330e..9aeb869 100644 (file)
 
 #include <algorithm>
 #include <fstream>
-#include <iostream>
+#include <sstream>
 #include <stdexcept>
 #include <vector>
 
 #include <boost/algorithm/string.hpp>
-#include <boost/filesystem.hpp>
-#include <boost/regex.hpp>
 
 #include <simgrid/msg.h>
 #include <simgrid/s4u.hpp>
 #include <smpi/smpi.h>
+#include <xbt/file.hpp>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(replay_multiple_manual, "Messages specific for this example");
 
@@ -174,30 +173,32 @@ static std::vector<Job*> all_jobs(const std::string& workload_file)
   xbt_assert(f.is_open(), "Cannot open file '%s'.", workload_file.c_str());
   std::vector<Job*> jobs;
 
-  boost::filesystem::path path(workload_file);
-  std::string dir = path.parent_path().native();
+  simgrid::xbt::Path path(workload_file);
+  std::string dir = path.get_dir_name();
 
-  boost::regex r(R"(^\s*(\S+)\s+(\S+\.txt)\s+(\d+)\s+(\d+)\s+(\d+(?:,\d+)*).*$)");
   std::string line;
   while (std::getline(f, line)) {
-    boost::smatch m;
-
-    if (boost::regex_match(line, m, r)) {
+    std::string app_name;
+    std::string filename_unprefixed;
+    int app_size;
+    int starting_time;
+    std::string alloc;
+
+    std::istringstream is(line);
+    if (is >> app_name >> filename_unprefixed >> app_size >> starting_time >> alloc) {
       try {
-        Job* job           = new Job;
-        job->smpi_app_name = m[1];
-        job->filename      = dir + "/" + std::string(m[2]);
-        job->app_size      = stoi(m[3]);
-        job->starting_time = stoi(m[4]);
-        std::string alloc  = m[5];
 
-        std::string filename_unprefixed = m[2];
+        Job* job           = new Job;
+        job->smpi_app_name = app_name;
+        job->filename      = dir + "/" + filename_unprefixed;
+        job->app_size      = app_size;
+        job->starting_time = starting_time;
 
         std::vector<std::string> subparts;
         boost::split(subparts, alloc, boost::is_any_of(","), boost::token_compress_on);
 
         if ((int)subparts.size() != job->app_size)
-          throw std::runtime_error("size/alloc inconsistency");
+          throw std::invalid_argument("size/alloc inconsistency");
 
         job->allocation.resize(subparts.size());
         for (unsigned int i = 0; i < subparts.size(); ++i)
@@ -206,7 +207,7 @@ static std::vector<Job*> all_jobs(const std::string& workload_file)
         // Let's read the filename
         std::ifstream traces_file(job->filename);
         if (!traces_file.is_open())
-          throw std::runtime_error("Cannot open file " + job->filename);
+          throw std::invalid_argument("Cannot open file " + job->filename);
 
         std::string traces_line;
         while (std::getline(traces_file, traces_line)) {
@@ -215,7 +216,7 @@ static std::vector<Job*> all_jobs(const std::string& workload_file)
         }
 
         if (static_cast<int>(job->traces_filenames.size()) < job->app_size)
-          throw std::runtime_error("size/tracefiles inconsistency");
+          throw std::invalid_argument("size/tracefiles inconsistency");
         job->traces_filenames.resize(job->app_size);
 
         XBT_INFO("Job read: app='%s', file='%s', size=%d, start=%d, "
@@ -223,8 +224,8 @@ static std::vector<Job*> all_jobs(const std::string& workload_file)
                  job->smpi_app_name.c_str(), filename_unprefixed.c_str(), job->app_size, job->starting_time,
                  alloc.c_str());
         jobs.push_back(job);
-      } catch (const std::exception& e) {
-        printf("Bad line '%s' of file '%s': %s.\n", line.c_str(), workload_file.c_str(), e.what());
+      } catch (const std::invalid_argument& e) {
+        xbt_die("Bad line '%s' of file '%s': %s.\n", line.c_str(), workload_file.c_str(), e.what());
       }
     }
   }