Changeset 6

Show
Ignore:
Timestamp:
11/30/06 11:58:48 (2 years ago)
Author:
lindquist
Message:

Changed multidg.d to use variadic templates
Fixed a warning in paint.d and added -w to win32.brf

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/minwin/multidg.d

    r5 r6  
    1 /* MultiDelegate: add, remove and fire multiple delegates  
     1/* MultiDelegate: add, remove and fire multiple delegates 
    22 * 
    33 * A multi-delegate is similar to a C# multicast delegate. 
     
    77 * in the order they were added. 
    88 * 
    9  * A MultiBoolDelegate is a multi-delegates where each  
     9 * A MultiBoolDelegate is a multi-delegates where each 
    1010 * delegate returns a bool and the result of executing 
    1111 * the MultiBoolDelegate is the or'ed value of all the bools. 
     
    1919 * explained at http://creativecommons.org/licenses/publicdomain 
    2020 * Email comments and bug reports to ben.hinkle@gmail.com 
    21  */  
     21 */ 
    2222 
    2323module minwin.multidg; 
     
    5555 
    5656  bool isEmpty() { 
    57     if (dgs.length == 0)  
     57    if (dgs.length == 0) 
    5858      return true; 
    5959    else if (dgs[0] is null) 
     
    6464 
    6565  // the array of delegate with possible trailing nulls 
    66   Callback[] dgs;  
     66  Callback[] dgs; 
    6767} 
    6868 
    69 // MultiDelegate with no args 
    70 struct MultiDelegate() { 
    71   alias void delegate() Callback; 
     69// MultiDelegate with variadic args 
     70struct MultiDelegate(T...) 
     71
     72  alias void delegate(T) Callback; 
    7273  mixin DelegateMixin!(); 
    73   void opCall() { 
     74  void opCall(T args) { 
    7475    foreach( Callback dg; dgs) { 
    7576      if (dg is null) break; 
    76       dg(); 
     77      dg(args); 
    7778    } 
    7879  } 
    7980} 
    8081 
    81 // MultiDelegate with one arg 
    82 struct MultiDelegate(T) { 
    83   alias void delegate(T arg) Callback; 
     82// MultiBoolDelegate with variadic args 
     83struct MultiBoolDelegate(T...) { 
     84  alias bool delegate(T) Callback; 
    8485  mixin DelegateMixin!(); 
    85   void opCall(T arg) { 
    86     foreach( Callback dg; dgs) { 
    87       if (dg is null) break; 
    88       dg(arg); 
    89     } 
    90   } 
    91 
    92  
    93 // MultiDelegate with two args 
    94 struct MultiDelegate(T1,T2) { 
    95   alias void delegate(T1 arg1,T2 arg2) Callback; 
    96   mixin DelegateMixin!(); 
    97   void opCall(T1 arg1,T2 arg2) { 
    98     foreach( Callback dg; dgs) { 
    99       if (dg is null) break; 
    100       dg(arg1,arg2); 
    101     } 
    102   } 
    103 
    104  
    105 // MultiDelegate with three args 
    106 struct MultiDelegate(T1,T2,T3) { 
    107   alias void delegate(T1 arg1,T2 arg2,T3 arg3) Callback; 
    108   mixin DelegateMixin!(); 
    109   void opCall(T1 arg1,T2 arg2,T3 arg3) { 
    110     foreach( Callback dg; dgs) { 
    111       if (dg is null) break; 
    112       dg(arg1,arg2,arg3); 
    113     } 
    114   } 
    115 
    116  
    117 // MultiDelegate with four args 
    118 struct MultiDelegate(T1,T2,T3,T4) { 
    119   alias void delegate(T1 arg1,T2 arg2,T3 arg3,T4 arg4) Callback; 
    120   mixin DelegateMixin!(); 
    121   void opCall(T1 arg1,T2 arg2,T3 arg3,T4 arg4) { 
    122     foreach( Callback dg; dgs) { 
    123       if (dg is null) break; 
    124       dg(arg1,arg2,arg3,arg4); 
    125     } 
    126   } 
    127 
    128  
    129 // MultiBoolDelegate with no args 
    130 struct MultiBoolDelegate() { 
    131   alias bool delegate() Callback; 
    132   mixin DelegateMixin!(); 
    133   bool opCall() { 
     86  bool opCall(T args) { 
    13487    bool result = false; 
    13588    foreach( Callback dg; dgs) { 
    13689      if (dg is null) break; 
    137       result |= dg(); 
    138     } 
    139     return result; 
    140   } 
    141 
    142  
    143 // MultiBoolDelegate with one arg 
    144 struct MultiBoolDelegate(T) { 
    145   alias bool delegate(T arg) Callback; 
    146   mixin DelegateMixin!(); 
    147   bool opCall(T arg) { 
    148     bool result = false; 
    149     foreach( Callback dg; dgs) { 
    150       if (dg is null) break; 
    151       result |= dg(arg); 
    152     } 
    153     return result; 
    154   } 
    155 
    156  
    157 // MultiBoolDelegate with two args 
    158 struct MultiBoolDelegate(T1,T2) { 
    159   alias bool delegate(T1 arg1,T2 arg2) Callback; 
    160   mixin DelegateMixin!(); 
    161   bool opCall(T1 arg1,T2 arg2) { 
    162     bool result = false; 
    163     foreach( Callback dg; dgs) { 
    164       if (dg is null) break; 
    165       result |= dg(arg1,arg2); 
    166     } 
    167     return result; 
    168   } 
    169 
    170  
    171 // MultiBoolDelegate with three args 
    172 struct MultiBoolDelegate(T1,T2,T3) { 
    173   alias bool delegate(T1 arg1,T2 arg2,T3 arg3) Callback; 
    174   mixin DelegateMixin!(); 
    175   bool opCall(T1 arg1,T2 arg2,T3 arg3) { 
    176     bool result = false; 
    177     foreach( Callback dg; dgs) { 
    178       if (dg is null) break; 
    179       result |= dg(arg1,arg2,arg3); 
    180     } 
    181     return result; 
    182   } 
    183 
    184  
    185 // MultiBoolDelegate with four args 
    186 struct MultiBoolDelegate(T1,T2,T3,T4) { 
    187   alias bool delegate(T1 arg1,T2 arg2,T3 arg3,T4 arg4) Callback; 
    188   mixin DelegateMixin!(); 
    189   bool opCall(T1 arg1,T2 arg2,T3 arg3,T4 arg4) { 
    190     bool result = false; 
    191     foreach( Callback dg; dgs) { 
    192       if (dg is null) break; 
    193       result |= dg(arg1,arg2,arg3,arg4); 
     90      result |= dg(args); 
    19491    } 
    19592    return result; 
     
    20097  /** Example class illustrating multi-delegates based on Qt's example at 
    20198   *    http://doc.trolltech.com/3.3/signalsandslots.html 
    202    *   
     99   * 
    203100   */ 
    204101  class Foo { 
  • trunk/minwin/paint.d

    r5 r6  
    108108    case PaintMode.Or: nmode = SRCPAINT; break; 
    109109    case PaintMode.Xor: nmode = SRCINVERT; break; 
     110    default: assert(0); 
    110111    } 
    111112    return nmode; 
  • trunk/minwin/win32.brf

    r5 r6  
    66-lib 
    77-g 
     8-w