diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-12 14:58:44 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-12 14:58:44 -0400 |
commit | 0555e7f61ef14ec667f8ba611e60fd96133a9676 (patch) | |
tree | c8b853c67515613d832820bd8471099793403a11 /src/post.cc | |
parent | 28c65cda512135bde36542351533941b019b6ee8 (diff) | |
download | fork-ledger-0555e7f61ef14ec667f8ba611e60fd96133a9676.tar.gz fork-ledger-0555e7f61ef14ec667f8ba611e60fd96133a9676.tar.bz2 fork-ledger-0555e7f61ef14ec667f8ba611e60fd96133a9676.zip |
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.
Diffstat (limited to 'src/post.cc')
-rw-r--r-- | src/post.cc | 23 |
1 files changed, 15 insertions, 8 deletions
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<post_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<post_t>(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': |