# HG changeset patch # User Frank Benoit # Date 1208099944 -7200 # Node ID 89776a9bb8b2886cda11b71327559630ab2bee9e # Parent ef6c06252a877d2769c823eee1d9f3ca2d70bda2 experimental runner factory diff -r ef6c06252a87 -r 89776a9bb8b2 dwtx/jface/operation/IRunnableWithProgress.d --- a/dwtx/jface/operation/IRunnableWithProgress.d Sun Apr 13 16:37:43 2008 +0200 +++ b/dwtx/jface/operation/IRunnableWithProgress.d Sun Apr 13 17:19:04 2008 +0200 @@ -16,6 +16,9 @@ import dwt.dwthelper.utils; +import tango.core.Tuple; +import tango.core.Traits; + /** * The IRunnableWithProgress interface should be implemented by any * class whose instances are intended to be executed as a long-running operation. @@ -50,3 +53,39 @@ */ public void run(IProgressMonitor monitor); } + +class _DgIRunnableWithProgressT(Dg,T...) : IRunnableWithProgress { + + alias ParameterTupleOf!(Dg) DgArgs; + static assert( is(DgArgs == Tuple!(T)) + || is(DgArgs == Tuple!(IProgressMonitor,T)), + "Delegate args not correct" ); + + Dg dg; + T t; + + private this( Dg dg, T t ){ + this.dg = dg; + static if( T.length > 0 ){ + this.t = t; + } + } + + void run( IProgressMonitor pm ){ + static if( is( typeof(dg(pm,t)))){ + dg(pm,t); + } + else static if( is( typeof(dg(t)))){ + dg(t); + } + else{ + static assert( false, "Delegate type is incorrect for arguments supplied"); + } + } +} + +_DgIRunnableWithProgressT!(Dg,T) dgIRunnableWithProgress(Dg,T...)( Dg dg, T args ){ + return new _DgIRunnableWithProgressT!(Dg,T)(dg,args); +} + +