Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
empty a C->C++ wrapper that will soon die
[simgrid.git] / src / xbt / config.cpp
index 242483b..9e896f3 100644 (file)
 #include <typeinfo>
 #include <vector>
 
-#include <xbt/ex.hpp>
-#include <xbt/config.h>
-#include <xbt/config.hpp>
+#include "simgrid/sg_config.hpp"
+#include "xbt/dynar.h"
+#include "xbt/log.h"
 #include "xbt/misc.h"
 #include "xbt/sysdep.h"
-#include "xbt/log.h"
-#include "xbt/dynar.h"
+#include <xbt/config.h>
+#include <xbt/config.hpp>
+#include <xbt/ex.hpp>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support");
 
-XBT_EXPORT_NO_IMPORT(xbt_cfg_t) simgrid_config = nullptr;
-extern "C" XBT_PUBLIC void sg_config_finalize();
+XBT_EXPORT_NO_IMPORT xbt_cfg_t simgrid_config = nullptr;
 
 namespace simgrid {
 namespace config {
@@ -263,7 +263,7 @@ private:
   bool warn_for_aliases = true;
 
 public:
-  Config() = default;
+  Config();
   ~Config();
 
   // No copy:
@@ -297,6 +297,10 @@ protected:
   ConfigurationElement* getDictElement(const char* name);
 };
 
+Config::Config()
+{
+  atexit(&sg_config_finalize);
+}
 Config::~Config()
 {
   XBT_DEBUG("Frees cfg set %p", this);
@@ -399,10 +403,8 @@ void alias(const char* realname, const char* aliasname)
 template <class T>
 XBT_PUBLIC void declareFlag(const char* name, const char* description, T value, std::function<void(const T&)> callback)
 {
-  if (simgrid_config == nullptr) {
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
-    atexit(sg_config_finalize);
-  }
   simgrid_config->registerOption<T>(
     name, description, std::move(value), std::move(callback));
 }
@@ -420,7 +422,10 @@ template XBT_PUBLIC void declareFlag(const char* name, const char* description,
 
 // ***** C bindings *****
 
-xbt_cfg_t xbt_cfg_new()        { return new simgrid::config::Config(); }
+xbt_cfg_t xbt_cfg_new()
+{
+  return new simgrid::config::Config();
+}
 void xbt_cfg_free(xbt_cfg_t * cfg) { delete *cfg; }
 
 void xbt_cfg_dump(const char *name, const char *indent, xbt_cfg_t cfg)
@@ -440,37 +445,29 @@ void xbt_cfg_register_double(const char *name, double default_value,
 
 void xbt_cfg_register_int(const char *name, int default_value,xbt_cfg_cb_t cb_set, const char *desc)
 {
-  if (simgrid_config == nullptr) {
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
-    atexit(&sg_config_finalize);
-  }
   simgrid_config->registerOption<int>(name, desc, default_value, cb_set);
 }
 
 void xbt_cfg_register_string(const char *name, const char *default_value, xbt_cfg_cb_t cb_set, const char *desc)
 {
-  if (simgrid_config == nullptr) {
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
-    atexit(sg_config_finalize);
-  }
   simgrid_config->registerOption<std::string>(name, desc, default_value ? default_value : "", cb_set);
 }
 
 void xbt_cfg_register_boolean(const char *name, const char*default_value,xbt_cfg_cb_t cb_set, const char *desc)
 {
-  if (simgrid_config == nullptr) {
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
-    atexit(sg_config_finalize);
-  }
   simgrid_config->registerOption<bool>(name, desc, simgrid::config::parseBool(default_value), cb_set);
 }
 
 void xbt_cfg_register_alias(const char *realname, const char *aliasname)
 {
-  if (simgrid_config == nullptr) {
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
-    atexit(sg_config_finalize);
-  }
   simgrid_config->alias(realname, aliasname);
 }
 
@@ -760,7 +757,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_cfg);
 
 XBT_TEST_SUITE("config", "Configuration support");
 
-XBT_PUBLIC_DATA(xbt_cfg_t) simgrid_config;
+XBT_PUBLIC_DATA xbt_cfg_t simgrid_config;
 
 static void make_set()
 {