diff options
author | John Wiegley <johnw@newartisans.com> | 2008-08-13 05:48:32 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-08-13 05:48:32 -0400 |
commit | 3231e380bbe6ebd5641a24a493078e8aee0fdfe3 (patch) | |
tree | c4fbd329f3a71a9804b0db19f1b1bbb8b4e799ac /src | |
parent | 46bc362804fbf0cab0384bf046c95b1495fa98c6 (diff) | |
download | ledger-3231e380bbe6ebd5641a24a493078e8aee0fdfe3.tar.gz ledger-3231e380bbe6ebd5641a24a493078e8aee0fdfe3.tar.bz2 ledger-3231e380bbe6ebd5641a24a493078e8aee0fdfe3.zip |
The balance output now includes the final total.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cc | 30 | ||||
-rw-r--r-- | src/output.cc | 12 | ||||
-rw-r--r-- | src/output.h | 18 |
3 files changed, 28 insertions, 32 deletions
diff --git a/src/main.cc b/src/main.cc index eeff5bb7..8790fb17 100644 --- a/src/main.cc +++ b/src/main.cc @@ -150,32 +150,28 @@ namespace ledger { return final_value_expr; } - template <class Formatter = format_xacts, + template <class Type = xact_t, class handler_ptr = xact_handler_ptr, void (report_t::*report_method)(handler_ptr) = &report_t::xacts_report> class reporter { - string format_name; + shared_ptr<item_handler<Type> > handler; public: - reporter(const string& _format_name) - : format_name(_format_name) {} + reporter(item_handler<Type> * _handler) + : handler(_handler) {} value_t operator()(call_scope_t& args) { - report_t& report(find_scope<report_t>(args)); - var_t<string> format(args, format_name); - - if (! report.format_string.empty()) - *format = report.format_string; + report_t& report(find_scope<report_t>(args)); if (args.value().size() > 0) report.append_predicate (args_to_predicate(args.value().as_sequence().begin(), args.value().as_sequence().end())); - (report.*report_method)(handler_ptr(new Formatter(report, *format))); + (report.*report_method)(handler_ptr(handler)); return true; } @@ -403,15 +399,17 @@ namespace ledger { function_t command; if (verb == "register" || verb == "reg" || verb == "r") - command = reporter<>("register_format"); + command = reporter<>(new format_xacts(report, session.register_format)); else if (verb == "print" || verb == "p") - command = reporter<>("print_format"); + command = reporter<>(new format_xacts(report, session.print_format)); else if (verb == "balance" || verb == "bal" || verb == "b") - command = reporter<format_accounts, acct_handler_ptr, - &report_t::accounts_report>("balance_format"); + command = reporter<account_t, acct_handler_ptr, + &report_t::accounts_report> + (new format_accounts(report, session.balance_format)); else if (verb == "equity") - command = reporter<format_equity, acct_handler_ptr, - &report_t::accounts_report>("print_format"); + command = reporter<account_t, acct_handler_ptr, + &report_t::accounts_report> + (new format_equity(report, session.print_format)); #if 0 else if (verb == "entry") command = entry_command(); diff --git a/src/output.cc b/src/output.cc index b05f5815..e3b31df4 100644 --- a/src/output.cc +++ b/src/output.cc @@ -138,22 +138,18 @@ void format_accounts::flush() { std::ostream& out(*report.output_stream); -#if 0 - // jww (2008-08-02): I need access to the output formatter before this is - // going to work. if (print_final_total) { assert(out); - assert(account_has_xdata(*session.master)); + assert(report.session.master->has_xdata()); - account_xdata_t& xdata(account_xdata(*session.master)); + account_t::xdata_t& xdata(report.session.master->xdata()); - if (! show_collapsed && xdata.total) { + if (! report.show_collapsed && xdata.total) { out << "--------------------\n"; xdata.value = xdata.total; - handler->format.format(out, *session.master); + format.format(out, *report.session.master); } } -#endif out.flush(); } diff --git a/src/output.h b/src/output.h index 885b8bc9..3fe1ce71 100644 --- a/src/output.h +++ b/src/output.h @@ -90,22 +90,24 @@ private: class format_accounts : public item_handler<account_t> { protected: - report_t& report; - + report_t& report; + format_t format; item_predicate<account_t> disp_pred; + bool print_final_total; bool disp_subaccounts_p(account_t& account, account_t *& to_show); bool display_account(account_t& account); public: - format_t format; - format_accounts(report_t& _report, const string& _format, - const string& display_predicate = "" /*, - const bool print_final_total = true */) - : report(_report), disp_pred(display_predicate), format(_format) { - TRACE_CTOR(format_accounts, "report&, const string&, const string&"); + const string& display_predicate = "", + const bool _print_final_total = true) + : report(_report), format(_format), disp_pred(display_predicate), + print_final_total(_print_final_total) + { + TRACE_CTOR(format_accounts, + "report&, const string&, const string&, const bool"); } virtual ~format_accounts() { TRACE_DTOR(format_accounts); |