howto workaround interfaces?

General FreeBASIC programming questions.
Post Reply
RockTheSchock
Posts: 252
Joined: Mar 12, 2006 16:25

howto workaround interfaces?

Post by RockTheSchock »

How would you implement interfaces when you would write sort of a java parser -> freebasic generator. I would like to write something to automatically translate awt/swing classes and interfaces. I thought to generate fb headers from java source code for public methods and fields and later reimplement java awt/swing core in freebasic.

How would i deal with multiple interfaces? Or is there a chance to get interfaces in some months?
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: howto workaround interfaces?

Post by caseih »

In C++ I think we'd use pure virtual abstract classes and multiple inheritance. In FB, there's no multiple inheritance So that wouldn't work if the class implemented more than one interface. So that's a tough one! I'm not sure how you would go about doing this.
RockTheSchock
Posts: 252
Joined: Mar 12, 2006 16:25

Re: howto workaround interfaces?

Post by RockTheSchock »

i am learning more and more about the vtable design. FBC repository and wikipedia is my friend: https://en.wikipedia.org/wiki/Virtual_method_table.

And there was a nice diagram by fxm. Hope i understood it correctly. Some thought how to implement interfaces with only abstract methods:

- we would need a second vtable ( vitable) ptr for objects containing references to the actual implemented virt. procedures.
- implementing multiple interfaces means we need to have a list of RTTIinfo for interfaces
- we need to check for cyclic ...
- the "is" operator needs to check also vitable->RTTIinfo
- at initialisiation there have to be done much more
- an interface extends object implicitly


something like this? am i right?

Code: Select all

' Extended Vptr/Vtable/RTTIinfo diagram
'
'                                     Vtable
'                             .---------------------.
'                         (-2)|    reserved (0)     |               RTTIinfo
'    Instance of UDT          |---------------------|       .-----------------------.
'    Extending Object     (-1)|   Ptr to RTTIinfo   |--->(0)|     reserved (0)      |    Mangled Typename
' .-------------------.       |---------------------|       |-----------------------|       .--------.
' |Vptr: Ptr to Vtable|--->(0)|Ptr to virt. proc. #1|   (+1)|Ptr to Mangled Typename|--->(0)| Length |
' |-------------------|       |---------------------|       |-----------------------|       | (ASCII)|
' |  typeNameString() |   (+1)|Ptr to virt. proc. #2|   (+2)| Ptr to Base RTTIinfo  |--.    |    &   |
' |  typeNameEqual()  |       |---------------------|       |_______________________|  |    |Typename|
' |  virtualProcPtr() |   (+2)|Ptr to virt. proc. #3|                                  |    | (ASCII)|
' |-------------------|       |_____________________|                                  |    |________|
' |Viptr:PTR to VITable-.                                                              |
' |-------------------| |            VITable             ______________________________|
' |UDT member field #1| |     .---------------------.   |
' |UDT member field #2| | (-2)|    reserved (0)     |   |            Base RTTIinfo
' |UDT member field #3| |     |---------------------|   |     .----------------------------.
' :                   : | (-1)|   Ptr to IRTTIinfo  |-. '->(0)|        reserved (0)        |
' |___________________| |     |---------------------| |       |----------------------------|
'                       '->(0)|Ref to virt. proc. #x| |   (+1)|Ptr to Mangled Base Typename|--->
'                             |---------------------| |       |----------------------------|
'                                                     |   (+2)| Ptr to Base.Base RTTIinfo  |--.
'                              IRTTIinfo              |       |____________________________|  |
'                   .----------------------------.    |
'                (0)|          elements          |<---'                                                                                          
'                   .----------------------------.
'               (+1)|Ptr to Mangled Base Typename|--->
'               (+2)|Ptr to Base.Base RTTIinfo   |--->
'                   .----------------------------.  
'               (+3)|Ptr to Mangled Base Typename|--->
'               (+4)|Ptr to Base.Base RTTIinfo   |--->
'                   |____________________________|  
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: howto workaround interfaces?

Post by srvaldez »

have you asked José Roca at http://www.planetsquires.com/protect/forum/ ?
he's an expert on low level COM and lately he's been busy writing classes in FB
Post Reply