Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
boostify parsers
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 6 Mar 2017 16:13:07 +0000 (17:13 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 6 Mar 2017 19:28:24 +0000 (20:28 +0100)
no more xbt_str_split with dynar

src/bindings/lua/lua_platf.cpp
src/kernel/routing/TorusZone.cpp
src/surf/network_ib.cpp
src/surf/plugins/host_energy.cpp
src/surf/xml/surfxml_sax_cb.cpp

index f9f80a9..5a72c1c 100644 (file)
@@ -18,8 +18,12 @@ extern "C" {
 #include <lauxlib.h>
 }
 
 #include <lauxlib.h>
 }
 
-#include <simgrid/host.h>
 #include "src/surf/surf_private.h"
 #include "src/surf/surf_private.h"
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <simgrid/host.h>
+#include <string>
+#include <vector>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(lua_platf, "Lua bindings (platform module)");
 
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(lua_platf, "Lua bindings (platform module)");
 
@@ -330,22 +334,20 @@ int console_add_route(lua_State *L) {
   lua_ensure(type == LUA_TSTRING,
       "Attribute 'links' must be specified for any route and must be a string (different links separated by commas or single spaces.");
   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
   lua_ensure(type == LUA_TSTRING,
       "Attribute 'links' must be specified for any route and must be a string (different links separated by commas or single spaces.");
   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
-  xbt_dynar_t names = xbt_str_split(lua_tostring(L, -1), ", \t\r\n");
-  if (xbt_dynar_is_empty(names)) {
+  std::vector<std::string> names;
+  boost::split(names, lua_tostring(L, -1), boost::is_any_of(", \t\r\n"));
+  if (names.empty()) {
     /* unique name */
     route.link_list->push_back(simgrid::surf::LinkImpl::byName(lua_tostring(L, -1)));
   } else {
     // Several names separated by , \t\r\n
     /* unique name */
     route.link_list->push_back(simgrid::surf::LinkImpl::byName(lua_tostring(L, -1)));
   } else {
     // Several names separated by , \t\r\n
-    unsigned int cpt;
-    char *name;
-    xbt_dynar_foreach(names, cpt, name) {
-      if (strlen(name)>0) {
-        simgrid::surf::LinkImpl* link = simgrid::surf::LinkImpl::byName(name);
+    for (auto name : names) {
+      if (name.length() > 0) {
+        simgrid::surf::LinkImpl* link = simgrid::surf::LinkImpl::byName(name.c_str());
         route.link_list->push_back(link);
       }
     }
   }
         route.link_list->push_back(link);
       }
     }
   }
-  xbt_dynar_free(&names);
   lua_pop(L,1);
 
   /* We are relying on the XML bypassing mechanism since the corresponding sg_platf does not exist yet.
   lua_pop(L,1);
 
   /* We are relying on the XML bypassing mechanism since the corresponding sg_platf does not exist yet.
@@ -412,17 +414,16 @@ int console_add_ASroute(lua_State *L) {
   lua_pushstring(L,"links");
   lua_gettable(L,-2);
   ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
   lua_pushstring(L,"links");
   lua_gettable(L,-2);
   ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
-  xbt_dynar_t names = xbt_str_split(lua_tostring(L, -1), ", \t\r\n");
-  if (xbt_dynar_is_empty(names)) {
+  std::vector<std::string> names;
+  boost::split(names, lua_tostring(L, -1), boost::is_any_of(", \t\r\n"));
+  if (names.empty()) {
     /* unique name with no comma */
     ASroute.link_list->push_back(simgrid::surf::LinkImpl::byName(lua_tostring(L, -1)));
   } else {
     // Several names separated by , \t\r\n
     /* unique name with no comma */
     ASroute.link_list->push_back(simgrid::surf::LinkImpl::byName(lua_tostring(L, -1)));
   } else {
     // Several names separated by , \t\r\n
-    unsigned int cpt;
-    char *name;
-    xbt_dynar_foreach(names, cpt, name) {
-      if (strlen(name)>0) {
-        simgrid::surf::LinkImpl* link = simgrid::surf::LinkImpl::byName(name);
+    for (auto name : names) {
+      if (name.length() > 0) {
+        simgrid::surf::LinkImpl* link = simgrid::surf::LinkImpl::byName(name.c_str());
         ASroute.link_list->push_back(link);
       }
     }
         ASroute.link_list->push_back(link);
       }
     }
index 3174121..de87cef 100644 (file)
@@ -6,6 +6,10 @@
 #include "src/kernel/routing/TorusZone.hpp"
 #include "src/kernel/routing/NetPoint.hpp"
 #include "src/surf/network_interface.hpp"
 #include "src/kernel/routing/TorusZone.hpp"
 #include "src/kernel/routing/NetPoint.hpp"
 #include "src/surf/network_interface.hpp"
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <string>
+#include <vector>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster_torus, surf_route_cluster, "Torus Routing part of surf");
 
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster_torus, surf_route_cluster, "Torus Routing part of surf");
 
