From a89702134ae7f9d4fb2178523311a4201d150480 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 10 Aug 2017 14:47:40 +0200 Subject: [PATCH] more strings --- src/kernel/routing/TorusZone.cpp | 20 ++++------ src/surf/xml/platf.hpp | 14 +++---- src/surf/xml/surfxml_sax_cb.cpp | 64 ++++++++++++++++---------------- 3 files changed, 45 insertions(+), 53 deletions(-) diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index e5c6ce7f4a..cf312416ad 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -81,12 +81,11 @@ void TorusZone::parse_specific_arguments(sg_platf_cluster_cbarg_t cluster) if (not dimensions.empty()) { /* We are in a torus cluster - * Parse attribute dimensions="dim1,dim2,dim3,...,dimN" and safe it in a vector. + * Parse attribute dimensions="dim1,dim2,dim3,...,dimN" and save them into a vector. * Additionally, we need to know how many ranks we have in total */ - for (auto group : dimensions) { - dimensions_.push_back(surf_parse_get_int(group.c_str())); - } + for (auto group : dimensions) + dimensions_.push_back(surf_parse_get_int(group)); linkCountPerNode_ = dimensions_.size(); } @@ -117,21 +116,16 @@ void TorusZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg unsigned int current_node = src->id(); unsigned int next_node = 0; /* - * Arrays that hold the coordinates of the current node and - * the target; comparing the values at the i-th position of - * both arrays, we can easily assess whether we need to route - * into this dimension or not. + * Arrays that hold the coordinates of the current node andthe target; comparing the values at the i-th position of + * both arrays, we can easily assess whether we need to route into this dimension or not. */ unsigned int myCoords[4]; rankId_to_coords(src->id(), dimensions_, &myCoords); unsigned int targetCoords[4]; rankId_to_coords(dst->id(), dimensions_, &targetCoords); /* - * linkOffset describes the offset where the link - * we want to use is stored - * (+1 is added because each node has a link from itself to itself, - * which can only be the case if src->m_id == dst->m_id -- see above - * for this special case) + * linkOffset describes the offset where the link we want to use is stored(+1 is added because each node has a link + * from itself to itself, which can only be the case if src->m_id == dst->m_id -- see above for this special case) */ int nodeOffset = (dimensions_.size() + 1) * src->id(); diff --git a/src/surf/xml/platf.hpp b/src/surf/xml/platf.hpp index 1a7dc48e03..159aa1ae14 100644 --- a/src/surf/xml/platf.hpp +++ b/src/surf/xml/platf.hpp @@ -3,11 +3,9 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#ifndef SURF_SURFXML_PARSE_H -#define SURF_SURFXML_PARSE_H +#ifndef SURF_SURFXML_PARSE_HPP +#define SURF_SURFXML_PARSE_HPP -#include -#include #include SG_BEGIN_DECL() @@ -20,11 +18,11 @@ XBT_PUBLIC(void) surf_parse_open(const char *file); XBT_PUBLIC(void) surf_parse_close(); XBT_PUBLIC(void) surf_parse_assert(bool cond, std::string msg); XBT_PUBLIC(void) XBT_ATTRIB_NORETURN surf_parse_error(std::string msg); -XBT_PUBLIC(void) surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post); -XBT_PUBLIC(void) surf_parse_warn(const char *msg,...) XBT_ATTRIB_PRINTF(1,2); +XBT_PUBLIC(void) surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post); +XBT_PUBLIC(void) surf_parse_warn(std::string msg); -XBT_PUBLIC(double) surf_parse_get_double(const char *string); -XBT_PUBLIC(int) surf_parse_get_int(const char *string); +XBT_PUBLIC(double) surf_parse_get_double(std::string s); +XBT_PUBLIC(int) surf_parse_get_int(std::string s); XBT_PUBLIC(double) surf_parse_get_time(const char *string, const char *entity_kind, const char *name); XBT_PUBLIC(double) surf_parse_get_size(const char *string, const char *entity_kind, const char *name); XBT_PUBLIC(double) surf_parse_get_bandwidth(const char *string, const char *entity_kind, const char *name); diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index b28cba8fdc..bd7ffc5d36 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -40,6 +40,7 @@ void surf_parse_assert(bool cond, std::string msg) xbt_die("Exiting now"); } } + void surf_parse_error(std::string msg) { int lineno = surf_parse_lineno; @@ -49,15 +50,12 @@ void surf_parse_error(std::string msg) xbt_die("Exiting now"); } -void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post) +void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post) { - if (sg_netpoint_by_name_or_null(hostname) != nullptr) // found + if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found return; - std::string msg = std::string(pre); - msg += hostname; - msg += post; - msg += " Existing netpoints: \n"; + std::string msg = pre + hostname + post + " Existing netpoints: \n"; std::vector list; simgrid::s4u::Engine::getInstance()->getNetpointList(&list); @@ -83,33 +81,33 @@ void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* pos surf_parse_error(msg); } -void surf_parse_warn(const char *fmt, ...) { - va_list va; - va_start(va,fmt); - char *msg = bvprintf(fmt,va); - va_end(va); - XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg); - free(msg); +void surf_parse_warn(std::string msg) +{ + XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg.c_str()); } -double surf_parse_get_double(const char *string) { - double res; - int ret = sscanf(string, "%lg", &res); - if (ret != 1) - surf_parse_error(std::string(string) + " is not a double"); - return res; +double surf_parse_get_double(std::string s) +{ + try { + return std::stod(s); + } catch (std::invalid_argument& ia) { + surf_parse_error(s + " is not a double"); + return -1; + } } -int surf_parse_get_int(const char *string) { - int res; - int ret = sscanf(string, "%d", &res); - if (ret != 1) - surf_parse_error(std::string(string) + " is not an integer"); - return res; +int surf_parse_get_int(std::string s) +{ + try { + return std::stoi(s); + } catch (std::invalid_argument& ia) { + surf_parse_error(s + " is not a double"); + return -1; + } } /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */ -static std::vector* explodesRadical(const char* radicals) +static std::vector* explodesRadical(std::string radicals) { std::vector* exploded = new std::vector(); @@ -119,15 +117,15 @@ static std::vector* explodesRadical(const char* radicals) 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; + int start = surf_parse_get_int(radical_ends.front()); + int end = 0; switch (radical_ends.size()) { case 1: end = start; break; case 2: - end = surf_parse_get_int((radical_ends.back()).c_str()); + end = surf_parse_get_int(radical_ends.back()); break; default: surf_parse_error(std::string("Malformed radical: ") + group); @@ -972,7 +970,8 @@ void ETag_surfxml_zone() void STag_surfxml_config() { ZONE_TAG = 0; - xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)"); + xbt_assert(current_property_set == nullptr, + "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)"); XBT_DEBUG("START configuration name = %s",A_surfxml_config_id); if (_sg_cfg_init_status == 2) { surf_parse_error("All tags must be given before any platform elements (such as , , , " @@ -1003,6 +1002,7 @@ void STag_surfxml_process() AX_surfxml_actor_function = AX_surfxml_process_function; STag_surfxml_actor(); } + void STag_surfxml_actor() { ZONE_TAG = 0; @@ -1021,6 +1021,7 @@ void ETag_surfxml_process() AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure; ETag_surfxml_actor(); } + void ETag_surfxml_actor() { s_sg_platf_process_cbarg_t actor; @@ -1067,8 +1068,7 @@ void STag_surfxml_model___prop(){ if (not current_model_property_set) current_model_property_set = new std::map(); - current_model_property_set->insert( - {std::string(A_surfxml_model___prop_id), std::string(A_surfxml_model___prop_value)}); + current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value}); } void ETag_surfxml_prop(){/* Nothing to do */} -- 2.20.1