Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill another dict in the C++ world
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 21 Jul 2017 17:28:15 +0000 (19:28 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 21 Jul 2017 17:28:15 +0000 (19:28 +0200)
src/include/surf/surf.h
src/surf/sg_platf.cpp
src/surf/surf_interface.hpp
src/surf/xml/surfxml_parseplatf.cpp

index 4a43c92..6d3b3b9 100644 (file)
@@ -434,9 +434,6 @@ XBT_PUBLIC_DATA(xbt_dict_t) current_property_set;// the prop set for the current
 /* surf parse file related (public because called from a test suite) */
 XBT_PUBLIC(void) parse_platform_file(const char *file);
 
-/* For the trace and trace:connect tag (store their content till the end of the parsing) */
-XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
-
 /*
  * Returns the initial path. On Windows the initial path is the current directory for the current process in the other
  * case the function returns "./" that represents the current directory on Unix/Linux platforms.
index 663f8c8..e376085 100644 (file)
@@ -711,5 +711,5 @@ void sg_platf_new_trace(sg_platf_trace_cbarg_t trace)
         "Trace '%s' must have either a content, or point to a file on disk.",trace->id);
     tmgr_trace = tmgr_trace_new_from_string(trace->id, trace->pc_data, trace->periodicity);
   }
-  xbt_dict_set(traces_set_list, trace->id, static_cast<void*>(tmgr_trace), nullptr);
+  traces_set_list.insert({trace->id, tmgr_trace});
 }
index 3ee42eb..63a79ae 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <boost/intrusive/list.hpp>
 #include <string>
+#include <unordered_map>
 
 #define NO_MAX_DURATION -1.0
 
@@ -29,6 +30,7 @@ extern XBT_PRIVATE double sg_bandwidth_factor;
 extern XBT_PRIVATE double sg_weight_S_parameter;
 extern XBT_PRIVATE int sg_network_crosstraffic;
 extern XBT_PRIVATE std::vector<std::string> surf_path;
+extern XBT_PRIVATE std::unordered_map<std::string, tmgr_trace_t> traces_set_list;
 
 extern "C" {
 XBT_PUBLIC(double) surf_get_clock();
@@ -61,12 +63,6 @@ enum heap_action_type{
   NOTSET
 };
 
-/*********
- * Trace *
- *********/
-/* For the trace and trace:connect tag (store their content till the end of the parsing) */
-XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
-
 /**********
  * Action *
  **********/
index 5f02c52..0e905d7 100644 (file)
@@ -27,20 +27,19 @@ extern "C" {
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
 
-SG_BEGIN_DECL()
 
 /* Trace related stuff */
-
-xbt_dict_t traces_set_list = nullptr;
+XBT_PRIVATE std::unordered_map<std::string, tmgr_trace_t> traces_set_list;
 XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_host_avail;
 XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_host_speed;
 XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_link_avail;
 XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_link_bw;
 XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_link_lat;
 
+SG_BEGIN_DECL()
 void sg_platf_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect)
 {
-  xbt_assert(xbt_dict_get_or_null(traces_set_list, trace_connect->trace),
+  xbt_assert(traces_set_list.find(trace_connect->trace) != traces_set_list.end(),
              "Cannot connect trace %s to %s: trace unknown", trace_connect->trace, trace_connect->element);
 
   switch (trace_connect->kind) {
@@ -116,15 +115,13 @@ void parse_platform_file(const char *file)
     after_config_done = 0;
     surf_parse_open(file);
 
-    traces_set_list = xbt_dict_new_homogeneous(nullptr);
-
     /* Do the actual parsing */
     parse_status = surf_parse();
 
     /* connect all traces relative to hosts */
     for (auto elm : trace_connect_list_host_avail) {
-      tmgr_trace_t trace = (tmgr_trace_t)xbt_dict_get_or_null(traces_set_list, elm.first.c_str());
-      xbt_assert(trace, "Trace %s undefined", elm.first.c_str());
+      xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str());
+      tmgr_trace_t trace = traces_set_list.at(elm.first);
 
       simgrid::s4u::Host* host = sg_host_by_name(elm.second.c_str());
       xbt_assert(host, "Host %s undefined", elm.second.c_str());
@@ -134,8 +131,8 @@ void parse_platform_file(const char *file)
     }
 
     for (auto elm : trace_connect_list_host_speed) {
-      tmgr_trace_t trace = (tmgr_trace_t)xbt_dict_get_or_null(traces_set_list, elm.first.c_str());
-      xbt_assert(trace, "Trace %s undefined", elm.first.c_str());
+      xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str());
+      tmgr_trace_t trace = traces_set_list.at(elm.first);
 
       simgrid::s4u::Host* host = sg_host_by_name(elm.second.c_str());
       xbt_assert(host, "Host %s undefined", elm.second.c_str());
@@ -145,8 +142,8 @@ void parse_platform_file(const char *file)
     }
 
     for (auto elm : trace_connect_list_link_avail) {
-      tmgr_trace_t trace = (tmgr_trace_t)xbt_dict_get_or_null(traces_set_list, elm.first.c_str());
-      xbt_assert(trace, "Trace %s undefined", elm.first.c_str());
+      xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str());
+      tmgr_trace_t trace = traces_set_list.at(elm.first);
 
       sg_link_t link = simgrid::s4u::Link::byName(elm.second.c_str());
       xbt_assert(link, "Link %s undefined", elm.second.c_str());
@@ -154,24 +151,21 @@ void parse_platform_file(const char *file)
     }
 
     for (auto elm : trace_connect_list_link_bw) {
-      tmgr_trace_t trace = (tmgr_trace_t)xbt_dict_get_or_null(traces_set_list, elm.first.c_str());
-      xbt_assert(trace, "Trace %s undefined", elm.first.c_str());
+      xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str());
+      tmgr_trace_t trace = traces_set_list.at(elm.first);
       sg_link_t link = simgrid::s4u::Link::byName(elm.second.c_str());
       xbt_assert(link, "Link %s undefined", elm.second.c_str());
       link->setBandwidthTrace(trace);
     }
 
     for (auto elm : trace_connect_list_link_lat) {
-      tmgr_trace_t trace = (tmgr_trace_t)xbt_dict_get_or_null(traces_set_list, elm.first.c_str());
-      xbt_assert(trace, "Trace %s undefined", elm.first.c_str());
+      xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str());
+      tmgr_trace_t trace = traces_set_list.at(elm.first);
       sg_link_t link = simgrid::s4u::Link::byName(elm.second.c_str());
       xbt_assert(link, "Link %s undefined", elm.second.c_str());
       link->setLatencyTrace(trace);
     }
 
-    /* Free my data */
-    xbt_dict_free(&traces_set_list);
-
     surf_parse_close();
 
     if (parse_status)