voile.dgfn

Delegate Function モジュール

デリゲートと関数ポインタどちらでも利用可能な引数なんかの場合に、分けるのが 面倒くさいので、一元的に取り扱えるようにするのがこのモジュールです。 以下が使用可能です。
  • DelegateFunction
  • dgfn


Date:
December 08, 2008

Author:
P.Knowledge, SHOO

Lisence:
NYSL ( http://www.kmonos.net/nysl/ )



class DelegateFunction (R,A...);
デリゲートファンクションクラス

関数ポインタとデリゲートを同等に扱えるようにするためのクラス。


Example:
 class X
 {
     real func()
     {
         return 10.0L;
     }
 }

 real func()
 {
     return 20.0L;
  }

 testfunc()
 {
     scope fn1 = dgfn(&func);
     scope x = new X;
     typeof(dgfn(&x.func)) fn2 = dgfn(&(x.func));
     assert(fn1() == 20.0L);
     assert(fn2() == 10.0L);
 }


alias DelegateType ;


alias FunctionType ;


CallType callType ();
関数呼び出しの種類

DGならdelegate, FNならfunction, NOなら何も設定されていない状態

this();
this(DelegateType aDelegate);
this(DelegateFunction aDelegate);
コンストラクタ

void opAssign (FunctionType aFunction);
void opAssign (DelegateType aDelegate);
関数の代入

関数ポインタやデリゲートを代入することで、関数ポインタやデリゲートに 変更することが可能。

bool isFunction ();
現在設定されている関数が、関数ポインタかどうか

Returns:
関数ポインタならば true が返る。

bool isDelegate ();
現在設定されている関数が、デリゲートかどうか

Returns:
デリゲートならば true が返る。

FunctionType getFunction ();
関数ポインタとして設定されていた関数を得る。

関数ポインタが設定されていた場合はその関数ポインタを返します。
デリゲートが設定されていた場合は .funcptr の値を返します。

Returns:
設定されていた関数ポインタが返る。

DelegateType getDelegate ();
デリゲートとして設定されていた関数を得る。

必ずこの関数を呼び出す前に設定されている関数がデリゲートであることを確認 しておいてください。

Returns:
設定されていたデリゲートが返る。

R opCall (A args);
関数の呼び出し

関数ポインタかデリゲートかを判定し、呼び出す。
どちらの場合も同様に扱うことが可能。

DelegateFunction!(R,A) dgfn (R, A...)(R function(A) aFunction);
DelegateFunction!(R,A) dgfn (R, A...)(R delegate(A) aDelegate);
ヘルパ関数

DelegateFunction を与えられた function あるいは delegate から自動生成する。

Params:
aFunction 関数ポインタ
aDelegate デリゲート

Returns:
生成される DelegateFunction

Page was generated with on Fri Apr 3 17:07:43 2009