VILLASframework / common

Archived: The libvillas-common library has been integrated into the VILLASnode repo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vertex id seems to never get initialized

IgnoreWarnings opened this issue · comments

file: vertex.hpp
problem: Vertex id never gets initialized
solution proposal: static member to hold next free id and increment and assignment in constructor
observations:

  • id is private
  • no setter
  • no inheritance
  • id used by serval methods but read only

should be moved to the submodule common.

This is the member variable in question:

The vertex id must be unique per graph not globally.

So there is a lastVertexId in directed.hpp which gets set in the Vertex here:

vertex->id = lastVertexId++;

Thanks for insight. This however breaks encapsulation, since the member is declared private and accessed via pointer.

Since its not unique per vertex, I will just initialize default value in header.

This however breaks encapsulation, since the member is declared private and accessed via pointer.

Can you elaborate on this?

I think vertices must only be created by DirectedGraph:: addVertex(). Maybe we should declare its constructor private..

the member id is declared private

private:
Identifier id;

and accessed via pointer.

the member id is declared private

This is okay as the graph class is a friend of the vertex