flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Easy inheriting of structures.

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Playing with Fresh, I wanted to make some more complex data structures for different type of files, so I realized that I need some OO-like inheriting of data structures. Of course there is standard way to do this, like Windows do it in many of internal structures (for example see the description of NM_LISTVIEW structure):

Code:
; Standard inheriting.
struc Header {
  .field1 dd ?
  .field2 dd ?
}

struc Inherited {
  .hdr  Header
  .add1 dd ?
  .add2 dd ?
}
    


I made it this way many times, but now I decide to play a little. Here is the result and I think it is more suitable than standard approach:

Code:
struc TCommonFile {
  .type         dd      ?
  .hFileName    dd      ?
  .hashFileName dd      ?

  .fLoaded      dd      ?
  .fNeverSaved  dd      ?
}
struct TCommonFile

struc TFormSource {
  . TCommonFile
  .ptrFormFile  dd      ?
}
struct TFormSource

struc TBinaryForm {
  . TCommonFile
  .ptrBaseWin  dd       ?       ; pointer to the TBaseWin of the form.
}
struct TBinaryForm

; now you can use the structures followind way:

BinaryForm TBinaryForm

        mov     eax, [esi+TCommonFile.hFileName]
        mov     ebx, [esi+TFormSource..hFileName]
        mov     ecx, [esi+TBinaryForm..hashFileName]
        mov     esi, [esi+TBinaryForm.ptrBaseWin]
        cmp     [BinaryForm..fLoaded], FALSE
    



Regards.
Post 05 Mar 2004, 11:24
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 875
Location: Colombia
pelaillo
Nice trick!
The number of points indicates the degree of inherition and we save the extra chars. The code is more readable.
Post 05 Mar 2004, 13:03
View user's profile Send private message Yahoo Messenger Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S.
Cool!!
I like its simplicity Smile

But, what do you think about solving "double dot problem" ?
Currently, I'm playing with some modification of huge Privalov's "struct" macro, posted somewhere here. (well, trying to understand it)
It's incomplete yet, but such things are already possible:
mov eax, [esi+TCommonFile.hFileName]
mov ebx, [esi+TFormSource.hFileName]

At the moment it has some problem, when complex structures are inherited with overriding of default values. Overriding works for simple fields like DWORD, but not for TCommonFile.
In the case posted here this doesn't matter, since there are just "dd ?" fields.
I can post current unfinished version, if you think 2 dots are bit boring and illogical Wink (though, I'd like to finish it before posting)
Post 05 Mar 2004, 14:07
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
S.T.A.S. wrote:
But, what do you think about solving "double dot problem" ?


Well, maybe it is feature, not a problem. Smile As pelaillo writes in above post, double point shows that the field is inherited. Smile
In addition, I don't want to make it via kilometer long macroses. It is the KISS principle - "keep it short and simple".
For example, base "struct" macro is KISS-macro, while extended Privalov's variant is maybe more powerfull, but it is not KISS-macro.

Regards.
Post 05 Mar 2004, 14:23
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S.
JohnFound wrote:
Well, maybe it is feature, not a problem..

Yes, I see your point. It's useful, indeed. (and I write it with ")
That's why I renamed "not KISS-macro" into "class" - it has another purpose.


BTW, could you say something about string constant macro? Is it a KISS-macro or not?
I hoped I could be useful for Fresh..
Post 05 Mar 2004, 16:19
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
S.T.A.S. wrote:
BTW, could you say something about string constant macro? Is it a KISS-macro or not? I hoped I could be useful for Fresh..


Well I like it. It is complex enough, but still it is the simplest solution of this proble - i.e. KISS. Very Happy I think to include it in Fresh standard macro library, but not immediately and maybe in some modified mode (I don't like so many period signs. I understand that you want to make it more global with adding .const.dw for example, but maybe separate names are more appropriate in this case.)

Regards.

P.S. btw, if you want to contribute to Fresh, in this moment, there are some freezed tasks, that need solution, but I have no time for them... for example visible controls style editor - Scientica was wrote one, but it is obsolete, because of changes in the design and he visibly have no time to renew it.
Post 05 Mar 2004, 16:40
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S.
JohnFound wrote:
I don't like so many period signs. I understand that you want to make it more global with adding .const.dw for example, but maybe separate names are more appropriate in this case.
Oh, name is the less important part of this macro for me.
I think this macro is to be integrated into something like invoke.


P.S.
About style editor.. I must say, I'm quite unpractised with GUI (and many other parts of API). Embarassed
I'd skip even DispatchMessage in damn window I must create, but this works a bit buggy in XP..
May be something else if I'll have time and knowledge
Post 05 Mar 2004, 23:00
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.