From dafe7c891af6e6c65a96c17ffe078adf124cc895 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 22 Dec 2010 15:32:34 -0500 Subject: [PATCH] Added "top_amount" value expr function --- src/report.cc | 24 ++++++++++++++++++++++++ src/report.h | 1 + 2 files changed, 25 insertions(+) diff --git a/src/report.cc b/src/report.cc index 5c7bf01d..8af1a459 100644 --- a/src/report.cc +++ b/src/report.cc @@ -452,6 +452,28 @@ value_t report_t::display_value(const value_t& val) return temp.unreduced(); } +namespace { + value_t top_amount(const value_t& val) + { + switch (val.type()) { + case value_t::BALANCE: + return (*val.as_balance().amounts.begin()).second; + + case value_t::SEQUENCE: { + return top_amount(*val.as_sequence().begin()); + } + + default: + return val; + } + } +} + +value_t report_t::fn_top_amount(call_scope_t& args) +{ + return top_amount(args[0]); +} + value_t report_t::fn_amount_expr(call_scope_t& scope) { return HANDLER(amount_).expr.calc(scope); @@ -1269,6 +1291,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, return MAKE_FUNCTOR(report_t::fn_display_amount); else if (is_eq(p, "trim")) return MAKE_FUNCTOR(report_t::fn_trim); + else if (is_eq(p, "top_amount")) + return MAKE_FUNCTOR(report_t::fn_top_amount); else if (is_eq(p, "to_boolean")) return MAKE_FUNCTOR(report_t::fn_to_boolean); else if (is_eq(p, "to_int")) diff --git a/src/report.h b/src/report.h index 5c172ee9..d0a49476 100644 --- a/src/report.h +++ b/src/report.h @@ -145,6 +145,7 @@ public: value_t fn_total_expr(call_scope_t& scope); value_t fn_display_amount(call_scope_t& scope); value_t fn_display_total(call_scope_t& scope); + value_t fn_top_amount(call_scope_t& val); value_t fn_should_bold(call_scope_t& scope); value_t fn_market(call_scope_t& scope); value_t fn_get_at(call_scope_t& scope);