programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Snippet: writing readable 'C' structure

From: Charles Melice <mail_at_forthcad.com>
Date: Mon, 10 May 1999 17:25:20 +0100

A basic, but valuable usage of a class system in Windows programming: I use
it also to define 'C' structure.

The following is snippet from my class-pakage.

\ -----------------------------------
\ Special class to define structure.
\ -----------------------------------

Class cStruct

Public \ Data types
    : _WPAD bl word drop ; \ not signifiant in WIN32
    : DWORD 1 cells buffer: ;
    : INT DWORD ;
    : LONG DWORD ;
    : UINT DWORD ;
    : LPSTR DWORD ;
    : COLORREF DWORD ;
    : WORD 2 chars buffer: ;
    : SHORT WORD ;
    : BYTE 1 chars buffer: ;
    : CHARS: chars buffer: ; ( n <<name>> -- )
    : LARGE_INTEGER 2 cells buffer: ;

[DEFINED] FPMATH [IF]
    : FLOAT 1 sfloats buffer: ;
    : DOUBLE 1 dfloats buffer: ;
[THEN]

Public \ utilities
    : ADDR ( addr ) ^this @ ;
    : StructSIZE ( -- size ) ^self @ SIZEOF ;
    : Clear ( -- ) ^this @ StructSIZE erase ;
End

\ ------------------------------------------------
\ A example of cStruct usage. Readable, Isn't ?
\ ------------------------------------------------

cStruct SubClass BITMAPINFOHEADER
Public
   DWORD biSize
   LONG biWidth
   LONG biHeight
   WORD biPlanes
   WORD biBitCount
   DWORD biCompression
   DWORD biSizeImage
   LONG biXPelsPerMeter
   LONG biYPelsPerMeter
   DWORD biClrUsed
   DWORD biClrImportant
End

________
Charles Melice
mail_at_forthcad.com
http://www.forthcad.com

.
Received on Mon May 10 1999 - 17:25:20 PDT

This archive was generated by hypermail 2.2.0 : Wed Jan 07 2009 - 03:04:06 PST