C++ Macro to D mixin template, delegates Please help
BLS
nanali at nospam-wanadoo.fr
Fri Sep 21 03:12:11 PDT 2007
Regan Heath schrieb:
> BLS wrote:
>> Regan Heath schrieb:
>>> Henning Hasemann wrote:
>
> I don't understand. What doesn't the code Henning posted do, that you
> need it to do??
>
Probabely, because I am not genius... :-( I 'd better read it twice!
Just one question : It seems that you use template overloading, or do I
miss something. In other words : Can I use template overloading like
function overloading ?
Many thanks for your efforts, Regan and Henning !
Bjoern
> class Foo {
> void foo() {
> writefln("foo called");
> }
> void bar() {
> writefln("bar called");
> }
>
> mixin MessageMap!(
> OnClose!(foo),
> OnRange!(1, 3, bar)
> );
> }
>
> expands to:
>
> class Foo {
> void foo() {
> writefln("foo called");
> }
> void bar() {
> writefln("bar called");
> }
>
> void newMsgProc(uint uID) { //expands just like "BEGIN_MSG_MAP"
> foreach(mapping; Mappings) { //loops 2x
> if(mapping.matches(uID)) //just like "if (uID == WM_CLOSE)"
> mapping.executeAction(); //just like "vfunc();"
> }
> }
> }
>
> Change MessageMap to expand to the function fignature you want, i.e.
>
> template MessageMap(Mappings ...) {
> override BOOL NewMsgProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM
> lParam, ref LRESULT lResult) {
> foreach(mapping; Mappings) {
> if(mapping.matches(uID))
> mapping.executeAction();
> }
> }
> }
>
> Change MessageMap to return the result of the mapping.executeAction just
> like "return lResult;" in the original C++.
>
> template MessageMap(Mappings ...) {
> override BOOL NewMsgProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM
> lParam, ref LRESULT lResult) {
> foreach(mapping; Mappings) {
> if(mapping.matches(uID)) {
> lResult = mapping.executeAction();
> return cast(BOOL)lResult;
> }
> }
> }
> }
>
> I think it's ok to use mixins as you're desribing, but why do you need
> to do it that way?
>
> Regan
Probabely, because I am not genius... :-( I 'd better read it twice!
Just one question : It seems that you use template overloading, or do I
miss something. In other words is template overloading legal ?
Many thanks for your efforts, Regan and Henning !
Bjoern
More information about the Digitalmars-d-learn
mailing list