X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c519915704726e094413a6267e925496082d245e..89d6f2594bd77b1d2a52ef35d296c461e9b7f9a8:/src/xbt/config.cpp diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index 25feb0858f..3d7c730097 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2004-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2004-2021. 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. */ @@ -16,8 +16,6 @@ #include #include #include -#include -#include #include #include "simgrid/Exception.hpp" @@ -38,7 +36,7 @@ namespace config { namespace { -static bool parse_bool(const char* value) +bool parse_bool(const char* value) { for (const char* true_value : {"yes", "on", "true", "1"}) if (std::strcmp(true_value, value) == 0) @@ -49,37 +47,30 @@ static bool parse_bool(const char* value) throw std::range_error("not a boolean"); } -static double parse_double(const char* value) +double parse_double(const char* value) { char* end; errno = 0; double res = std::strtod(value, &end); if (errno == ERANGE) throw std::range_error("out of range"); - else if (errno) - xbt_die("Unexpected errno"); + xbt_assert(errno == 0, "Unexpected errno: %d", errno); if (end == value || *end != '\0') throw std::range_error("invalid double"); - else - return res; + return res; } -static long int parse_long(const char* value) +long int parse_long(const char* value) { char* end; errno = 0; long int res = std::strtol(value, &end, 0); - if (errno) { - if (res == LONG_MIN && errno == ERANGE) - throw std::range_error("underflow"); - else if (res == LONG_MAX && errno == ERANGE) - throw std::range_error("overflow"); - xbt_die("Unexpected errno"); - } + if (errno == ERANGE) + throw std::range_error(res == LONG_MIN ? "underflow" : "overflow"); + xbt_assert(errno == 0, "Unexpected errno: %d", errno); if (end == value || *end != '\0') throw std::range_error("invalid integer"); - else - return res; + return res; } // ***** ConfigType ***** @@ -182,7 +173,6 @@ public: TypedConfigurationElement(const std::string& key, const std::string& desc, T value, std::function callback) : ConfigurationElement(key, desc), content(std::move(value)), callback(std::move(callback)) {} - ~TypedConfigurationElement() override = default; std::string get_string_value() override; const char* get_type_name() override; @@ -245,9 +235,9 @@ template const char* TypedConfigurationElement::get_type_name() // class Config { private: // name -> ConfigElement: - std::map> options; + std::map, std::less<>> options; // alias -> ConfigElement from options: - std::map aliases; + std::map> aliases; bool warn_for_aliases = true; public: