voile.judge
judgement モジュール
複数の要素でチェックを行いたい場合に使用することのできる Judgement が利用可能
Date:
December 08, 2008
Author:
P.Knowledge, SHOO
Lisence:
NYSL ( http://www.kmonos.net/nysl/ )
- class
JudgementException
: object.Exception;
- 審判を含めて投げることのできる例外
投げる際にJudgementオブジェクトを含めて投げることが可能です。
auto dJudge = new Judgement;
...
if (dJudge.bad)
{
throw new JudgementException(dJudge);
}
- Judgement
judgement
;
- Judgementオブジェクトへのアクセス
- this(Judgement aJudge, string file = null, int line = 0);
- コンストラクタ
- Object[]
results
();
- See Also:
Judgement.result()
- int
opApply
(int delegate(ref Object) dg);
int
opApply
(int delegate(ref int, ref Object) dg);
- See Also:
Judgement.
opApply
()
- class
Judgement
;
- 審判クラス
discuss() 関数の引数の結果が、存在するか否かで審判を下す。
詳しくは discuss() 関数を参照。
また、 discuss() 関数により審判を行ったあとは results() 関数で結果を得ること
が可能。 results() 関数は、 discuss() を行う際の引数に指定した文字列や Object
実行する際に生じた例外などが含まれます。
ヘルパ関数の judge() 関数と with 文と if 文、 ok ステータスを使うとスマートに
見えるかも?
Example:
void checkFunc()
{
if (a.checked && b.checked)
{
throw new Exception("conflict switches 'a' and 'b'.");
}
}
void func()
{
with (judge(checkFunc))
{
if (ok)
{
status = "OK";
}
else
{
status = "NG [" ~ messages[0].toString ~ "]";
}
}
}
- typeof(this)
discuss
(T...)(lazy T args);
- 審議
引数を指定して審判を行います。
下記の、引数の説明にあるリストの実行結果を判定し、
- 引数
- 引数の実行結果
- 引数の実行に際して生じる例外
- 引数のdelegateやfunctionの実行結果
- 引数のdelegateやfunctionの実行に際して生じる例外
を検出し、結果に加えます。
実行の結果、nullを返すというのが良い結果であり、戻り値が発生する場合、
審判に否決したということになります。
審判の結果は success や rejection またはそれらのすきな別名を使用して得る
とが可能です。
ダイレクトに結果を得たい場合は results() 関数を呼び出すことで結果を出す
過程において生じた Object の配列を得ることが可能です。
Params:
args |
下記リスト参照
- char[]
- char[][]
- Object
- Object[]
- char[] delegate()
- char[][] delegate()
- Object delegate()
- Object[] delegate()
- bool delegate()
- void delegate()
- char[] function()
- char[][] function()
- Object function()
- Object[] function()
- bool function()
- void function()
- 上記delegateおよびfunctionの実行結果
複数の指定が可能です。
引数のlazy属性によって、引数の順番通りの実行が保障されます。
必ず1つ以上の引数を指定してください。 |
Returns:
自分自身を返します
- final bool
success
();
alias
succeed
;
alias
ok
;
alias
good
;
alias
pass
;
alias
passed
;
- 可決
- final bool
rejection
();
alias
rejected
;
alias
failure
;
alias
fail
;
alias
ng
;
alias
bad
;
- 否決
- final Object[]
results
();
- 結果
生じた Object のリストを返します。
審判ではこの戻り値がnullであることが望ましい。
- final int
opApply
(int delegate(ref Object) dg);
- foreach (d; judgement.result)と同義
- final int
opApply
(int delegate(ref int, ref Object) dg);
- foreach (i, d; judgement.result)と同義
- final char[]
toString
();
- 文字列を返す
Returns:
results のそれぞれのオブジェクトの
toString
で得られる文字列を改行でつ
ないだ文字列を返します。
- final void
throwIfFailure
(bool doCopy = true);
- 例外を投げる
Throws:
JudgementException=自身を含めたJudgementExceptionを投げる
- Judgement
judge
(T...)(lazy T args);
- Judgementクラスのヘルパ関数
インスタンスオブジェクトを生成し、審議し、返す。
Params:
args |
Judgement.discuss() の引数 |
Returns:
審議した後の Judgement オブジェクト
|