From: Martin Quinson Date: Sun, 14 Feb 2016 11:06:49 +0000 (+0100) Subject: Exposing a pointer to internals is not considered as good OOP practices X-Git-Tag: v3_13~837 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5fedb73886fa7c03fcc89ca008fb7a6dc72d80a1?ds=inline Exposing a pointer to internals is not considered as good OOP practices Plus, that was amusingly useless here. --- diff --git a/src/surf/surf_routing.hpp b/src/surf/surf_routing.hpp index e7242e85cb..b0d8e0a3c7 100644 --- a/src/surf/surf_routing.hpp +++ b/src/surf/surf_routing.hpp @@ -36,7 +36,6 @@ class NetCard { public: virtual ~NetCard(){}; virtual int id()=0; // Our rank in the vertices_ array of our containing AS. - virtual int *getIdPtr()=0; virtual void setId(int id)=0; virtual char *name()=0; virtual As *containingAS()=0; // This is the AS in which I am @@ -113,12 +112,11 @@ public: {} ~NetCardImpl() { xbt_free(name_);}; - int id() {return id_;} - int *getIdPtr() {return &id_;} - void setId(int id) {id_ = id;} - char *name() {return name_;} - As *containingAS() {return containingAS_;} - e_surf_network_element_type_t getRcType() {return componentType_;} + int id() override {return id_;} + void setId(int id) override {id_ = id;} + char *name() override {return name_;} + As *containingAS() override {return containingAS_;} + e_surf_network_element_type_t getRcType() override {return componentType_;} private: int id_ = -1; char *name_; diff --git a/src/surf/surf_routing_dijkstra.cpp b/src/surf/surf_routing_dijkstra.cpp index cd6d5e4ffd..c5a59fadf6 100644 --- a/src/surf/surf_routing_dijkstra.cpp +++ b/src/surf/surf_routing_dijkstra.cpp @@ -201,11 +201,8 @@ void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c /* set utils vars */ srcDstCheck(src, dst); - int *src_id = src->getIdPtr(); - int *dst_id = dst->getIdPtr(); - - if (!src_id || !dst_id) - THROWF(arg_error,0,"No route from '%s' to '%s'",src->name(),dst->name()); + int src_id = src->id(); + int dst_id = dst->id(); int *pred_arr = NULL; sg_platf_route_cbarg_t e_route; @@ -215,8 +212,8 @@ void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph); /* Use the graph_node id mapping set to quickly find the nodes */ - graph_node_map_element_t src_elm = nodeMapSearch(*src_id); - graph_node_map_element_t dst_elm = nodeMapSearch(*dst_id); + graph_node_map_element_t src_elm = nodeMapSearch(src_id); + graph_node_map_element_t dst_elm = nodeMapSearch(dst_id); int src_node_id = ((graph_node_data_t) xbt_graph_node_get_data(src_elm->node))->graph_id; int dst_node_id = ((graph_node_data_t) xbt_graph_node_get_data(dst_elm->node))->graph_id;