X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5e9351c7145890c8105dd81af2f09cd6dc50383f..85313e62aa3ec8a2f1de00cb7da9df46588ea2c2:/src/xbt/xbt_parse_units.cpp diff --git a/src/xbt/xbt_parse_units.cpp b/src/xbt/xbt_parse_units.cpp index 01066f2f1c..768ceca01f 100644 --- a/src/xbt/xbt_parse_units.cpp +++ b/src/xbt/xbt_parse_units.cpp @@ -1,3 +1,8 @@ +/* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved. */ + +/* 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. */ + #include "simgrid/Exception.hpp" #include "xbt/ex.h" #include "xbt/log.h" @@ -22,11 +27,7 @@ public: unit_scale::unit_scale(std::initializer_list> generators) { - for (const auto& gen : generators) { - const std::string& unit = std::get<0>(gen); - double value = std::get<1>(gen); - const int base = std::get<2>(gen); - const bool abbrev = std::get<3>(gen); + for (auto [unit, value, base, abbrev] : generators) { double mult; std::vector prefixes; switch (base) { @@ -61,9 +62,9 @@ static double xbt_parse_get_value_with_unit(const std::string& filename, int lin double res = strtod(string.c_str(), &endptr); const char* ptr = endptr; // for const-correctness if (errno == ERANGE) - throw simgrid::ParseError(filename, lineno, std::string("value out of range: ") + string); + throw simgrid::ParseError(filename, lineno, "value out of range: " + string); if (ptr == string) - throw simgrid::ParseError(filename, lineno, std::string("cannot parse number:") + string); + throw simgrid::ParseError(filename, lineno, "cannot parse number:" + string); if (ptr[0] == '\0') { // Ok, 0 can be unit-less if (res != 0 && not entity_kind.empty()) @@ -141,19 +142,15 @@ std::vector xbt_parse_get_all_speeds(const std::string& filename, int li const std::string& entity_kind) { std::vector speed_per_pstate; + std::vector pstate_list; - if (speeds.find('.') == std::string::npos) { - double speed = xbt_parse_get_speed(filename, lineno, speeds, entity_kind); + boost::split(pstate_list, speeds, boost::is_any_of(",")); + for (auto speed_str : pstate_list) { + boost::trim(speed_str); + double speed = xbt_parse_get_speed(filename, lineno, speed_str, entity_kind); speed_per_pstate.push_back(speed); - } else { - 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 = xbt_parse_get_speed(filename, lineno, speed_str, entity_kind); - speed_per_pstate.push_back(speed); - XBT_DEBUG("Speed value: %f", speed); - } + XBT_DEBUG("Speed value: %f", speed); } + return speed_per_pstate; }