X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/477fc68ab3dd1b5210d7db49144d90d0d9e57993..35a644bdf9d0c5603c9483f03f913e4a649638d6:/src/xbt/xbt_parse_units.cpp diff --git a/src/xbt/xbt_parse_units.cpp b/src/xbt/xbt_parse_units.cpp index a77b852c44..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) { @@ -51,23 +52,23 @@ unit_scale::unit_scale(std::initializer_listsecond; } -double xbt_parse_get_time(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name) +double xbt_parse_get_time(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind) { static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60), std::make_pair("d", 24 * 60 * 60), @@ -88,72 +89,68 @@ double xbt_parse_get_time(const std::string& filename, int lineno, const char* s std::make_pair("us", 1e-6), std::make_pair("ns", 1e-9), std::make_pair("ps", 1e-12)}; - return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name, - "Append 's' to your time to get seconds", "s"); + return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, + "Append 's' to your time to get seconds", "s"); } -double surf_parse_get_size(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name) +double xbt_parse_get_size(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind) { static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true), std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)}; - return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name, - "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B"); + return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, + "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B"); } -double xbt_parse_get_bandwidth(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name) +double xbt_parse_get_bandwidth(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind) { static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true), std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)}; - return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name, - "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", - "Bps"); + return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, + "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", + "Bps"); } -std::vector xbt_parse_get_bandwidths(const std::string& filename, int lineno, const char* string, - const char* entity_kind, const std::string& name) +std::vector xbt_parse_get_bandwidths(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind) { static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true), std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)}; std::vector bandwidths; std::vector tokens; - boost::split(tokens, string, boost::is_any_of(";")); - for (auto token : tokens) { - bandwidths.push_back(surf_parse_get_value_with_unit( - filename, lineno, token.c_str(), units, entity_kind, name, + boost::split(tokens, string, boost::is_any_of(";,")); + for (auto const& token : tokens) { + bandwidths.push_back(xbt_parse_get_value_with_unit( + filename, lineno, token.c_str(), units, entity_kind, "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps")); } return bandwidths; } -double xbt_parse_get_speed(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name) +double xbt_parse_get_speed(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind) { static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)}; - return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name, - "Append 'f' or 'flops' to your speed to get flop per second", "f"); + return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, + "Append 'f' or 'flops' to your speed to get flop per second", "f"); } -std::vector xbt_parse_get_all_speeds(const std::string& filename, int lineno, char* speeds, - const char* entity_kind, const std::string& id) +std::vector xbt_parse_get_all_speeds(const std::string& filename, int lineno, const std::string& speeds, + const std::string& entity_kind) { std::vector speed_per_pstate; + std::vector pstate_list; - if (strchr(speeds, ',') == nullptr) { - double speed = xbt_parse_get_speed(filename, lineno, speeds, entity_kind, id); + 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.c_str(), entity_kind, id); - speed_per_pstate.push_back(speed); - XBT_DEBUG("Speed value: %f", speed); - } + XBT_DEBUG("Speed value: %f", speed); } + return speed_per_pstate; }