From 02e78255166b17bff08a408166cc56ff9269c925 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 22 May 2010 17:04:38 -0400 Subject: Option --count sums payees, account, commodities --- src/output.cc | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'src/output.cc') diff --git a/src/output.cc b/src/output.cc index e3aa9f4a..ec1faba6 100644 --- a/src/output.cc +++ b/src/output.cc @@ -236,38 +236,51 @@ void report_accounts::flush() { std::ostream& out(report.output_stream); - foreach (accounts_pair& entry, accounts) + foreach (accounts_pair& entry, accounts) { + if (report.HANDLED(count)) + out << entry.second << ' '; out << *entry.first << '\n'; + } } void report_accounts::operator()(post_t& post) { - std::map::iterator i = accounts.find(post.account); + std::map::iterator i = accounts.find(post.account); if (i == accounts.end()) - accounts.insert(accounts_pair(post.account, true)); + accounts.insert(accounts_pair(post.account, 1)); + else + (*i).second++; } void report_payees::flush() { std::ostream& out(report.output_stream); - foreach (payees_pair& entry, payees) + foreach (payees_pair& entry, payees) { + if (report.HANDLED(count)) + out << entry.second << ' '; out << entry.first << '\n'; + } } void report_payees::operator()(post_t& post) { - std::map::iterator i = payees.find(post.xact->payee); + std::map::iterator i = payees.find(post.xact->payee); if (i == payees.end()) - payees.insert(payees_pair(post.xact->payee, true)); + payees.insert(payees_pair(post.xact->payee, 1)); + else + (*i).second++; } void report_commodities::flush() { std::ostream& out(report.output_stream); - foreach (commodities_pair& entry, commodities) + foreach (commodities_pair& entry, commodities) { + if (report.HANDLED(count)) + out << entry.second << ' '; out << *entry.first << '\n'; + } } void report_commodities::operator()(post_t& post) @@ -275,18 +288,22 @@ void report_commodities::operator()(post_t& post) amount_t temp(post.amount.strip_annotations(report.what_to_keep())); commodity_t& comm(temp.commodity()); - std::map::iterator i = commodities.find(&comm); + std::map::iterator i = commodities.find(&comm); if (i == commodities.end()) - commodities.insert(commodities_pair(&comm, true)); + commodities.insert(commodities_pair(&comm, 1)); + else + (*i).second++; if (comm.has_annotation()) { annotated_commodity_t& ann_comm(as_annotated_commodity(comm)); if (ann_comm.details.price) { - std::map::iterator i = + std::map::iterator i = commodities.find(&ann_comm.details.price->commodity()); if (i == commodities.end()) commodities.insert - (commodities_pair(&ann_comm.details.price->commodity(), true)); + (commodities_pair(&ann_comm.details.price->commodity(), 1)); + else + (*i).second++; } } @@ -294,7 +311,9 @@ void report_commodities::operator()(post_t& post) amount_t temp_cost(post.cost->strip_annotations(report.what_to_keep())); i = commodities.find(&temp_cost.commodity()); if (i == commodities.end()) - commodities.insert(commodities_pair(&temp_cost.commodity(), true)); + commodities.insert(commodities_pair(&temp_cost.commodity(), 1)); + else + (*i).second++; } } -- cgit v1.2.3