diff options
author | John Wiegley <johnw@newartisans.com> | 2010-05-22 17:04:38 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-05-22 21:35:02 -0400 |
commit | 02e78255166b17bff08a408166cc56ff9269c925 (patch) | |
tree | c2c0016572efdeb356a793aa1e9414a9e9058bfe /src | |
parent | de3803d0277353520116f05c7b2357196a8cfe48 (diff) | |
download | fork-ledger-02e78255166b17bff08a408166cc56ff9269c925.tar.gz fork-ledger-02e78255166b17bff08a408166cc56ff9269c925.tar.bz2 fork-ledger-02e78255166b17bff08a408166cc56ff9269c925.zip |
Option --count sums payees, account, commodities
Diffstat (limited to 'src')
-rw-r--r-- | src/output.cc | 43 | ||||
-rw-r--r-- | src/output.h | 12 | ||||
-rw-r--r-- | src/report.cc | 1 | ||||
-rw-r--r-- | src/report.h | 1 |
4 files changed, 39 insertions, 18 deletions
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<account_t *, bool>::iterator i = accounts.find(post.account); + std::map<account_t *, std::size_t>::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<string, bool>::iterator i = payees.find(post.xact->payee); + std::map<string, std::size_t>::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<commodity_t *, bool>::iterator i = commodities.find(&comm); + std::map<commodity_t *, std::size_t>::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<commodity_t *, bool>::iterator i = + std::map<commodity_t *, std::size_t>::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++; } } diff --git a/src/output.h b/src/output.h index 3e70d9fe..3a7b68df 100644 --- a/src/output.h +++ b/src/output.h @@ -108,9 +108,9 @@ class report_accounts : public item_handler<post_t> protected: report_t& report; - std::map<account_t *, bool> accounts; + std::map<account_t *, std::size_t> accounts; - typedef std::map<account_t *, bool>::value_type accounts_pair; + typedef std::map<account_t *, std::size_t>::value_type accounts_pair; public: report_accounts(report_t& _report) : report(_report) { @@ -129,9 +129,9 @@ class report_payees : public item_handler<post_t> protected: report_t& report; - std::map<string, bool> payees; + std::map<string, std::size_t> payees; - typedef std::map<string, bool>::value_type payees_pair; + typedef std::map<string, std::size_t>::value_type payees_pair; public: report_payees(report_t& _report) : report(_report) { @@ -150,9 +150,9 @@ class report_commodities : public item_handler<post_t> protected: report_t& report; - std::map<commodity_t *, bool> commodities; + std::map<commodity_t *, std::size_t> commodities; - typedef std::map<commodity_t *, bool>::value_type commodities_pair; + typedef std::map<commodity_t *, std::size_t>::value_type commodities_pair; public: report_commodities(report_t& _report) : report(_report) { diff --git a/src/report.cc b/src/report.cc index 509be8b1..d2db87b0 100644 --- a/src/report.cc +++ b/src/report.cc @@ -853,6 +853,7 @@ option_t<report_t> * report_t::lookup_option(const char * p) else OPT(columns_); else OPT_ALT(basis, cost); else OPT_(current); + else OPT(count); break; case 'd': OPT(daily); diff --git a/src/report.h b/src/report.h index 6b10dbcc..783f0026 100644 --- a/src/report.h +++ b/src/report.h @@ -454,6 +454,7 @@ public: }); OPTION(report_t, columns_); + OPTION(report_t, count); OPTION__(report_t, csv_format_, CTOR(report_t, csv_format_) { on(none, |