[Gambas-devel] Multi-level virtual objects, inheritance and symbol resolution mess

Tobias Boege taboege at ...176...
Fri Sep 5 21:26:58 CEST 2014


Hi Benoit,

I'm almost done with implementing an adjacency matrix based Graph class
(GraphMatrix), to then set the Graph interface in stone. See #6451 for
the code I'll talk about.

Only there is one obstacle to overcome: accessing symbols of a
GraphMatrix.Vertices[sVertex] object. The situation is as follows:

  - GraphMatrix Inherits Graph (which is an "abstract" class).
  - .Vertices is a virtual object whose _get method calls back:
  - Me._getVertex (which is within GraphMatrix and) which returns a:
  - _Graph_Vertex, a virtual class which is the base of all implementation-
    specific vertex classes.
  - In case of GraphMatrix, this is a _Matrix_Vertex virtual class which
    Inherits _Graph_Vertex.

>From there I want to access the InDegree property which is properly
implemented in the _Matrix_Vertex class but all I get is ("a" is an existing
vertex in the graph):

  hGraph.Vertices["a"].InDegree
  >> (Function GraphMatrix:3)

Indeed, InDegree is the 3rd symbol in _Matrix_Vertex. If I issue

  hGraph.Vertices["a"].InDegree()
  >> Error: Not enough arguments

The 3rd symbol in GraphMatrix is _getEdge which needs two arguments... If I
try that:

  hGraph.Vertices["a"].InDegree("b", "a")
  >> Error: Edge does not exist

which is the error I would expect from my graph if I called the _getEdge
method! It seems like the InDegree property is not mapped to my
_Matrix_Vertex.InDegree implementation but to the method of same index in
GraphMatrix.

_Matrix_Vertex actually is a virtual class obtained via a virtual class
interface from GraphMatrix. Is the virtual class information lost somewhere
on the way or do I exceed a limit here?

---

So, in a nutshell: GraphMatrix.Vertices is a virtual class which calls back
GraphMatrix._getVertex which returns another virtual object from which I
want to access a property.

In a graph class (ImageGraph) implemented in Gambas -- where there are no
virtual classes -- the _ImageGraph_Vertex Inherits _Graph_Vertex is a real
class. And there it works!

Attached are: the project which uses the native GraphMatrix class and fails,
and the working ImageGraph Gambas class. I would really like to finish this
thing soon. If you could take a good look, that would surely be a great help.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graphmatrix-test-0.0.1.tar.gz
Type: application/octet-stream
Size: 3870 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20140905/a79e6439/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GraphFloodfill-0.1.1.tar.gz
Type: application/octet-stream
Size: 7545 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20140905/a79e6439/attachment-0001.obj>


More information about the Devel mailing list