From 0555e7f61ef14ec667f8ba611e60fd96133a9676 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 12 Jun 2010 14:58:44 -0400 Subject: Improved value expression function 'commodity' Without arguments -- and in a posting -- it is equivalent to "commodity(amount)". Otherwise, it returns the commodity symbol of its argument. --- src/post.cc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/post.cc') diff --git a/src/post.cc b/src/post.cc index 2a8abddc..fa8bab4f 100644 --- a/src/post.cc +++ b/src/post.cc @@ -197,13 +197,20 @@ namespace { return post.has_xdata() && post.xdata().has_flags(POST_EXT_DIRECT_AMT); } - value_t get_commodity(post_t& post) { - if (post.has_xdata() && - post.xdata().has_flags(POST_EXT_COMPOUND)) - return string_value(post.xdata().compound_value.to_amount() - .commodity().symbol()); - else - return string_value(post.amount.commodity().symbol()); + value_t get_commodity(call_scope_t& scope) + { + in_context_t env(scope, "&v"); + if (env.has(0)) { + return string_value(env.value_at(0).to_amount().commodity().symbol()); + } else { + post_t& post(find_scope(scope)); + if (post.has_xdata() && + post.xdata().has_flags(POST_EXT_COMPOUND)) + return string_value(post.xdata().compound_value.to_amount() + .commodity().symbol()); + else + return string_value(post.amount.commodity().symbol()); + } } value_t get_commodity_is_primary(post_t& post) { @@ -427,7 +434,7 @@ expr_t::ptr_op_t post_t::lookup(const symbol_t::kind_t kind, else if (name == "calculated") return WRAP_FUNCTOR(get_wrapper<&get_is_calculated>); else if (name == "commodity") - return WRAP_FUNCTOR(get_wrapper<&get_commodity>); + return WRAP_FUNCTOR(&get_commodity); break; case 'd': -- cgit v1.2.3