Mercurial > projects > dwt-addons
changeset 57:89776a9bb8b2
experimental runner factory
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 13 Apr 2008 17:19:04 +0200 |
parents | ef6c06252a87 |
children | 8efa0d75df77 |
files | dwtx/jface/operation/IRunnableWithProgress.d |
diffstat | 1 files changed, 39 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 <code>IRunnableWithProgress</code> 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); +} + +