Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[config] Some alias support in the C++ API
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 2 May 2016 14:27:43 +0000 (16:27 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 3 May 2016 07:37:43 +0000 (09:37 +0200)
include/xbt/config.hpp
src/xbt/config.cpp

index 65279e8..5187bcd 100644 (file)
@@ -10,6 +10,7 @@
 #include <cstdlib>
 
 #include <functional>
+#include <initializer_list>
 #include <stdexcept>
 #include <string>
 #include <type_traits>
@@ -71,6 +72,18 @@ extern template XBT_PUBLIC(void) declareFlag(const char* name,
 extern template XBT_PUBLIC(void) declareFlag(const char* name,
   const char* description, std::string value, std::function<void(std::string const &)> callback);
 
+// ***** alias *****
+
+XBT_PUBLIC(void) alias(const char* realname, const char* aliasname);
+
+inline
+void alias(std::initializer_list<const char*> names)
+{
+  auto i = names.begin();
+  for (++i; i != names.end(); ++i)
+    alias(*names.begin(), *i);
+}
+
 /** Bind a variable to configuration flag
  *
  *  @param value Bound variable
@@ -86,6 +99,13 @@ void bindFlag(T& value, const char* name, const char* description)
   });
 }
 
+template<class T>
+void bindFlag(T& value, std::initializer_list<const char*> names, const char* description)
+{
+  bindFlag(value, *names.begin(), description);
+  alias(names);
+}
+
 /** Bind a variable to configuration flag
  *
  *  <pre><code>
@@ -97,6 +117,18 @@ void bindFlag(T& value, const char* name, const char* description)
  *  </pre><code>
  */
 // F is a checker, F : T& -> ()
+template<class T, class F>
+typename std::enable_if<std::is_same<
+  void,
+  decltype( std::declval<F>()(std::declval<const T&>()) )
+>::value, void>::type
+bindFlag(T& value, std::initializer_list<const char*> names, const char* description,
+  F callback)
+{
+  bindFlag(value, *names.begin(), description);
+  alias(names);
+}
+
 template<class T, class F>
 typename std::enable_if<std::is_same<
   void,
index f915d84..521d32c 100644 (file)
@@ -430,6 +430,13 @@ template XBT_PUBLIC(double const&) getConfig<double>(const char* name);
 template XBT_PUBLIC(bool const&) getConfig<bool>(const char* name);
 template XBT_PUBLIC(std::string const&) getConfig<std::string>(const char* name);
 
+// ***** alias *****
+
+void alias(const char* realname, const char* aliasname)
+{
+  simgrid_config->alias(realname, aliasname);
+}
+
 // ***** declareFlag *****
 
 template<class T>
@@ -451,7 +458,6 @@ template XBT_PUBLIC(void) declareFlag(const char* name,
 template XBT_PUBLIC(void) declareFlag(const char* name,
   const char* description, std::string value, std::function<void(std::string const &)> callback);
 
-
 }
 }