Changeset 8

Show
Ignore:
Timestamp:
11/17/06 18:20:45 (2 years ago)
Author:
baxissimo
Message:

Added first arg offset capability

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/luigi/signalobj.d

    r7 r8  
    116116     * have it.) 
    117117     */ 
    118     slot_key fconnect(DT)(DT f) 
     118    slot_key fconnect(DT,int arg_offset=0)(DT f) 
    119119    { 
    120120        // make the key 
     
    124124        //slot_t f_wrap = SlotAdapter!(slot_t).adapt(f); 
    125125        // wrap is safer for now. 
    126         slot_t f_wrap = SlotAdapter!(slot_t).wrap(f); 
     126        slot_t f_wrap; 
     127        f_wrap = SlotAdapter!(slot_t).wrap!(typeof(f),arg_offset)(f); 
    127128 
    128129        s.connect(f_wrap); 
     
    130131        thunkMap[f_key]=f_wrap; 
    131132        return f_key; 
     133    } 
     134    // this doesn't quite work yet because of DMD bug #540 
     135    // Name also has to be different from 'fconnect' for what also looks  
     136    // to be a compiler bug.  They should be able to co-exist.  
     137    template fconnecti(int arg_offset) { 
     138        slot_key fconnecti(DT)(DT f) 
     139        { 
     140            return fconnect!(DT,arg_offset)(f); 
     141        } 
    132142    } 
    133143 
     
    183193    static assert( is(slot_ret_t==void), "Expected native slot type to return void."  ); 
    184194     
    185     slot_t wrap(WrapSlotT)(WrapSlotT fn) { 
     195    slot_t wrap(WrapSlotT,int arg_offset=0)(WrapSlotT fn) { 
    186196        alias WrapSlotT wrap_slot_t; 
    187197        alias ReturnType!(fn) wrap_ret_t; 
    188198        alias ParameterTypeTuple!(fn) wrap_arg_t; 
    189199 
    190         // This has to be a class for std.signal's use, currently 
     200        // This has to be a _class_ for std.signal's use, currently 
    191201        class Inner { 
    192202            wrap_slot_t thunked_slot; 
    193203            void slot(slot_arg_t arg)  
    194204            { 
    195                 thunked_slot(arg[0..wrap_arg_t.length]); 
     205                thunked_slot(arg[arg_offset..wrap_arg_t.length+arg_offset]); 
    196206            } 
    197207        } 
    198208        Inner inner = new Inner; 
    199         inner.thunked_slot = fn;  
     209        inner.thunked_slot = fn; 
    200210        return &inner.slot; 
    201211    } 
    202212 
    203     SigSlotT adapt(WrapSlotT)(WrapSlotT fn
     213    slot_t adapt(WrapSlotT)(WrapSlotT fn, int arg_offset=0
    204214    { 
    205215        static if (is(slot_t==WrapSlotT)) { 
     
    214224        } 
    215225        else { 
    216             return wrap(fn); 
     226            return wrap(fn,arg_offset); 
    217227        } 
    218228    } 
     
    350360    fsig.fconnect(&func3ldr); 
    351361 
    352     //fsig.fconnect(&func1s, 1); // someday! 
     362    // Connect, but skip the first arg of the signal 
     363    // I.e. just subscribe to the string part of the message. 
     364    // This IFTI limitation is annoying! 
     365    // fsig.fconnecti!(1)(&func1s); 
     366    fsig.fconnect!(typeof(&func1s),1)(&func1s); 
    353367 
    354368    slot_key literal =