@@ -79,23 +83,20 @@ void TorusZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id,
 
 void TorusZone::parse_specific_arguments(sg_platf_cluster_cbarg_t cluster)
 {
 
 void TorusZone::parse_specific_arguments(sg_platf_cluster_cbarg_t cluster)
 {
+  std::vector<std::string> dimensions;
+  boost::split(dimensions, cluster->topo_parameters, boost::is_any_of(","));
 
 
-  unsigned int iter;
-  char* groups;
-  xbt_dynar_t dimensions = xbt_str_split(cluster->topo_parameters, ",");
-
-  if (!xbt_dynar_is_empty(dimensions)) {
+  if (!dimensions.empty()) {
     /* We are in a torus cluster
      * Parse attribute dimensions="dim1,dim2,dim3,...,dimN" and safe it in a vector.
      * Additionally, we need to know how many ranks we have in total
      */
     /* We are in a torus cluster
      * Parse attribute dimensions="dim1,dim2,dim3,...,dimN" and safe it in a vector.
      * Additionally, we need to know how many ranks we have in total
      */
-    xbt_dynar_foreach (dimensions, iter, groups) {
-      dimensions_.push_back(surf_parse_get_int(groups));
+    for (auto group : dimensions) {
+      dimensions_.push_back(surf_parse_get_int(group.c_str()));
     }
 
     linkCountPerNode_ = dimensions_.size();
   }
     }
 
     linkCountPerNode_ = dimensions_.size();
   }
-  xbt_dynar_free(&dimensions);
 }
 
 void TorusZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t route, double* lat)
 }
 
 void TorusZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t route, double* lat)
index 41fa93c..0cf97ad 100644 (file)
@@ -11,6 +11,8 @@
 #include "src/surf/maxmin_private.hpp"
 #include "src/surf/network_ib.hpp"
 #include "src/surf/xml/platf.hpp"
 #include "src/surf/maxmin_private.hpp"
 #include "src/surf/network_ib.hpp"
 #include "src/surf/xml/platf.hpp"
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
 
@@ -98,16 +100,18 @@ namespace simgrid {
       active_nodes=nullptr;
 
       const char* IB_factors_string=xbt_cfg_get_string("smpi/IB-penalty-factors");
       active_nodes=nullptr;
 
       const char* IB_factors_string=xbt_cfg_get_string("smpi/IB-penalty-factors");
-      xbt_dynar_t radical_elements = xbt_str_split(IB_factors_string, ";");
-
-      surf_parse_assert(xbt_dynar_length(radical_elements)==3,
-          "smpi/IB-penalty-factors should be provided and contain 3 elements, semi-colon separated. Example: 0.965;0.925;1.35");
-
-      Be = xbt_str_parse_double(xbt_dynar_get_as(radical_elements, 0, char *), "First part of smpi/IB-penalty-factors is not numerical: %s");
-      Bs = xbt_str_parse_double(xbt_dynar_get_as(radical_elements, 1, char *), "Second part of smpi/IB-penalty-factors is not numerical: %s");
-      ys = xbt_str_parse_double(xbt_dynar_get_as(radical_elements, 2, char *), "Third part of smpi/IB-penalty-factors is not numerical: %s");
-
-      xbt_dynar_free(&radical_elements);
+      std::vector<std::string> radical_elements;
+      boost::split(radical_elements, IB_factors_string, boost::is_any_of(";"));
+
+      surf_parse_assert(radical_elements.size() == 3, "smpi/IB-penalty-factors should be provided and contain 3 "
+                                                      "elements, semi-colon separated. Example: 0.965;0.925;1.35");
+
+      Be = xbt_str_parse_double(radical_elements.front().c_str(),
+                                "First part of smpi/IB-penalty-factors is not numerical: %s");
+      Bs = xbt_str_parse_double((radical_elements.at(1)).c_str(),
+                                "Second part of smpi/IB-penalty-factors is not numerical: %s");
+      ys = xbt_str_parse_double(radical_elements.back().c_str(),
+                                "Third part of smpi/IB-penalty-factors is not numerical: %s");
     }
 
     NetworkIBModel::~NetworkIBModel()
     }
 
     NetworkIBModel::~NetworkIBModel()
index 08ab4df..6afa7f0 100644 (file)
@@ -7,8 +7,13 @@
 #include "simgrid/simix.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "simgrid/simix.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
+
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
 #include <simgrid/s4u/engine.hpp>
 #include <simgrid/s4u/engine.hpp>
+#include <string>
 #include <utility>
 #include <utility>
+#include <vector>
 
 /** @addtogroup SURF_plugin_energy
 
 
 /** @addtogroup SURF_plugin_energy
 
@@ -225,14 +230,16 @@ void HostEnergy::initWattsRangeList()
   if (all_power_values_str == nullptr)
     return;
 
   if (all_power_values_str == nullptr)
     return;
 
-  xbt_dynar_t all_power_values = xbt_str_split(all_power_values_str, ",");
-  int pstate_nb                = xbt_dynar_length(all_power_values);
+  std::vector<std::string> all_power_values;
+  boost::split(all_power_values, all_power_values_str, boost::is_any_of(","));
 
 
-  for (int i = 0; i < pstate_nb; i++) {
+  int i = 0;
+  for (auto current_power_values_str : all_power_values) {
     /* retrieve the power values associated with the current pstate */
     /* retrieve the power values associated with the current pstate */
-    xbt_dynar_t current_power_values = xbt_str_split(xbt_dynar_get_as(all_power_values, i, char*), ":");
-    xbt_assert(xbt_dynar_length(current_power_values) == 3,
-               "Power properties incorrectly defined - could not retrieve idle, min and max power values for host %s",
+    std::vector<std::string> current_power_values;
+    boost::split(current_power_values, current_power_values_str, boost::is_any_of(":"));
+    xbt_assert(current_power_values.size() == 3, "Power properties incorrectly defined - "
+                                                 "could not retrieve idle, min and max power values for host %s",
                host->cname());
 
     /* min_power corresponds to the idle power (cpu load = 0) */
                host->cname());
 
     /* min_power corresponds to the idle power (cpu load = 0) */
@@ -240,17 +247,15 @@ void HostEnergy::initWattsRangeList()
     char* msg_idle = bprintf("Invalid idle value for pstate %d on host %s: %%s", i, host->cname());
     char* msg_min  = bprintf("Invalid min value for pstate %d on host %s: %%s", i, host->cname());
     char* msg_max  = bprintf("Invalid max value for pstate %d on host %s: %%s", i, host->cname());
     char* msg_idle = bprintf("Invalid idle value for pstate %d on host %s: %%s", i, host->cname());
     char* msg_min  = bprintf("Invalid min value for pstate %d on host %s: %%s", i, host->cname());
     char* msg_max  = bprintf("Invalid max value for pstate %d on host %s: %%s", i, host->cname());
-    PowerRange range(xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 0, char*), msg_idle),
-                     xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 1, char*), msg_min),
-                     xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 2, char*), msg_max));
+    PowerRange range(xbt_str_parse_double((current_power_values.at(0)).c_str(), msg_idle),
+                     xbt_str_parse_double((current_power_values.at(1)).c_str(), msg_min),
+                     xbt_str_parse_double((current_power_values.at(2)).c_str(), msg_max));
     power_range_watts_list.push_back(range);
     xbt_free(msg_idle);
     xbt_free(msg_min);
     xbt_free(msg_max);
     power_range_watts_list.push_back(range);
     xbt_free(msg_idle);
     xbt_free(msg_min);
     xbt_free(msg_max);
