howto workaround interfaces?

General FreeBASIC programming questions.
RockTheSchock
Posts: 221
Joined: Mar 12, 2006 16:25

howto workaround interfaces?

Postby RockTheSchock » Aug 09, 2016 18:32

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: 1374
Joined: Feb 26, 2007 5:32

Re: howto workaround interfaces?

Postby caseih » Aug 09, 2016 19:18

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: 221
Joined: Mar 12, 2006 16:25

Re: howto workaround interfaces?

Postby RockTheSchock » Aug 09, 2016 22:31

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: 2108
Joined: Sep 25, 2005 21:54

Re: howto workaround interfaces?

Postby srvaldez » Aug 09, 2016 23:38

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

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests