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:
common/include/villas/graph/vertex.hpp
Line 38 in 618804a
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:
common/include/villas/graph/directed.hpp
Line 90 in 618804a
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
common/include/villas/graph/vertex.hpp
Lines 37 to 38 in 618804a
and accessed via pointer.
the member id is declared private
This is okay as the graph class is a friend of the vertex