From 1b220223e4eacd6859fb69d4f7abe06270d85dbb Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 21 Jul 2017 19:28:15 +0200 Subject: [PATCH 1/1] kill another dict in the C++ world --- src/include/surf/surf.h | 3 --- src/surf/sg_platf.cpp | 2 +- src/surf/surf_interface.hpp | 8 ++------ src/surf/xml/surfxml_parseplatf.cpp | 32 ++++++++++++----------------- 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 4a43c922e0..6d3b3b9c32 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -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. diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 663f8c8d50..e3760856f0 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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(tmgr_trace), nullptr); + traces_set_list.insert({trace->id, tmgr_trace}); } diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 3ee42ebf17..63a79ae068 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -14,6 +14,7 @@ #include #include +#include #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 surf_path; +extern XBT_PRIVATE std::unordered_map 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 * **********/ diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index 5f02c5230a..0e905d76dd 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -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 traces_set_list; XBT_PRIVATE std::unordered_map trace_connect_list_host_avail; XBT_PRIVATE std::unordered_map trace_connect_list_host_speed; XBT_PRIVATE std::unordered_map trace_connect_list_link_avail; XBT_PRIVATE std::unordered_map trace_connect_list_link_bw; XBT_PRIVATE std::unordered_map 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) -- 2.20.1