Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
code simplification around simgrid::surf::NetCardImpl
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 11 Feb 2016 23:00:53 +0000 (00:00 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 11 Feb 2016 23:00:53 +0000 (00:00 +0100)
src/surf/sg_platf.cpp
src/surf/surf_routing.cpp
src/surf/surf_routing.hpp

index 7badc2a..8156a97 100644 (file)
@@ -71,7 +71,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
     current_routing->p_hierarchy = SURF_ROUTING_BASE;
 
   simgrid::surf::NetCard *netcard =
-      new simgrid::surf::NetCardImpl(xbt_strdup(host->id), -1, SURF_NETWORK_ELEMENT_HOST, current_routing);
+      new simgrid::surf::NetCardImpl(host->id, SURF_NETWORK_ELEMENT_HOST, current_routing);
 
   netcard->setId(current_routing->parsePU(netcard));
   sg_host_t h = simgrid::s4u::Host::by_name_or_create(host->id);
@@ -129,8 +129,7 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router)
              "Reading a router, processing unit \"%s\" already exists",
              router->id);
 
-  simgrid::surf::NetCard *info = new simgrid::surf::NetCardImpl(
-    xbt_strdup(router->id), -1, SURF_NETWORK_ELEMENT_ROUTER, current_routing);
+  simgrid::surf::NetCard *info = new simgrid::surf::NetCardImpl(router->id, SURF_NETWORK_ELEMENT_ROUTER, current_routing);
   info->setId(current_routing->parsePU(info));
   xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) info);
   XBT_DEBUG("Having set name '%s' id '%d'", router->id, info->getId());
index 5416cbf..126f532 100644 (file)
@@ -197,11 +197,7 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
   new_as->p_hierarchy = SURF_ROUTING_NULL;
   new_as->p_name = xbt_strdup(AS->id);
 
-  simgrid::surf::NetCard *info =
-    new simgrid::surf::NetCardImpl(xbt_strdup(new_as->p_name),
-                                            -1,
-                                            SURF_NETWORK_ELEMENT_AS,
-                                            current_routing);
+  simgrid::surf::NetCard *info = new simgrid::surf::NetCardImpl(new_as->p_name, SURF_NETWORK_ELEMENT_AS, current_routing);
   if (current_routing == NULL && routing_platf->p_root == NULL) {
 
     /* it is the first one */
index 6096197..5c59098 100644 (file)
@@ -110,8 +110,10 @@ public:
 
 struct XBT_PRIVATE NetCardImpl : public NetCard {
 public:
-  NetCardImpl(char *name, int id, e_surf_network_element_type_t rcType, As *rcComponent)
-  : p_rcComponent(rcComponent), p_rcType(rcType), m_id(id), p_name(name) {}
+  NetCardImpl(const char *name, e_surf_network_element_type_t rcType, As *rcComponent)
+  : p_rcComponent(rcComponent),
+    p_rcType(rcType),
+    p_name(xbt_strdup(name)) {}
   ~NetCardImpl() { xbt_free(p_name);};
 
   int getId() {return m_id;}
@@ -123,7 +125,7 @@ public:
 private:
   As *p_rcComponent;
   e_surf_network_element_type_t p_rcType;
-  int m_id;
+  int m_id = -1;
   char *p_name;
 };