From dc4c2b8d50fa7014bccfc5251c7a90d62926ddb6 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 14 Feb 2005 07:45:09 +0000 Subject: Added the new transaction handler `truncate_entries' which can be used to trim a number of entries from the beginning or end of a transction stream. (push_to_transactions_list): Removed unneeded "handler" argument. --- walk.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'walk.cc') diff --git a/walk.cc b/walk.cc index da7db316..a402ebf5 100644 --- a/walk.cc +++ b/walk.cc @@ -56,6 +56,53 @@ void add_transaction_to(const transaction_t& xact, value_t& value) value = xact.amount; } +void truncate_entries::flush() +{ + if (! xacts.size()) + return; + + entry_t * last_entry = (*xacts.begin())->entry; + + int l = 0; + for (transactions_list::iterator x = xacts.begin(); + x != xacts.end(); + x++) + if (last_entry != (*x)->entry) { + l++; + last_entry = (*x)->entry; + } + l++; + + last_entry = (*xacts.begin())->entry; + + int i = 0; + for (transactions_list::iterator x = xacts.begin(); + x != xacts.end(); + x++) { + if (last_entry != (*x)->entry) { + last_entry = (*x)->entry; + i++; + } + + bool print = false; + if (tailwise) { + if (count > 0 && l - i <= count) + print = true; + else if (count < 0 && l - i > - count) + print = true; + } else { + if (count > 0 && i < count) + print = true; + else if (count < 0 && i >= - count) + print = true; + } + + if (print) + item_handler::operator()(**x); + } + item_handler::flush(); +} + void set_account_value::operator()(transaction_t& xact) { add_transaction_to(xact, account_xdata(*xact.account).value); -- cgit v1.2.3