C++ MSG_MAP marcro -> Mixin
Daniel Keep
daniel.keep.lists at gmail.com
Wed Sep 19 17:00:57 PDT 2007
BLS wrote:
> BLS schrieb:
>> Hi,
>> MFC and wxWidgets are supporting MESSAGEMAPS macros. I would like to
>> port them to D.
>>
>> class CMsg
>> {
>> public:
>>
>> virtual BOOL NewMsgProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM
>> lParam,LRESULT lResult)
>> {
>> return FALSE;
>> }
>> };
>>
>> Okay, here iy goes ....
>> #define BEGIN_MSG_MAP() \
>> public: \
>> virtual BOOL NewMsgProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM
>> lParam,LRESULT& lResult) \
>> { \
>> #define ON_MESSAGE(Msg, vfunc) \
>> if(uID == Msg) \
>> { \
>> vfunc(uID, wParam, lParam); \
>> lResult = 0; \
>> return TRUE; \
>> }
>>
>> #define ON_MESSAGE_RANGE(MsgF, MsgL, vfunc) \
>> if(uID >= MsgF && uID <= MsgL) \
>> { \
>> lResult=vfunc(uID, wParam, lParam); \
>> return TRUE; \
>> }
>>
>> #define ON_COMMAND_CONTROL(iControl, iEvent, vfunc) \
>> if(uID == WM_COMMAND && iControl == LOWORD(wParam) && iEvent ==
>> HIWORD(wParam)) \
>> { \
>> vfunc(HIWORD(wParam), LOWORD(wParam), (HWND)lParam); \
>> lResult = 0; \
>> return TRUE; \
>> }
>>
>> and so on....
>>
>> Is it possible to replace this C++ Macros with D2 Mixins and compile
>> time manipulation of strings ?
>> How ?
>> Thanks, Bjoern
>
> And I really wonder myself how to (probabely) replace this stuff using
> Tango's Signal Slot implementation.... but I guess I miss something;
With enough CTFE, you could do it. I've actually been thinking about
making a generator ctfe compiler (but haven't got *any* free time at the
moment).
If I were doing this, I'd probably try something along these lines:
mixin(wxMsgMap(`
on(id1) handler1;
on(id2) handler2;
on(id3..id6) handler3;
`));
Parsing that shouldn't be too difficult. Of course, there are other
ways of constructing this:
mixin wxMsgMap!(
OnMessage!(id1, handler1),
OnMessage!(id2, handler2),
OnMessage!(id3, id6, handler3)
);
Where wxMsgMap takes a tuple of templated OnMessage structs.
Just some ideas.
-- Daniel
More information about the Digitalmars-d-learn
mailing list