Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make the sendsend tests at least fail fast to not hinder my workflow
[simgrid.git] / include / xbt / config.hpp
index 59dfd0a..8071dbd 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016-2022. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2016-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. */
@@ -77,6 +77,10 @@ extern template XBT_PUBLIC double const& get_value<double>(const std::string& na
 extern template XBT_PUBLIC bool const& get_value<bool>(const std::string& name);
 extern template XBT_PUBLIC std::string const& get_value<std::string>(const std::string& name);
 
+// ***** alias *****
+
+XBT_PUBLIC void alias(const char* realname, std::initializer_list<const char*> aliases);
+
 // Register:
 
 /** Register a configuration flag
@@ -89,6 +93,13 @@ extern template XBT_PUBLIC std::string const& get_value<std::string>(const std::
 template <class T>
 XBT_PUBLIC void declare_flag(const std::string& name, const std::string& description, T value,
                              std::function<void(const T&)> callback = std::function<void(const T&)>());
+template <class T>
+void declare_flag(const std::string& name, std::initializer_list<const char*> aliases, const std::string& description,
+                  T value, std::function<void(const T&)> callback = std::function<void(const T&)>())
+{
+  declare_flag(name, description, std::move(value), std::move(callback));
+  alias(name.c_str(), aliases);
+}
 
 extern template XBT_PUBLIC void declare_flag(const std::string& name, const std::string& description, int value,
                                              std::function<void(int const&)> callback);
@@ -99,10 +110,6 @@ extern template XBT_PUBLIC void declare_flag(const std::string& name, const std:
 extern template XBT_PUBLIC void declare_flag(const std::string& name, const std::string& description, std::string value,
                                              std::function<void(std::string const&)> callback);
 
-// ***** alias *****
-
-XBT_PUBLIC void alias(const char* realname, std::initializer_list<const char*> aliases);
-
 /** Bind a variable to configuration flag
  *
  *  @param value Bound variable
@@ -167,7 +174,7 @@ bind_flag(std::string& value, const char* name, const char* description,
                  if (val == "help")
                    mesg += std::string("Possible values for option ") + name + ":\n";
                  else
-                   mesg += std::string("Invalid value '") + val + "' for option " + name + ". Possible values:\n";
+                   mesg += "Invalid value '" + val + "' for option " + name + ". Possible values:\n";
                  for (auto const& kv : valid_values)
                    mesg += "  - '" + kv.first + "': " + kv.second + (kv.first == value ? "  <=== DEFAULT" : "") + "\n";
                  xbt_die("%s", mesg.c_str());