From 73049fc3c9c1159f15d39ff550712a8c9a8f6ebb Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 6 Mar 2017 17:13:07 +0100 Subject: [PATCH] boostify parsers no more xbt_str_split with dynar --- src/bindings/lua/lua_platf.cpp | 33 +++++++++++++------------- src/kernel/routing/TorusZone.cpp | 17 +++++++------- src/surf/network_ib.cpp | 24 +++++++++++-------- src/surf/plugins/host_energy.cpp | 29 +++++++++++++---------- src/surf/xml/surfxml_sax_cb.cpp | 40 ++++++++++++++------------------ 5 files changed, 75 insertions(+), 68 deletions(-) diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index f9f80a90c1..5a72c1cfca 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -18,8 +18,12 @@ extern "C" { #include } -#include #include "src/surf/surf_private.h" +#include +#include +#include +#include +#include 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(); - xbt_dynar_t names = xbt_str_split(lua_tostring(L, -1), ", \t\r\n"); - if (xbt_dynar_is_empty(names)) { + std::vector 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 - 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); } } } - 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. @@ -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(); - xbt_dynar_t names = xbt_str_split(lua_tostring(L, -1), ", \t\r\n"); - if (xbt_dynar_is_empty(names)) { + std::vector 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 - 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); } } diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index 31741214ad..de87cefeed 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -6,6 +6,10 @@ #include "src/kernel/routing/TorusZone.hpp" #include "src/kernel/routing/NetPoint.hpp" #include "src/surf/network_interface.hpp" +#include +#include +#include +#include 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) { + std::vector 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 */ - 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(); } - xbt_dynar_free(&dimensions); } void TorusZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t route, double* lat) diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 41fa93c82c..0cf97adbb3 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -11,6 +11,8 @@ #include "src/surf/maxmin_private.hpp" #include "src/surf/network_ib.hpp" #include "src/surf/xml/platf.hpp" +#include +#include 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"); - 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 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() diff --git a/src/surf/plugins/host_energy.cpp b/src/surf/plugins/host_energy.cpp index 08ab4df26f..6afa7f043c 100644 --- a/src/surf/plugins/host_energy.cpp +++ b/src/surf/plugins/host_energy.cpp @@ -7,8 +7,13 @@ #include "simgrid/simix.hpp" #include "src/plugins/vm/VirtualMachineImpl.hpp" #include "src/surf/cpu_interface.hpp" + +#include +#include #include +#include #include +#include /** @addtogroup SURF_plugin_energy @@ -225,14 +230,16 @@ void HostEnergy::initWattsRangeList() 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 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 */ - 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 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) */ @@ -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()); - 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); - - xbt_dynar_free(¤t_power_values); + i++; } - xbt_dynar_free(&all_power_values); } } } diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 6aef8bbe3b..b7114274f7 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -19,9 +19,12 @@ #include "xbt/log.h" #include "xbt/misc.h" #include "xbt/str.h" -#include #include "src/surf/xml/platf_private.hpp" +#include +#include +#include +#include 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* explodesRadical(const char* radicals) { std::vector* exploded = new std::vector(); - char* groups; - unsigned int iter; // 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 radical_elements; + boost::split(radical_elements, radicals, boost::is_any_of(",")); + for (auto group : radical_elements) { + std::vector 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; - switch (xbt_dynar_length(radical_ends)) { + switch (radical_ends.size()) { 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: - surf_parse_error("Malformed radical: %s", groups); + surf_parse_error("Malformed radical: %s", group.c_str()); break; } - for (int i = start; i <= end; i++) exploded->push_back(i); - - xbt_dynar_free(&radical_ends); } - xbt_dynar_free(&radical_elements); return exploded; } @@ -278,16 +276,14 @@ static std::vector 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 { - 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 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); } - xbt_dynar_free(&pstate_list); } return speed_per_pstate; } -- 2.20.1