Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the amount of includes teshsuite/simdag
[simgrid.git] / teshsuite / simdag / platforms / flatifier.cpp
index 22d747a..e4e48f5 100644 (file)
@@ -4,24 +4,9 @@
 /* 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. */
 
-#ifndef _XBT_WIN32
-#include <unistd.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <string.h>
-#include <math.h>
-
 #include "src/surf/network_interface.hpp"
 #include "simgrid/simdag.h"
-#include "xbt/log.h"
-#include "xbt/dict.h"
-#include "xbt/ex.h"
 #include "xbt/xbt_os_time.h"
-#include "surf/surf.h"
-#include "src/surf/surf_private.h"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(flatifier, "Logging specific to this platform parsing tool");
 
@@ -38,8 +23,7 @@ static int name_compare_links(const void *n1, const void *n2)
 static int parse_cmdline(int *timings, char **platformFile, int argc, char **argv)
 {
   int wrong_option = 0;
-  int i;
-  for (i = 1; i < argc; i++) {
+  for (int i = 1; i < argc; i++) {
     if (strlen(argv[i]) > 1 && argv[i][0] == '-' && argv[i][1] == '-') {
       if (!strcmp(argv[i], "--timings")) {
         *timings = 1;
@@ -158,29 +142,26 @@ int main(int argc, char **argv)
     xbt_dict_foreach(host_list, cursor_src, src, host1){ // Routes from host
       value1 = sg_host_by_name(src)->pimpl_netcard;
       xbt_dict_foreach(host_list, cursor_dst, dst, host2){ //to host
-        xbt_dynar_t route=NULL;
+        std::vector<Link*> *route = new std::vector<Link*>();
         value2 = sg_host_by_name(dst)->pimpl_netcard;
-        routing_platf->getRouteAndLatency(value1, value2, &route,NULL);
-        if (!xbt_dynar_is_empty(route)){
+        routing_platf->getRouteAndLatency(value1, value2, route,NULL);
+        if (! route->empty()){
           printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
-          for(i=0;i<xbt_dynar_length(route) ;i++){
-            void *link = xbt_dynar_get_as(route,i,void *);
-
-            printf("<%s id=\"%s\"/>",link_ctn,surf_resource_name((surf_cpp_resource_t)link));
-          }
+          for (auto link: *route)
+            printf("<%s id=\"%s\"/>",link_ctn,link->getName());
           printf("\n  </route>\n");
         }
+        delete route;
       }
       xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router
         value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
         if(value2->isRouter()){
           printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
-          xbt_dynar_t route=NULL;
-          routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,&route,NULL);
-          for(i=0;i<xbt_dynar_length(route) ;i++){
-            void *link = xbt_dynar_get_as(route,i,void *);
-            printf("<%s id=\"%s\"/>",link_ctn,surf_resource_name((surf_cpp_resource_t)link));
-          }
+          std::vector<Link*> *route = new std::vector<Link*>();
+          routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route,NULL);
+          for (auto link : *route)
+            printf("<%s id=\"%s\"/>",link_ctn,link->getName());
+          delete route;
           printf("\n  </route>\n");
         }
       }
@@ -193,26 +174,22 @@ int main(int argc, char **argv)
           value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
           if(value2->isRouter()){
             printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
-            xbt_dynar_t route=NULL;
-            routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,&route,NULL);
-            for(i=0;i<xbt_dynar_length(route) ;i++){
-              void *link = xbt_dynar_get_as(route,i,void *);
-
-              printf("<%s id=\"%s\"/>",link_ctn,surf_resource_name((surf_cpp_resource_t)link));
-            }
+            std::vector<Link*> *route = new std::vector<Link*>();
+            routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route,NULL);
+            for(auto link :*route)
+              printf("<%s id=\"%s\"/>",link_ctn,link->getName());
+            delete route;
             printf("\n  </route>\n");
           }
         }
         xbt_dict_foreach(host_list, cursor_dst, dst, value2){ //to host
           printf("  <route src=\"%s\" dst=\"%s\">\n  ",src, dst);
-          xbt_dynar_t route=NULL;
+          std::vector<Link*> *route = new std::vector<Link*>();
           value2 = sg_host_by_name(dst)->pimpl_netcard;
-          routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,&route, NULL);
-          for(i=0;i<xbt_dynar_length(route) ;i++){
-            void *link = xbt_dynar_get_as(route,i,void *);
-
-            printf("<%s id=\"%s\"/>",link_ctn,surf_resource_name((surf_cpp_resource_t)link));
-          }
+          routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route, NULL);
+          for(auto link : *route)
+            printf("<%s id=\"%s\"/>",link_ctn,link->getName());
+          delete route;
           printf("\n  </route>\n");
         }
       }