More Flexible Structure Extends

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
deathmx
User
User
Posts: 34
Joined: Mon Feb 26, 2018 3:14 am

More Flexible Structure Extends

Post by deathmx »

This would really help in cleaning up structures.

Code: Select all


Structure IsBeautiful
 AlwaysisBeautiful.i  
EndStructure

Structure IsGettingMoreBeautiful
  AlwaysisgettingmoreBeautiful.i
EndStructure



Structure Purebasic
  
  Extends IsBeautiful
  
  astimepasses.i
  
  Extends IsGettingMoreBeautiful
  
EndStructure


Creates:

Structure Purebasic
  AlwaysisBeautiful.i  
  astimepasses.i
  AlwaysisgettingmoreBeautiful.i
EndStructure

;yes i maybe kissing ass.. but, I do love this language lol.

User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: More Flexible Structure Extends

Post by mk-soft »

It would violate the rules of structural extension.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
deathmx
User
User
Posts: 34
Joined: Mon Feb 26, 2018 3:14 am

Re: More Flexible Structure Extends

Post by deathmx »

Please elaborate :) , it can still eaisly be made compatible with the previous behaviour.

Is there is something i missing?
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: More Flexible Structure Extends

Post by #NULL »

PureBasic only supports single inheritance, not multiple inheritance. So in the following example the procedure p() can access \a always at the same offset (at the beginning of the structure), even if an sB or sC object is passed to p().

Code: Select all

Structure sA
  a.i
EndStructure

Structure sB Extends sA
  b.i
EndStructure

Structure sC Extends sB
  c.i
EndStructure

Procedure p(*p.sA)
  Debug *p\a
EndProcedure

Define.sA a\a = 11
Define.sB b\a = 22
Define.sC c\a = 33

p(@a) ; 11
p(@b) ; 22
p(@c) ; 33

Debug OffsetOf(sA\a) ; 0
Debug OffsetOf(sB\a) ; 0
Debug OffsetOf(sC\a) ; 0
With multiple inheritance like this..

Code: Select all

Structure sX Extends sB, sA
  x.i
EndStructure
..either sB or sA will be at a different offset than 0, so for passing an sX to p() the offset of \a will be different than if an sA is passed.
deathmx
User
User
Posts: 34
Joined: Mon Feb 26, 2018 3:14 am

Re: More Flexible Structure Extends

Post by deathmx »

Sorry, looks like i wasn't clear. I was actually requesting Multiple Inheritance.


Somewhat like this... it would be nice to do this without macros. Especially since ide doesn't detect whats going on in the macros.

Code: Select all


Macro Extends_SA
  a.i
EndMacro

Macro Extends_SB
  
  b.i
  Extends_SA
EndMacro


Structure SA
  a.i
EndStructure

Structure SB
  
  b.i
  Extends_SA
EndStructure

Structure sC
  c.i
  Extends_SB
EndStructure

Procedure p(*p.sA)
  Debug *p\a
EndProcedure

Define.sA a\a = 11
Define.sB b\a = 22
Define.sC c\a = 33

p(@a) ; 11  11
p(@b) ; 22   0
p(@c) ; 33   0

Debug OffsetOf(sA\a) ; 0  0
Debug OffsetOf(sB\a) ; 0  8
Debug OffsetOf(sC\a) ; 0  16



User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: More Flexible Structure Extends

Post by Demivec »

Your request is similar to anonymous structures and anonymous unions.
Post Reply