summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-03-08 04:15:48 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-03-08 04:15:48 -0400
commit77faaa926f06dc10cab65d08e0d35836d4a273a6 (patch)
tree4ae29e114cdcb7e4f858c0cd9817f12d9c3543c9 /src
parentdd6c0ae80dadc0965d9b723ed6a7be9323beec52 (diff)
downloadfork-ledger-77faaa926f06dc10cab65d08e0d35836d4a273a6.tar.gz
fork-ledger-77faaa926f06dc10cab65d08e0d35836d4a273a6.tar.bz2
fork-ledger-77faaa926f06dc10cab65d08e0d35836d4a273a6.zip
Rewrote the balance report again, to fix --depth
Diffstat (limited to 'src')
-rw-r--r--src/account.cc4
-rw-r--r--src/account.h3
-rw-r--r--src/output.cc95
-rw-r--r--src/output.h5
-rw-r--r--src/report.h2
5 files changed, 53 insertions, 56 deletions
diff --git a/src/account.cc b/src/account.cc
index 0db42cdb..24849a72 100644
--- a/src/account.cc
+++ b/src/account.cc
@@ -136,7 +136,7 @@ string account_t::partial_name(bool flat) const
acct && acct->parent;
acct = acct->parent) {
if (! flat) {
- std::size_t count = acct->children_with_flags(ACCOUNT_EXT_MATCHING);
+ std::size_t count = acct->children_with_flags(ACCOUNT_EXT_TO_DISPLAY);
assert(count > 0);
if (count > 1)
break;
@@ -198,7 +198,7 @@ namespace {
for (const account_t * acct = account.parent;
acct && acct->parent;
acct = acct->parent) {
- std::size_t count = acct->children_with_flags(ACCOUNT_EXT_MATCHING);
+ std::size_t count = acct->children_with_flags(ACCOUNT_EXT_TO_DISPLAY);
assert(count > 0);
if (count > 1)
depth++;
diff --git a/src/account.h b/src/account.h
index 0fa03dde..2f3eec24 100644
--- a/src/account.h
+++ b/src/account.h
@@ -134,7 +134,8 @@ class account_t : public scope_t
#define ACCOUNT_EXT_AUTO_VIRTUALIZE 0x08
#define ACCOUNT_EXT_VISITED 0x10
#define ACCOUNT_EXT_MATCHING 0x20
-#define ACCOUNT_EXT_DISPLAYED 0x40
+#define ACCOUNT_EXT_TO_DISPLAY 0x40
+#define ACCOUNT_EXT_DISPLAYED 0x80
struct details_t
{
diff --git a/src/output.cc b/src/output.cc
index 02bd7120..b10dcff6 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -117,12 +117,6 @@ format_accounts::format_accounts(report_t& _report,
{
TRACE_CTOR(format_accounts, "report&, const string&");
- if (report.HANDLED(display_)) {
- DEBUG("account.display",
- "Account display predicate: " << report.HANDLER(display_).str());
- disp_pred.predicate.parse(report.HANDLER(display_).str());
- }
-
const char * f = format.c_str();
if (const char * p = std::strstr(f, "%/")) {
@@ -142,48 +136,62 @@ format_accounts::format_accounts(report_t& _report,
void format_accounts::post_account(account_t& account)
{
- bind_scope_t bound_scope(report, account);
- bool format_account = false;
+ if (account.xdata().has_flags(ACCOUNT_EXT_TO_DISPLAY)) {
+ account.xdata().add_flags(ACCOUNT_EXT_DISPLAYED);
+
+ bind_scope_t bound_scope(report, account);
+ account_line_format.format(report.output_stream, bound_scope);
+ }
+}
- DEBUG("account.display", "Should we display " << account.fullname());
+std::pair<std::size_t, std::size_t>
+format_accounts::mark_accounts(account_t& account, const bool flat)
+{
+ std::size_t visited = 0;
+ std::size_t to_display = 0;
- if (account.has_flags(ACCOUNT_EXT_MATCHING) ||
- (! report.HANDLED(flat) &&
- account.children_with_flags(ACCOUNT_EXT_MATCHING) > 1)) {
- DEBUG("account.display", " Yes, because it matched");
- format_account = true;
+ foreach (accounts_map::value_type& pair, account.accounts) {
+ std::pair<std::size_t, std::size_t> i = mark_accounts(*pair.second, flat);
+ visited += i.first;
+ to_display += i.second;
}
- else if (! report.HANDLED(flat) &&
- 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");
- if (disp_pred(bound_scope)) {
- DEBUG("account.display",
- " And yes, because it matches the display predicate");
- format_account = true;
- } else {
- DEBUG("account.display",
- " And no, because it didn't match the display predicate");
+
+#if defined(DEBUG_ON)
+ DEBUG("account.display", "Considering account: " << account.fullname());
+ if (account.has_flags(ACCOUNT_EXT_VISITED))
+ DEBUG("account.display", " it was visited itself");
+ DEBUG("account.display", " it has " << visited << " visited children");
+ DEBUG("account.display",
+ " it has " << to_display << " children to display");
+#endif
+
+ if (account.has_flags(ACCOUNT_EXT_VISITED) || (! flat && visited > 0)) {
+ bind_scope_t bound_scope(report, account);
+ if (disp_pred(bound_scope) && (flat || to_display != 1)) {
+ account.xdata().add_flags(ACCOUNT_EXT_TO_DISPLAY);
+ DEBUG("account.display", "Marking account as TO_DISPLAY");
+ to_display = 1;
}
- }
- else {
- DEBUG("account.display",
- " No, neither it nor its children were eligible for display");
+ visited = 1;
}
- if (format_account) {
- account.xdata().add_flags(ACCOUNT_EXT_DISPLAYED);
- account_line_format.format(report.output_stream, bound_scope);
- }
+ return std::pair<std::size_t, std::size_t>(visited, to_display);
}
void format_accounts::flush()
{
std::ostream& out(report.output_stream);
+ if (report.HANDLED(display_)) {
+ DEBUG("account.display",
+ "Account display predicate: " << report.HANDLER(display_).str());
+ disp_pred.predicate.parse(report.HANDLER(display_).str());
+ }
+
std::size_t top_displayed = 0;
+ mark_accounts(*report.session.master, report.HANDLED(flat));
+
foreach (account_t * account, posted_accounts) {
post_account(*account);
@@ -194,8 +202,9 @@ void format_accounts::flush()
if (! report.HANDLED(flat)) {
foreach (accounts_map::value_type pair, report.session.master->accounts) {
if (pair.second->has_flags(ACCOUNT_EXT_DISPLAYED) ||
- pair.second->children_with_flags(ACCOUNT_EXT_DISPLAYED))
+ pair.second->children_with_flags(ACCOUNT_EXT_DISPLAYED)) {
top_displayed++;
+ }
}
}
@@ -211,22 +220,6 @@ void format_accounts::flush()
void format_accounts::operator()(account_t& account)
{
- DEBUG("account.display",
- "Proposing to format account: " << account.fullname());
-
- if (account.has_flags(ACCOUNT_EXT_VISITED)) {
- DEBUG("account.display", " Account or its children was visited");
-
- bind_scope_t bound_scope(report, account);
- if (disp_pred(bound_scope)) {
- DEBUG("account.display",
- " And the account matched the display predicate");
- account.xdata().add_flags(ACCOUNT_EXT_MATCHING);
- } else {
- DEBUG("account.display",
- " But it did not match the display predicate");
- }
- }
posted_accounts.push_back(&account);
}
diff --git a/src/output.h b/src/output.h
index 19dc5e20..00f7d38d 100644
--- a/src/output.h
+++ b/src/output.h
@@ -49,12 +49,12 @@
#include "chain.h"
#include "predicate.h"
#include "format.h"
+#include "account.h"
namespace ledger {
class xact_t;
class post_t;
-class account_t;
class report_t;
/**
@@ -106,6 +106,9 @@ public:
TRACE_DTOR(format_accounts);
}
+ std::pair<std::size_t, std::size_t>
+ mark_accounts(account_t& account, const bool flat);
+
virtual void post_account(account_t& account);
virtual void flush();
diff --git a/src/report.h b/src/report.h
index a8f048d3..55c37b22 100644
--- a/src/report.h
+++ b/src/report.h
@@ -304,7 +304,7 @@ public:
OPTION_(report_t, depth_, DO_(scope) {
interactive_t args(scope, "l");
- parent->HANDLER(limit_).on(string("depth<=") + args.get<string>(0));
+ parent->HANDLER(display_).on(string("depth<=") + args.get<string>(0));
});
OPTION_(report_t, deviation, DO() { // -D