summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--walk.cc47
-rw-r--r--walk.h24
2 files changed, 68 insertions, 3 deletions
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<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);
diff --git a/walk.h b/walk.h
index 871a9639..c8e15a88 100644
--- a/walk.h
+++ b/walk.h
@@ -145,6 +145,25 @@ class ignore_transactions : public item_handler<transaction_t>
virtual void operator()(transaction_t& xact) {}
};
+class truncate_entries : public item_handler<transaction_t>
+{
+ int count;
+ bool tailwise;
+
+ transactions_list xacts;
+
+ public:
+ truncate_entries(item_handler<transaction_t> * handler,
+ int _count, bool _tailwise = false)
+ : item_handler<transaction_t>(handler),
+ count(_count), tailwise(_tailwise) {}
+
+ virtual void flush();
+ virtual void operator()(transaction_t& xact) {
+ xacts.push_back(&xact);
+ }
+};
+
class set_account_value : public item_handler<transaction_t>
{
public:
@@ -159,9 +178,8 @@ class push_to_transactions_list : public item_handler<transaction_t>
public:
transactions_list& xact_list;
- push_to_transactions_list(transactions_list& _xact_list,
- item_handler<transaction_t> * handler = NULL)
- : item_handler<transaction_t>(handler), xact_list(_xact_list) {}
+ push_to_transactions_list(transactions_list& _xact_list)
+ : xact_list(_xact_list) {}
virtual void operator()(transaction_t& xact) {
xact_list.push_back(&xact);