X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/77bbf3027c4240a2e833209a3a3f186589da8577..0542dca1b5c334f0482f3dd62a21faa017a884c5:/include/xbt/config.hpp diff --git a/include/xbt/config.hpp b/include/xbt/config.hpp index d457e57a4e..a274225de1 100644 --- a/include/xbt/config.hpp +++ b/include/xbt/config.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2016-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2016-2018. 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. */ @@ -23,7 +23,7 @@ namespace simgrid { namespace config { -XBT_PUBLIC_CLASS missing_key_error : public std::runtime_error { +class XBT_PUBLIC missing_key_error : public std::runtime_error { public: explicit missing_key_error(const std::string& what) : std::runtime_error(what) {} @@ -52,13 +52,12 @@ inline std::string to_string(std::string&& value) // Get config -template -XBT_PUBLIC(T const&) getConfig(const char* name); +template XBT_PUBLIC T const& getConfig(const char* name); -extern template XBT_PUBLIC(int const&) getConfig(const char* name); -extern template XBT_PUBLIC(double const&) getConfig(const char* name); -extern template XBT_PUBLIC(bool const&) getConfig(const char* name); -extern template XBT_PUBLIC(std::string const&) getConfig(const char* name); +extern template XBT_PUBLIC int const& getConfig(const char* name); +extern template XBT_PUBLIC double const& getConfig(const char* name); +extern template XBT_PUBLIC bool const& getConfig(const char* name); +extern template XBT_PUBLIC std::string const& getConfig(const char* name); // Register: @@ -69,22 +68,22 @@ extern template XBT_PUBLIC(std::string const&) getConfig(const char * @param value Initial/default value * @param callback called with the option value */ -template -XBT_PUBLIC(void) declareFlag(const char* name, const char* description, - T value, std::function callback = std::function()); - -extern template XBT_PUBLIC(void) declareFlag(const char* name, - const char* description, int value, std::function callback); -extern template XBT_PUBLIC(void) declareFlag(const char* name, - const char* description, double value, std::function callback); -extern template XBT_PUBLIC(void) declareFlag(const char* name, - const char* description, bool value, std::function callback); -extern template XBT_PUBLIC(void) declareFlag(const char* name, - const char* description, std::string value, std::function callback); +template +XBT_PUBLIC void declareFlag(const char* name, const char* description, T value, + std::function callback = std::function()); + +extern template XBT_PUBLIC void declareFlag(const char* name, const char* description, int value, + std::function callback); +extern template XBT_PUBLIC void declareFlag(const char* name, const char* description, double value, + std::function callback); +extern template XBT_PUBLIC void declareFlag(const char* name, const char* description, bool value, + std::function callback); +extern template XBT_PUBLIC void declareFlag(const char* name, const char* description, std::string value, + std::function callback); // ***** alias ***** -XBT_PUBLIC(void) alias(const char* realname, const char* aliasname); +XBT_PUBLIC void alias(const char* realname, const char* aliasname); inline void alias(std::initializer_list names) @@ -156,7 +155,7 @@ bindFlag(T& value, const char* name, const char* description, * *

  *  static int x;
- *  simgrid::config::bindFlag(a, "x", [](int x) { return return x > 0; });
+ *  simgrid::config::bindFlag(a, "x", [](int x) { return x > 0; });
  *  
*/ // F is a predicate, F : T const& -> bool @@ -170,7 +169,7 @@ bindFlag(T& value, const char* name, const char* description, { declareFlag(name, description, value, [&value, callback](const T& val) { if (not callback(val)) - throw std::range_error("invalid value"); + throw std::range_error("invalid value."); value = std::move(val); }); } @@ -179,7 +178,7 @@ bindFlag(T& value, const char* name, const char* description, * *

  *  static simgrid::config::flag answer("answer", "Expected answer", 42);
- *  static simgrid::config::flag name("name", "Ford Prefect", "John Doe");
+ *  static simgrid::config::flag name("name", "Ford Perfect", "John Doe");
  *  static simgrid::config::flag gamma("gamma", "Gamma factor", 1.987);
  *  
*/ @@ -238,6 +237,6 @@ public: } } -XBT_PUBLIC(std::string) xbt_cfg_get_string(const char* name); +XBT_PUBLIC std::string xbt_cfg_get_string(const char* name); #endif