From 7bac600c529ba83f8f246a2dcfa9ddd9c0095675 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 12 Feb 2016 00:00:53 +0100 Subject: [PATCH 1/1] code simplification around simgrid::surf::NetCardImpl --- src/surf/sg_platf.cpp | 5 ++--- src/surf/surf_routing.cpp | 6 +----- src/surf/surf_routing.hpp | 8 +++++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 7badc2a405..8156a97657 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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()); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 5416cbf0d3..126f532e91 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -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 */ diff --git a/src/surf/surf_routing.hpp b/src/surf/surf_routing.hpp index 6096197350..5c59098d20 100644 --- a/src/surf/surf_routing.hpp +++ b/src/surf/surf_routing.hpp @@ -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; }; -- 2.20.1