[Gambas-devel] Multi-level virtual objects, inheritance and symbol resolution mess
Benoît Minisini
gambas at ...1...
Sat Sep 6 17:50:00 CEST 2014
Le 06/09/2014 16:39, Benoît Minisini a écrit :
> Le 05/09/2014 21:26, Tobias Boege a écrit :
>> 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
>>
>
> I'm currently looking at it...
>
OK. As I thought, the "_" prefix was the problem. I fixed the
interpreter so that it decides that a native class is virtual by taking
into account the "GB_VIRTUAL_CLASS()" declaration, not just the initial
dot in the name.
But there is another problem:
hGraphMatrix.Vertices[] calls GraphVertices_get, which calls the
"_getVertex" method. As "_getVertex" returns a "virtual object", no
dynamic calling can occur, and the InDegree property of _Graph_Vertex is
called, never the InDegree property of _Matrix_Vertex.
I have no solution at the moment...
--
Benoît Minisini
More information about the Devel
mailing list