X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/29a3b2869c0075fc75e8ccc66fc1d9c4c8bf6a85..bf5d9a3ed276303ac434aaeb44f406c2b7dcdb90:/src/kernel/routing/DijkstraZone.cpp diff --git a/src/kernel/routing/DijkstraZone.cpp b/src/kernel/routing/DijkstraZone.cpp index f065cbc748..25818ae500 100644 --- a/src/kernel/routing/DijkstraZone.cpp +++ b/src/kernel/routing/DijkstraZone.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2009-2019. 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. */ @@ -8,6 +8,7 @@ #include "src/surf/network_interface.hpp" #include "src/surf/xml/platf_private.hpp" #include "surf/surf.hpp" +#include "xbt/string.hpp" #include #include @@ -26,7 +27,7 @@ public: int graph_id_ = -1; /* used for caching internal graph id's */ }; -DijkstraZone::DijkstraZone(NetZoneImpl* father, std::string name, resource::NetworkModel* netmodel, bool cached) +DijkstraZone::DijkstraZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel, bool cached) : RoutedZone(father, name, netmodel), cached_(cached) { } @@ -56,7 +57,6 @@ void DijkstraZone::seal() /* Add the loopback if needed */ if (network_model_->loopback_ && hierarchy_ == RoutingMode::base) { - xbt_dynar_foreach (xbt_graph_get_nodes(route_graph_), cursor, node) { bool found = false; xbt_edge_t edge = nullptr; @@ -77,7 +77,7 @@ void DijkstraZone::seal() } /* initialize graph indexes in nodes after graph has been built */ - xbt_dynar_t nodes = xbt_graph_get_nodes(route_graph_); + const_xbt_dynar_t nodes = xbt_graph_get_nodes(route_graph_); xbt_dynar_foreach (nodes, cursor, node) { GraphNodeData* data = static_cast(xbt_graph_node_get_data(node)); @@ -118,15 +118,14 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr /* if the src and dst are the same */ if (src_node_id == dst_node_id) { - xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t); xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t); xbt_edge_t edge = xbt_graph_get_edge(route_graph_, node_s_v, node_e_v); if (edge == nullptr) - THROWF(arg_error, 0, "No route from '%s' to '%s'", src->get_cname(), dst->get_cname()); + throw std::invalid_argument(xbt::string_printf("No route from '%s' to '%s'", src->get_cname(), dst->get_cname())); - RouteCreationArgs* e_route = static_cast(xbt_graph_edge_get_data(edge)); + const RouteCreationArgs* e_route = static_cast(xbt_graph_edge_get_data(edge)); for (auto const& link : e_route->link_list) { route->link_list.insert(route->link_list.begin(), link); @@ -169,9 +168,9 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr xbt_dynar_foreach (xbt_graph_node_get_outedges(v_node), cursor, edge) { xbt_node_t u_node = xbt_graph_edge_get_target(edge); - GraphNodeData* data = static_cast(xbt_graph_node_get_data(u_node)); + const GraphNodeData* data = static_cast(xbt_graph_node_get_data(u_node)); int u_id = data->graph_id_; - RouteCreationArgs* tmp_e_route = static_cast(xbt_graph_edge_get_data(edge)); + const RouteCreationArgs* tmp_e_route = static_cast(xbt_graph_edge_get_data(edge)); int cost_v_u = tmp_e_route->link_list.size(); /* count of links, old model assume 1 */ if (cost_v_u + cost_arr[v_id] < cost_arr[u_id]) { @@ -193,11 +192,11 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr xbt_edge_t edge = xbt_graph_get_edge(route_graph_, node_pred_v, node_v); if (edge == nullptr) - THROWF(arg_error, 0, "No route from '%s' to '%s'", src->get_cname(), dst->get_cname()); + throw std::invalid_argument(xbt::string_printf("No route from '%s' to '%s'", src->get_cname(), dst->get_cname())); - RouteCreationArgs* e_route = static_cast(xbt_graph_edge_get_data(edge)); + const RouteCreationArgs* e_route = static_cast(xbt_graph_edge_get_data(edge)); - NetPoint* prev_gw_src = gw_src; + const NetPoint* prev_gw_src = gw_src; gw_src = e_route->gw_src; NetPoint* gw_dst = e_route->gw_dst; @@ -249,7 +248,7 @@ void DijkstraZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, Net new_edge(dst->id(), src->id(), new_extended_route(hierarchy_, dst, src, gw_dst, gw_src, link_list, symmetrical, 0)); } -void DijkstraZone::new_edge(int src_id, int dst_id, simgrid::kernel::routing::RouteCreationArgs* route) +void DijkstraZone::new_edge(int src_id, int dst_id, RouteCreationArgs* route) { XBT_DEBUG("Create Route from '%d' to '%d'", src_id, dst_id); @@ -265,15 +264,17 @@ void DijkstraZone::new_edge(int src_id, int dst_id, simgrid::kernel::routing::Ro // Make sure that this graph edge was not already added to the graph if (xbt_graph_get_edge(route_graph_, src, dst) != nullptr) { if (route->gw_dst == nullptr || route->gw_src == nullptr) - THROWF(arg_error, 0, "Route from %s to %s already exists", route->src->get_cname(), route->dst->get_cname()); + throw std::invalid_argument( + xbt::string_printf("Route from %s to %s already exists", route->src->get_cname(), route->dst->get_cname())); else - THROWF(arg_error, 0, "Route from %s@%s to %s@%s already exists", route->src->get_cname(), - route->gw_src->get_cname(), route->dst->get_cname(), route->gw_dst->get_cname()); + throw std::invalid_argument(xbt::string_printf("Route from %s@%s to %s@%s already exists", + route->src->get_cname(), route->gw_src->get_cname(), + route->dst->get_cname(), route->gw_dst->get_cname())); } // Finally add it xbt_graph_new_edge(route_graph_, src, dst, route); } -} -} -} // namespace +} // namespace routing +} // namespace kernel +} // namespace simgrid