diff options
-rw-r--r-- | src/report.cc | 24 | ||||
-rw-r--r-- | src/report.h | 1 |
2 files changed, 25 insertions, 0 deletions
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); |