summaryrefslogtreecommitdiff
path: root/src/post.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-03-03 16:29:59 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-03-03 16:29:59 -0400
commit9ae28a160a4af46dca9eb5b5f270b01acf3eb721 (patch)
tree14c68e57ccfc1eaba61dff368c7626f5ff52ff43 /src/post.cc
parentc305db937c761e75adbc0cd33bc56a8593ab0caf (diff)
downloadfork-ledger-9ae28a160a4af46dca9eb5b5f270b01acf3eb721.tar.gz
fork-ledger-9ae28a160a4af46dca9eb5b5f270b01acf3eb721.tar.bz2
fork-ledger-9ae28a160a4af46dca9eb5b5f270b01acf3eb721.zip
Added a new "account_amount" valexpr function
At the moment, it's only useful during parsing.
Diffstat (limited to 'src/post.cc')
-rw-r--r--src/post.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/post.cc b/src/post.cc
index 18f84f7a..79add9b9 100644
--- a/src/post.cc
+++ b/src/post.cc
@@ -209,6 +209,35 @@ namespace {
return string_value(post.reported_account()->name);
}
+ value_t get_account_amount(call_scope_t& scope)
+ {
+ in_context_t<post_t> env(scope, "&v");
+
+ account_t * account = NULL;
+ if (env.has(0)) {
+ account_t * master = env->account;
+ while (master->parent)
+ master = master->parent;
+
+ if (env.value_at(0).is_string())
+ account = master->find_account(env.get<string>(0), false);
+ else if (env.value_at(0).is_mask())
+ account = master->find_account_re(env.get<mask_t>(0).expr.str());
+ } else {
+ account = env->reported_account();
+ }
+
+ if (! account)
+ throw_(std::runtime_error, _("Cannot locate referenced account"));
+
+ DEBUG("post.account_amount", "Found account: " << account->fullname());
+
+ if (account->xdata().value.is_null())
+ return 0L;
+ else
+ return account->xdata().value.simplified();
+ }
+
value_t get_account_depth(post_t& post) {
return long(post.reported_account()->depth);
}
@@ -227,6 +256,8 @@ expr_t::ptr_op_t post_t::lookup(const string& name)
return WRAP_FUNCTOR(get_wrapper<&get_amount>);
else if (name == "account")
return WRAP_FUNCTOR(get_account);
+ else if (name == "account_amount")
+ return WRAP_FUNCTOR(get_account_amount);
else if (name == "account_base")
return WRAP_FUNCTOR(get_wrapper<&get_account_base>);
break;