Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
xbt_str_split --
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 13 Mar 2017 09:39:30 +0000 (10:39 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 13 Mar 2017 10:28:17 +0000 (11:28 +0100)
src/surf/trace_mgr.cpp

index ddd0708..5455bdb 100644 (file)
@@ -5,16 +5,19 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "xbt/sysdep.h"
+#include "xbt/dict.h"
 #include "xbt/log.h"
 #include "xbt/str.h"
-#include "xbt/dict.h"
+
 #include "src/surf/trace_mgr.hpp"
 #include "src/surf/surf_interface.hpp"
 #include "surf_private.h"
 #include "xbt/RngStream.h"
+#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/join.hpp>
+#include <boost/algorithm/string/split.hpp>
 #include <math.h>
 #include <unordered_map>
-#include <boost/algorithm/string/join.hpp>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_trace, surf, "Surf trace management");
 
@@ -33,26 +36,24 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *name, const char *input, dou
 {
   int linecount = 0;
   tmgr_event_t last_event = nullptr;
-  unsigned int cpt;
-  char *val;
 
   xbt_assert(trace_list.find(name) == trace_list.end(), "Refusing to define trace %s twice", name);
   xbt_assert(periodicity >= 0, "Invalid periodicity %g (must be positive)", periodicity);
 
   tmgr_trace_t trace = new simgrid::trace_mgr::trace();
 
-  xbt_dynar_t list = xbt_str_split(input, "\n\r");
-  xbt_dynar_foreach(list, cpt, val) {
+  std::vector<std::string> list;
+  boost::split(list, input, boost::is_any_of("\n\r"));
+  for (auto val : list) {
     s_tmgr_event_t event;
     linecount++;
-    xbt_str_trim(val, " \t\n\r\x0B");
+    boost::trim(val);
     if (val[0] == '#' || val[0] == '\0' || val[0] == '%') // pass comments
       continue;
-
-    if (sscanf(val, "PERIODICITY " "%lg" "\n", &periodicity) == 1)
+    if (sscanf(val.c_str(), "PERIODICITY " "%lg" "\n", &periodicity) == 1)
       continue;
 
-    xbt_assert(sscanf(val, "%lg" " " "%lg" "\n", &event.delta, &event.value) == 2,
+    xbt_assert(sscanf(val.c_str(), "%lg" " " "%lg" "\n", &event.delta, &event.value) == 2,
         "%s:%d: Syntax error in trace\n%s", name, linecount, input);
 
     if (last_event) {
@@ -77,7 +78,6 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *name, const char *input, dou
 
   trace_list.insert({xbt_strdup(name), trace});
 
-  xbt_dynar_free(&list);
   return trace;
 }