digitalmars.D.learn - C++ MSG_MAP marcro -> Mixin
- BLS (45/45) Sep 19 2007 Hi,
- BLS (3/55) Sep 19 2007 And I really wonder myself how to (probabely) replace this stuff using
- Daniel Keep (20/75) Sep 19 2007 With enough CTFE, you could do it. I've actually been thinking about
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
Sep 19 2007
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, BjoernAnd I really wonder myself how to (probabely) replace this stuff using Tango's Signal Slot implementation.... but I guess I miss something;
Sep 19 2007
BLS wrote:BLS schrieb: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. -- DanielHi, 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, BjoernAnd I really wonder myself how to (probabely) replace this stuff using Tango's Signal Slot implementation.... but I guess I miss something;
Sep 19 2007
Daniel Keep schrieb:BLS wrote:Thanks Daniel, I am afraid I am not able to follow your suggestion...Can you figure it out please ? // I mean your second solution However, let's say I'll use D template mixins instead of C macros // The known parameters as follows virtual BOOL NewMsgProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM lParam,LRESULT lResult) So : #define ON_MESSAGE_RANGE(MsgF, MsgL, vfunc) \ if(uID >= MsgF && uID <= MsgL) \ { \ lResult=vfunc(uID, wParam, lParam); \ return TRUE; \ } // Replaced with Template Mixin Template ON_MESSAGE_RANGE(M1, M2, F) (M1 MsgF, M2 MsgL, F function(...) dg ) { typeof(dg) dg_m; if(uID >= MsgF && uID <= MsgL) { lResult = dg_m(uID, wParam, lParam); return TRUE; } } is a valid ? I guess - F function(...) dg is not. BjoernBLS schrieb: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. -- DanielHi, 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, BjoernAnd I really wonder myself how to (probabely) replace this stuff using Tango's Signal Slot implementation.... but I guess I miss something;
Sep 20 2007
BLS schrieb:Daniel Keep schrieb:Okay, I think I have to works with delegates instead, bause I have to work on class-members. probabely : Template ON_MESSAGE_RANGE(M1, M2, D) (M1 MsgF, M2 MsgL, D delegate(...) dg ) { if(uID >= MsgF && uID <= MsgL) { lResult = dg(uID, wParam, lParam); return TRUE; } } Is a reasonable solution... However, I am not sure.BLS wrote:Thanks Daniel, I am afraid I am not able to follow your suggestion...Can you figure it out please ? // I mean your second solution However, let's say I'll use D template mixins instead of C macros // The known parameters as follows virtual BOOL NewMsgProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM lParam,LRESULT lResult) So : #define ON_MESSAGE_RANGE(MsgF, MsgL, vfunc) \ if(uID >= MsgF && uID <= MsgL) \ { \ lResult=vfunc(uID, wParam, lParam); \ return TRUE; \ } // Replaced with Template Mixin Template ON_MESSAGE_RANGE(M1, M2, F) (M1 MsgF, M2 MsgL, F function(...) dg ) { typeof(dg) dg_m; if(uID >= MsgF && uID <= MsgL) { lResult = dg_m(uID, wParam, lParam); return TRUE; } } is a valid ? I guess - F function(...) dg is not. BjoernBLS schrieb: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. -- DanielHi, 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, BjoernAnd I really wonder myself how to (probabely) replace this stuff using Tango's Signal Slot implementation.... but I guess I miss something;
Sep 20 2007