diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-17 21:19:31 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-17 21:19:31 -0400 |
commit | 4ec2dfeef13ead1d87302ef953e05efec102bb25 (patch) | |
tree | 0ff109dd6aaccf466ecbd64f80ae3138b9219b6a /src | |
parent | 93d195f1d97c376c26e5a7e88d6b0fc6e3b8e2d0 (diff) | |
download | fork-ledger-4ec2dfeef13ead1d87302ef953e05efec102bb25.tar.gz fork-ledger-4ec2dfeef13ead1d87302ef953e05efec102bb25.tar.bz2 fork-ledger-4ec2dfeef13ead1d87302ef953e05efec102bb25.zip |
Added --flat option, to flatten the balance report
Diffstat (limited to 'src')
-rw-r--r-- | src/account.cc | 23 | ||||
-rw-r--r-- | src/account.h | 2 | ||||
-rw-r--r-- | src/output.cc | 6 | ||||
-rw-r--r-- | src/output.h | 9 | ||||
-rw-r--r-- | src/report.cc | 10 | ||||
-rw-r--r-- | src/report.h | 1 | ||||
-rw-r--r-- | src/scope.h | 9 |
7 files changed, 42 insertions, 18 deletions
diff --git a/src/account.cc b/src/account.cc index b463968b..07c01c7e 100644 --- a/src/account.cc +++ b/src/account.cc @@ -125,17 +125,19 @@ string account_t::fullname() const } } -string account_t::partial_name() const +string account_t::partial_name(bool flat) const { string pname = name; for (const account_t * acct = parent; acct && acct->parent; acct = acct->parent) { - std::size_t count = acct->children_with_flags(ACCOUNT_EXT_MATCHING); - assert(count > 0); - if (count > 1) - break; + if (! flat) { + std::size_t count = acct->children_with_flags(ACCOUNT_EXT_MATCHING); + assert(count > 0); + if (count > 1) + break; + } pname = acct->name + ":" + pname; } return pname; @@ -148,8 +150,13 @@ std::ostream& operator<<(std::ostream& out, const account_t& account) } namespace { - value_t get_partial_name(account_t& account) { - return string_value(account.partial_name()); + value_t get_partial_name(call_scope_t& scope) + { + account_t& account(find_scope<account_t>(scope)); + + var_t<bool> flatten(scope, 0); + + return string_value(account.partial_name(flatten ? *flatten : false)); } value_t get_account(account_t& account) { // this gets the name @@ -238,7 +245,7 @@ expr_t::ptr_op_t account_t::lookup(const string& name) case 'p': if (name == "partial_account") - return WRAP_FUNCTOR(get_wrapper<&get_partial_name>); + return WRAP_FUNCTOR(get_partial_name); break; case 's': diff --git a/src/account.h b/src/account.h index d97df2e0..f9fd2f52 100644 --- a/src/account.h +++ b/src/account.h @@ -97,7 +97,7 @@ class account_t : public scope_t return fullname(); } string fullname() const; - string partial_name() const; + string partial_name(bool flat = false) const; void add_account(account_t * acct) { accounts.insert(accounts_map::value_type(acct->name, acct)); diff --git a/src/output.cc b/src/output.cc index 2e068631..31208c26 100644 --- a/src/output.cc +++ b/src/output.cc @@ -222,11 +222,13 @@ std::size_t format_accounts::post_accounts(account_t& account) DEBUG("account.display", "Should we display " << account.fullname()); if (account.has_flags(ACCOUNT_EXT_MATCHING) || - account.children_with_flags(ACCOUNT_EXT_MATCHING) > 1) { + (! flatten_list && + account.children_with_flags(ACCOUNT_EXT_MATCHING) > 1)) { DEBUG("account.display", " Yes, because it matched"); format_account = true; } - else if (account.children_with_flags(ACCOUNT_EXT_VISITED) && + else if (! flatten_list && + account.children_with_flags(ACCOUNT_EXT_VISITED) && ! account.children_with_flags(ACCOUNT_EXT_MATCHING)) { DEBUG("account.display", " Maybe, because it has visited, but no matching, children"); diff --git a/src/output.h b/src/output.h index bb1b907b..ded29143 100644 --- a/src/output.h +++ b/src/output.h @@ -163,13 +163,16 @@ protected: report_t& report; format_t format; item_predicate disp_pred; + bool flatten_list; public: format_accounts(report_t& _report, - const string& _format = "") - : report(_report), format(_format), disp_pred() + const string& _format = "", + bool _flatten_list = false) + : report(_report), format(_format), disp_pred(), + flatten_list(_flatten_list) { - TRACE_CTOR(format_accounts, "report&, const string&, const bool"); + TRACE_CTOR(format_accounts, "report&, const string&, bool"); if (report.HANDLED(display_)) { DEBUG("account.display", diff --git a/src/report.cc b/src/report.cc index a28ff144..a856b7df 100644 --- a/src/report.cc +++ b/src/report.cc @@ -73,7 +73,8 @@ report_t::report_t(session_t& _session) HANDLER(balance_format_).on( "%20(print_balance(strip(display_total), 20))" - " %(depth_spacer)%-(partial_account)\n"); + " %(!options.flat ? depth_spacer : \"\")" + "%-(partial_account(options.flat))\n"); HANDLER(equity_format_).on("\n%D %Y%C%P\n%/ %-34W %12t\n"); @@ -404,7 +405,8 @@ option_t<report_t> * report_t::lookup_option(const char * p) else OPT(equity_format_); break; case 'f': - OPT(forecast_); + OPT(flat); + else OPT(forecast_); else OPT(format_); else OPT_ALT(head_, first_); break; @@ -524,8 +526,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name) if (*(p + 1) == '\0' || is_eq(p, "bal") || is_eq(p, "balance")) return expr_t::op_t::wrap_functor (reporter<account_t, acct_handler_ptr, &report_t::accounts_report> - (new format_accounts(*this, report_format(HANDLER(balance_format_))), - *this)); + (new format_accounts(*this, report_format(HANDLER(balance_format_)), + HANDLED(flat)), *this)); break; case 'c': diff --git a/src/report.h b/src/report.h index e85d1d34..cc3d5a62 100644 --- a/src/report.h +++ b/src/report.h @@ -333,6 +333,7 @@ public: }); OPTION(report_t, equity_format_); + OPTION(report_t, flat); OPTION(report_t, forecast_); OPTION(report_t, format_); // -F OPTION(report_t, gain); // -G diff --git a/src/scope.h b/src/scope.h index 2ab788fc..b49e3ebe 100644 --- a/src/scope.h +++ b/src/scope.h @@ -345,6 +345,15 @@ public: }; template <> +inline bool var_t<bool>::operator *() { + return value->to_boolean(); +} +template <> +inline bool var_t<bool>::operator *() const { + return value->to_boolean(); +} + +template <> inline long var_t<long>::operator *() { return value->to_long(); } |