www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Help converting a headerfile to D

reply Oliver <Oliver_member pathlink.com> writes:
Hello there !

I am converting a GUI C-API to D and have 2 questions concerning headerfiles.

1. How would I convert these ? 

typedef void (*WindowFunc)      (Window *w);
typedef void (*WindowMouseFunc) (Window *w, int buttons, Point xy);
typedef void (*WindowKeyFunc)   (Window *w, unsigned long key);
typedef void (*WindowDrawFunc)  (Window *w, Graphics *g);

typedef void (*ControlFunc)     (Control *c);
typedef void (*MouseFunc)       (Control *c, int buttons, Point xy);
typedef void (*KeyFunc)         (Control *c, unsigned long key);
typedef void (*DrawFunc)        (Control *c, Graphics *g);

typedef void (*MenuAction)      (MenuItem *mi);

typedef void (*TimerAction)     (Timer *t);

2. And these ?

#define app_copy_rect(g,dp,src,sr) ((g)->copy_rect((g),(dp),(src),(sr)))
#define app_fill_rect(g,r)         ((g)->fill_rect((g),(r)))
#define app_draw_utf8(g,p,utf8,nb) ((g)->draw_utf8((g),(p),(utf8),(nb)))
#define app_draw_line(g,p1,p2)     ((g)->draw_line((g),(p1),(p2)))
(g is some struct)


Help would be greatly appreciated.

Regards, Oliver
May 15 2005
parent reply "Unknown W. Brackets" <unknown simplemachines.org> writes:
For the first section, change "unsigned long" to "uint" and you're done. 
  Unless you don't want them to be typedefs, but rather aliases - in 
this case, change "typedef" to "alias".

For the second, write them as functions (which will be inlined):

whatever app_copy_rect(whatever g, whatever dp, whatever src, whatever sr)
{
	return g.copy_rect(g, dp, src, sr);
}

-[Unknown]


 Hello there !
 
 I am converting a GUI C-API to D and have 2 questions concerning headerfiles.
 
 1. How would I convert these ? 
 
 typedef void (*WindowFunc)      (Window *w);
 typedef void (*WindowMouseFunc) (Window *w, int buttons, Point xy);
 typedef void (*WindowKeyFunc)   (Window *w, unsigned long key);
 typedef void (*WindowDrawFunc)  (Window *w, Graphics *g);
 
 typedef void (*ControlFunc)     (Control *c);
 typedef void (*MouseFunc)       (Control *c, int buttons, Point xy);
 typedef void (*KeyFunc)         (Control *c, unsigned long key);
 typedef void (*DrawFunc)        (Control *c, Graphics *g);
 
 typedef void (*MenuAction)      (MenuItem *mi);
 
 typedef void (*TimerAction)     (Timer *t);
 
 2. And these ?
 
 #define app_copy_rect(g,dp,src,sr) ((g)->copy_rect((g),(dp),(src),(sr)))
 #define app_fill_rect(g,r)         ((g)->fill_rect((g),(r)))
 #define app_draw_utf8(g,p,utf8,nb) ((g)->draw_utf8((g),(p),(utf8),(nb)))
 #define app_draw_line(g,p1,p2)     ((g)->draw_line((g),(p1),(p2)))
 (g is some struct)
 
 
 Help would be greatly appreciated.
 
 Regards, Oliver
 
 
May 15 2005
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Unknown W. Brackets" <unknown simplemachines.org> wrote in message 
news:d68ur1$pq7$1 digitaldaemon.com...
 For the first section, change "unsigned long" to "uint" and you're done. 
 Unless you don't want them to be typedefs, but rather aliases - in this 
 case, change "typedef" to "alias".
Ooh, and if you're passing in class refs (like Window and Control), be sure to remove the pointer symbol (*) in the parameter lists. If they're structs, though, leave the pointer symbol there.
May 16 2005
parent Chris Sauls <ibisbasenji gmail.com> writes:
Jarrett Billingsley wrote:
 Ooh, and if you're passing in class refs (like Window and Control), be sure 
 to remove the pointer symbol (*) in the parameter lists.  If they're 
 structs, though, leave the pointer symbol there. 
Or get rid of the pointer symbol anyway and use an inout parameter. -- Chris Sauls
May 19 2005