-
-    xbt_dynar_free(&current_power_values);
+    i++;
   }
   }
-  xbt_dynar_free(&all_power_values);
 }
 }
 }
 }
 }
 }
index 6aef8bb..b711427 100644 (file)
 #include "xbt/log.h"
 #include "xbt/misc.h"
 #include "xbt/str.h"
 #include "xbt/log.h"
 #include "xbt/misc.h"
 #include "xbt/str.h"
-#include <string>
 
 #include "src/surf/xml/platf_private.hpp"
 
 #include "src/surf/xml/platf_private.hpp"
+#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <string>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
 
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
 
@@ -91,35 +94,30 @@ int surf_parse_get_int(const char *string) {
 static std::vector<int>* explodesRadical(const char* radicals)
 {
   std::vector<int>* exploded = new std::vector<int>();
 static std::vector<int>* explodesRadical(const char* radicals)
 {
   std::vector<int>* exploded = new std::vector<int>();
-  char* groups;
-  unsigned int iter;
 
   // Make all hosts
 
   // Make all hosts
-  xbt_dynar_t radical_elements = xbt_str_split(radicals, ",");
-  xbt_dynar_foreach (radical_elements, iter, groups) {
-
-    xbt_dynar_t radical_ends = xbt_str_split(groups, "-");
-    int start                = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char*));
+  std::vector<std::string> radical_elements;
+  boost::split(radical_elements, radicals, boost::is_any_of(","));
+  for (auto group : radical_elements) {
+    std::vector<std::string> radical_ends;
+    boost::split(radical_ends, group, boost::is_any_of("-"));
+    int start                = surf_parse_get_int((radical_ends.front()).c_str());
     int end                  = 0;
 
     int end                  = 0;
 
-    switch (xbt_dynar_length(radical_ends)) {
+    switch (radical_ends.size()) {
       case 1:
         end = start;
         break;
       case 2:
       case 1:
         end = start;
         break;
       case 2:
-        end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char*));
+        end = surf_parse_get_int((radical_ends.back()).c_str());
         break;
       default:
         break;
       default:
-        surf_parse_error("Malformed radical: %s", groups);
+        surf_parse_error("Malformed radical: %s", group.c_str());
         break;
     }
         break;
     }
-
     for (int i = start; i <= end; i++)
       exploded->push_back(i);
     for (int i = start; i <= end; i++)
       exploded->push_back(i);
-
-    xbt_dynar_free(&radical_ends);
   }
   }
-  xbt_dynar_free(&radical_elements);
 
   return exploded;
 }
 
   return exploded;
 }
@@ -278,16 +276,14 @@ static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* e
     double speed = surf_parse_get_speed(speeds, entity_kind, id);
     speed_per_pstate.push_back(speed);
   } else {
     double speed = surf_parse_get_speed(speeds, entity_kind, id);
     speed_per_pstate.push_back(speed);
   } else {
-    xbt_dynar_t pstate_list = xbt_str_split(speeds, ",");
-    unsigned int i;
-    char* speed_str;
-    xbt_dynar_foreach(pstate_list, i, speed_str) {
-      xbt_str_trim(speed_str, nullptr);
-      double speed = surf_parse_get_speed(speed_str,entity_kind, id);
+    std::vector<std::string> pstate_list;
+    boost::split(pstate_list, speeds, boost::is_any_of(","));
+    for (auto speed_str : pstate_list) {
+      boost::trim(speed_str);
+      double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
       speed_per_pstate.push_back(speed);
       XBT_DEBUG("Speed value: %f", speed);
     }
       speed_per_pstate.push_back(speed);
       XBT_DEBUG("Speed value: %f", speed);
     }
-    xbt_dynar_free(&pstate_list);
   }
   return speed_per_pstate;
 }
   }
   return speed_per_pstate;
 }