Implemented --unround using value expressions

This commit is contained in:
John Wiegley 2009-03-06 00:19:24 -04:00
parent 6ac79137f7
commit dd23edd5ce
4 changed files with 14 additions and 29 deletions

View file

@ -90,13 +90,11 @@ post_handler_ptr chain_post_handlers(report_t& report,
report, report.HANDLED(revalued_only)));
}
// calc_posts computes visited posting values and the running total
// calc_posts computes the running total. When this appears will determine,
// for example, whether filtered posts are included or excluded from the
// running total.
handler.reset(new calc_posts(handler, expr, only_preliminaries));
// unround_posts will unround the amounts in all postings
if (report.HANDLED(unround))
handler.reset(new unround_posts(handler));
// filter_posts will only pass through posts matching the
// `secondary_predicate'.
if (report.HANDLED(only_)) {

View file

@ -82,29 +82,6 @@ public:
}
};
/**
* @brief Brief
*
* Long.
*/
class unround_posts : public item_handler<post_t>
{
public:
unround_posts(post_handler_ptr handler)
: item_handler<post_t>(handler) {
TRACE_CTOR(unround_posts, "posts_list&");
}
virtual ~unround_posts() {
TRACE_DTOR(unround_posts);
}
virtual void operator()(post_t& post) {
post.xdata().compound_value = post.amount.unrounded();
post.xdata().add_flags(POST_EXT_COMPOUND);
item_handler<post_t>::operator()(post);
}
};
class posts_iterator;
/**

View file

@ -196,6 +196,11 @@ value_t report_t::fn_rounded(call_scope_t& args)
return args.value().rounded();
}
value_t report_t::fn_unrounded(call_scope_t& args)
{
return args.value().unrounded();
}
value_t report_t::fn_quantity(call_scope_t& scope)
{
interactive_t args(scope, "a");
@ -858,6 +863,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
case 'u':
if (is_eq(p, "underline"))
return WRAP_FUNCTOR(fn_underline);
else if (is_eq(p, "unrounded"))
return MAKE_FUNCTOR(report_t::fn_unrounded);
break;
case 'w':

View file

@ -145,6 +145,7 @@ public:
value_t fn_scrub(call_scope_t& scope);
value_t fn_quantity(call_scope_t& scope);
value_t fn_rounded(call_scope_t& scope);
value_t fn_unrounded(call_scope_t& scope);
value_t fn_truncated(call_scope_t& scope);
value_t fn_abs(call_scope_t& scope);
value_t fn_justify(call_scope_t& scope);
@ -639,7 +640,9 @@ public:
parent->HANDLER(limit_).on("uncleared|pending");
});
OPTION(report_t, unround);
OPTION_(report_t, unround, DO() {
parent->HANDLER(amount_).set_expr("unrounded(amount)");
});
OPTION_(report_t, weekly, DO() { // -W
parent->HANDLER(period_).on("weekly");