diff options
author | John Wiegley <johnw@newartisans.com> | 2004-08-12 23:21:57 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-08-12 23:21:57 -0400 |
commit | a4f5abe860025c8f4120b3bfb7aea7e555692153 (patch) | |
tree | 852b5a0ff6936b940520b6b3124a3c538b8e4771 /walk.h | |
parent | b20ddba1d5652157bb432e0c826ea746dd81482e (diff) | |
download | fork-ledger-a4f5abe860025c8f4120b3bfb7aea7e555692153.tar.gz fork-ledger-a4f5abe860025c8f4120b3bfb7aea7e555692153.tar.bz2 fork-ledger-a4f5abe860025c8f4120b3bfb7aea7e555692153.zip |
Added a days-of-the-week report, under -w
Diffstat (limited to 'walk.h')
-rw-r--r-- | walk.h | 98 |
1 files changed, 59 insertions, 39 deletions
@@ -47,6 +47,44 @@ struct compare_items { typedef std::deque<transaction_t *> transactions_deque; typedef std::deque<entry_t *> entries_deque; +inline void walk_transactions(transactions_list::iterator begin, + transactions_list::iterator end, + item_handler<transaction_t>& handler) { + for (transactions_list::iterator i = begin; i != end; i++) + handler(*i); +} + +inline void walk_transactions(transactions_list& list, + item_handler<transaction_t>& handler) { + walk_transactions(list.begin(), list.end(), handler); +} + +inline void walk_transactions(transactions_deque::iterator begin, + transactions_deque::iterator end, + item_handler<transaction_t>& handler) { + for (transactions_deque::iterator i = begin; i != end; i++) + handler(*i); +} + +inline void walk_transactions(transactions_deque& deque, + item_handler<transaction_t>& handler) { + walk_transactions(deque.begin(), deque.end(), handler); +} + +inline void walk_entries(entries_list::iterator begin, + entries_list::iterator end, + item_handler<transaction_t>& handler) { + for (entries_list::iterator i = begin; i != end; i++) + walk_transactions((*i)->transactions, handler); +} + +inline void walk_entries(entries_list& list, + item_handler<transaction_t>& handler) { + walk_entries(list.begin(), list.end(), handler); +} + +////////////////////////////////////////////////////////////////////// + class ignore_transactions : public item_handler<transaction_t> { public: @@ -267,7 +305,7 @@ class subtotal_transactions : public item_handler<transaction_t> delete *i; } - virtual void flush(); + virtual void flush(const char * spec_fmt = NULL); virtual void operator()(transaction_t * xact); }; @@ -292,6 +330,26 @@ class interval_transactions : public subtotal_transactions virtual void operator()(transaction_t * xact); }; +class dow_transactions : public subtotal_transactions +{ + transactions_deque days_of_the_week[7]; + + public: + dow_transactions(item_handler<transaction_t> * handler) + : subtotal_transactions(handler) {} + + virtual ~dow_transactions() { + flush(); + } + + virtual void flush(); + + virtual void operator()(transaction_t * xact) { + struct std::tm * desc = std::gmtime(&xact->entry->date); + days_of_the_week[desc->tm_wday].push_back(xact); + } +}; + class related_transactions : public item_handler<transaction_t> { bool also_matching; @@ -321,44 +379,6 @@ class related_transactions : public item_handler<transaction_t> } }; -////////////////////////////////////////////////////////////////////// - -inline void walk_transactions(transactions_list::iterator begin, - transactions_list::iterator end, - item_handler<transaction_t>& handler) { - for (transactions_list::iterator i = begin; i != end; i++) - handler(*i); -} - -inline void walk_transactions(transactions_list& list, - item_handler<transaction_t>& handler) { - walk_transactions(list.begin(), list.end(), handler); -} - -inline void walk_transactions(transactions_deque::iterator begin, - transactions_deque::iterator end, - item_handler<transaction_t>& handler) { - for (transactions_deque::iterator i = begin; i != end; i++) - handler(*i); -} - -inline void walk_transactions(transactions_deque& deque, - item_handler<transaction_t>& handler) { - walk_transactions(deque.begin(), deque.end(), handler); -} - -inline void walk_entries(entries_list::iterator begin, - entries_list::iterator end, - item_handler<transaction_t>& handler) { - for (entries_list::iterator i = begin; i != end; i++) - walk_transactions((*i)->transactions, handler); -} - -inline void walk_entries(entries_list& list, - item_handler<transaction_t>& handler) { - walk_entries(list.begin(), list.end(), handler); -} - ////////////////////////////////////////////////////////////////////// // |