diff options
author | John Wiegley <johnw@newartisans.com> | 2010-05-12 04:32:02 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-05-12 04:32:02 -0400 |
commit | 5f1a858941adc17fcf714c7b6b176aeae727c436 (patch) | |
tree | 846efb794cb76fdc4c63fa4c6ab554b83af49f07 /src/xact.cc | |
parent | 7ca8149ec5c7fa88d98df83e6260210372223036 (diff) | |
parent | cb047c013df0eaf1c5e9edd67bbb6b6fa537d2a0 (diff) | |
download | fork-ledger-5f1a858941adc17fcf714c7b6b176aeae727c436.tar.gz fork-ledger-5f1a858941adc17fcf714c7b6b176aeae727c436.tar.bz2 fork-ledger-5f1a858941adc17fcf714c7b6b176aeae727c436.zip |
Merge branch 'next'
Diffstat (limited to 'src/xact.cc')
-rw-r--r-- | src/xact.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/xact.cc b/src/xact.cc index 1a022387..344f66ea 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -36,6 +36,7 @@ #include "account.h" #include "journal.h" #include "pool.h" +#include "interactive.h" namespace ledger { @@ -483,6 +484,36 @@ namespace { value_t get_wrapper(call_scope_t& scope) { return (*Func)(find_scope<xact_t>(scope)); } + + value_t fn_any(call_scope_t& scope) + { + interactive_t args(scope, "X&X"); + + post_t& post(find_scope<post_t>(scope)); + expr_t& expr(args.get<expr_t&>(0)); + + foreach (post_t * p, post.xact->posts) { + bind_scope_t bound_scope(scope, *p); + if (expr.calc(bound_scope).to_boolean()) + return true; + } + return false; + } + + value_t fn_all(call_scope_t& scope) + { + interactive_t args(scope, "X&X"); + + post_t& post(find_scope<post_t>(scope)); + expr_t& expr(args.get<expr_t&>(0)); + + foreach (post_t * p, post.xact->posts) { + bind_scope_t bound_scope(scope, *p); + if (! expr.calc(bound_scope).to_boolean()) + return false; + } + return true; + } } expr_t::ptr_op_t xact_t::lookup(const symbol_t::kind_t kind, @@ -492,6 +523,13 @@ expr_t::ptr_op_t xact_t::lookup(const symbol_t::kind_t kind, return item_t::lookup(kind, name); switch (name[0]) { + case 'a': + if (name == "any") + return WRAP_FUNCTOR(&fn_any); + else if (name == "all") + return WRAP_FUNCTOR(&fn_all); + break; + case 'c': if (name == "code") return WRAP_FUNCTOR(get_wrapper<&get_code>); |