Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
code simplification: write the recursivity properly
[simgrid.git] / src / surf / surf_routing.cpp
index 1728b56..d4cd3d5 100644 (file)
@@ -35,8 +35,6 @@ namespace routing {
  * @brief A library containing all known hosts
  */
 
-int COORD_HOST_LEVEL = -1;         //Coordinates level
-
 int MSG_FILE_LEVEL = -1;             //Msg file level
 
 int SIMIX_STORAGE_LEVEL = -1;        //Simix storage level
@@ -62,8 +60,7 @@ simgrid::kernel::routing::NetCard *sg_netcard_by_name_or_null(const char *name)
 }
 
 /* Global vars */
-simgrid::kernel::routing::RoutingPlatf *routing_platf = nullptr;
-
+simgrid::kernel::routing::RoutingPlatf* routing_platf = new simgrid::kernel::routing::RoutingPlatf();
 
 void sg_platf_new_trace(sg_platf_trace_cbarg_t trace)
 {
@@ -98,44 +95,20 @@ namespace routing {
  */
 void RoutingPlatf::getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Link*> * route, double *latency)
 {
-  XBT_DEBUG("getRouteAndLatency from %s to %s", src->name(), dst->name());
+  XBT_DEBUG("getRouteAndLatency from %s to %s", src->name().c_str(), dst->name().c_str());
 
   AsImpl::getRouteRecursive(src, dst, route, latency);
 }
 
-static xbt_dynar_t _recursiveGetOneLinkRoutes(AsImpl *as)
+std::vector<Onelink*>* RoutingPlatf::getOneLinkRoutes()
 {
-  xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
-
-  //adding my one link routes
-  xbt_dynar_t onelink_mine = as->getOneLinkRoutes();
-  if (onelink_mine)
-    xbt_dynar_merge(&ret,&onelink_mine);
-
-  //recursing
-  char *key;
-  xbt_dict_cursor_t cursor = nullptr;
-  AsImpl *rc_child;
-  xbt_dict_foreach(as->children(), cursor, key, rc_child) {
-    xbt_dynar_t onelink_child = _recursiveGetOneLinkRoutes(rc_child);
-    if (onelink_child)
-      xbt_dynar_merge(&ret,&onelink_child);
-  }
-  return ret;
-}
-
-xbt_dynar_t RoutingPlatf::getOneLinkRoutes(){
-  return _recursiveGetOneLinkRoutes(root_);
+  std::vector<Onelink*>* res = new std::vector<Onelink*>();
+  root_->getOneLinkRoutes(res);
+  return res;
 }
 
 }}}
 
-/** @brief create the root AS */
-void routing_model_create(Link *loopback)
-{
-  routing_platf = new simgrid::kernel::routing::RoutingPlatf(loopback);
-}
-
 /* ************************************************************************** */
 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
 
@@ -167,10 +140,7 @@ void routing_exit() {
   delete routing_platf;
 }
 
-simgrid::kernel::routing::RoutingPlatf::RoutingPlatf(simgrid::surf::Link *loopback)
-: loopback_(loopback)
-{
-}
+simgrid::kernel::routing::RoutingPlatf::RoutingPlatf() = default;
 simgrid::kernel::routing::RoutingPlatf::~RoutingPlatf()
 {
   delete root_;