Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Exposing a pointer to internals is not considered as good OOP practices
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 14 Feb 2016 11:06:49 +0000 (12:06 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 14 Feb 2016 11:06:49 +0000 (12:06 +0100)
Plus, that was amusingly useless here.

src/surf/surf_routing.hpp
src/surf/surf_routing_dijkstra.cpp

index e7242e8..b0d8e0a 100644 (file)
@@ -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_;
index cd6d5e4..c5a59fa 100644 (file)
@@ -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;