diff options
author | John Wiegley <johnw@newartisans.com> | 2005-02-14 07:45:09 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 02:41:00 -0400 |
commit | dc4c2b8d50fa7014bccfc5251c7a90d62926ddb6 (patch) | |
tree | ed066ab189199a26fcb7123f5f74ad0735654a43 /walk.cc | |
parent | 962e17c1a94575cb690aa9fb24ed666bcba8aabe (diff) | |
download | fork-ledger-dc4c2b8d50fa7014bccfc5251c7a90d62926ddb6.tar.gz fork-ledger-dc4c2b8d50fa7014bccfc5251c7a90d62926ddb6.tar.bz2 fork-ledger-dc4c2b8d50fa7014bccfc5251c7a90d62926ddb6.zip |
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.
Diffstat (limited to 'walk.cc')
-rw-r--r-- | walk.cc | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -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<transaction_t>::operator()(**x); + } + item_handler<transaction_t>::flush(); +} + void set_account_value::operator()(transaction_t& xact) { add_transaction_to(xact, account_xdata(*xact.account).value); |