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.
This commit is contained in:
parent
962e17c1a9
commit
dc4c2b8d50
2 changed files with 68 additions and 3 deletions
47
walk.cc
47
walk.cc
|
|
@ -56,6 +56,53 @@ void add_transaction_to(const transaction_t& xact, value_t& value)
|
||||||
value = xact.amount;
|
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)
|
void set_account_value::operator()(transaction_t& xact)
|
||||||
{
|
{
|
||||||
add_transaction_to(xact, account_xdata(*xact.account).value);
|
add_transaction_to(xact, account_xdata(*xact.account).value);
|
||||||
|
|
|
||||||
24
walk.h
24
walk.h
|
|
@ -145,6 +145,25 @@ class ignore_transactions : public item_handler<transaction_t>
|
||||||
virtual void operator()(transaction_t& xact) {}
|
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>
|
class set_account_value : public item_handler<transaction_t>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -159,9 +178,8 @@ class push_to_transactions_list : public item_handler<transaction_t>
|
||||||
public:
|
public:
|
||||||
transactions_list& xact_list;
|
transactions_list& xact_list;
|
||||||
|
|
||||||
push_to_transactions_list(transactions_list& _xact_list,
|
push_to_transactions_list(transactions_list& _xact_list)
|
||||||
item_handler<transaction_t> * handler = NULL)
|
: xact_list(_xact_list) {}
|
||||||
: item_handler<transaction_t>(handler), xact_list(_xact_list) {}
|
|
||||||
|
|
||||||
virtual void operator()(transaction_t& xact) {
|
virtual void operator()(transaction_t& xact) {
|
||||||
xact_list.push_back(&xact);
|
xact_list.push_back(&xact);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue