Added back the -V (market value) option.

This commit is contained in:
John Wiegley 2009-01-19 22:28:00 -04:00
parent 83648af19f
commit e9a5a9bd77
2 changed files with 34 additions and 0 deletions

View file

@ -277,6 +277,26 @@ value_t report_t::get_display_total(call_scope_t& scope)
return display_total.calc(scope);
}
value_t report_t::f_market_value(call_scope_t& args)
{
var_t<datetime_t> date(args, 1);
var_t<string> in_terms_of(args, 2);
commodity_t * commodity = NULL;
if (in_terms_of)
commodity = amount_t::current_pool->find_or_create(*in_terms_of);
DEBUG("report.market", "getting market value of: " << args[0]);
value_t result =
args[0].value(date ? optional<datetime_t>(*date) : optional<datetime_t>(),
commodity ? optional<commodity_t&>(*commodity) :
optional<commodity_t&>());
DEBUG("report.market", "result is: " << result);
return result;
}
namespace {
value_t print_balance(call_scope_t& args)
{
@ -484,6 +504,11 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::get_display_total);
break;
case 'm':
if (std::strcmp(p, "market_value") == 0)
return MAKE_FUNCTOR(report_t::f_market_value);
break;
case 'o':
if (std::strncmp(p, "opt_", 4) == 0) {
p = p + 4;
@ -560,6 +585,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
case 'm':
if (std::strcmp(p, "monthly") == 0)
return MAKE_FUNCTOR(report_t::option_monthly);
else if (std::strcmp(p, "market") == 0)
return MAKE_FUNCTOR(report_t::option_market);
break;
case 'n':
@ -676,6 +703,11 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_uncleared);
break;
case 'V':
if (! *(p + 1))
return MAKE_FUNCTOR(report_t::option_market);
break;
case 'W':
if (! *(p + 1))
return MAKE_FUNCTOR(report_t::option_weekly);

View file

@ -679,6 +679,8 @@ public:
value_t get_total_expr(call_scope_t& scope);
value_t get_display_total(call_scope_t& scope);
value_t f_market_value(call_scope_t& args);
value_t option_amount_data(call_scope_t&) { // j
format_string = session.plot_amount_format;
return true;