summaryrefslogtreecommitdiff
path: root/walk.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-08-05 19:12:23 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-08-05 19:12:23 -0400
commit7e87a0a0b1a8b76c44f4f678d8bfb5129ba6c5da (patch)
treeee00c3c5b17534ff44bedc9ff125eb6f3e25e40a /walk.h
parent1741c80fe4f9dd896d4c8912b2ba35b14500ca1c (diff)
downloadfork-ledger-7e87a0a0b1a8b76c44f4f678d8bfb5129ba6c5da.tar.gz
fork-ledger-7e87a0a0b1a8b76c44f4f678d8bfb5129ba6c5da.tar.bz2
fork-ledger-7e87a0a0b1a8b76c44f4f678d8bfb5129ba6c5da.zip
added back sorting support
Diffstat (limited to 'walk.h')
-rw-r--r--walk.h73
1 files changed, 72 insertions, 1 deletions
diff --git a/walk.h b/walk.h
index b509d1dc..f8dba7ed 100644
--- a/walk.h
+++ b/walk.h
@@ -7,6 +7,7 @@
#include "valexpr.h"
#include <iostream>
+#include <deque>
namespace ledger {
@@ -84,7 +85,45 @@ class format_transaction
void operator()(transaction_t * xact,
balance_pair_t * balance,
unsigned int * index,
- const bool inverted) const;
+ const bool inverted) const;
+};
+
+struct compare_transactions {
+ const node_t * sort_order;
+
+ compare_transactions(const node_t * _sort_order)
+ : sort_order(_sort_order) {
+ assert(sort_order);
+ }
+
+ bool operator()(const transaction_t * left,
+ const transaction_t * right) const {
+ assert(left);
+ assert(right);
+ balance_t left_result;
+ sort_order->compute(left_result, details_t(left));
+ balance_t right_result;
+ sort_order->compute(right_result, details_t(right));
+ return left_result < right_result;
+ }
+};
+
+typedef std::deque<transaction_t *> transactions_deque;
+
+class collect_transactions
+{
+ transactions_deque& transactions;
+
+ public:
+ collect_transactions(transactions_deque& _transactions)
+ : transactions(_transactions) {}
+
+ void operator()(transaction_t * xact,
+ balance_pair_t * balance,
+ unsigned int * index,
+ const bool inverted) {
+ transactions.push_back(xact);
+ }
};
class ignore_transaction
@@ -153,6 +192,38 @@ void walk_entries(entries_list::iterator begin,
related, inverted, &balance, &index);
}
+template <typename Function>
+void walk_transactions(transactions_list::iterator begin,
+ transactions_list::iterator end,
+ Function functor,
+ const node_t * predicate,
+ const bool related,
+ const bool inverted,
+ const node_t * display_predicate = NULL)
+{
+ balance_pair_t balance;
+ unsigned int index;
+
+ for (transactions_list::iterator i = begin; i != end; i++)
+ functor(*i, &balance, &index, inverted);
+}
+
+template <typename Function>
+void walk_transactions(transactions_deque::iterator begin,
+ transactions_deque::iterator end,
+ Function functor,
+ const node_t * predicate,
+ const bool related,
+ const bool inverted,
+ const node_t * display_predicate = NULL)
+{
+ balance_pair_t balance;
+ unsigned int index;
+
+ for (transactions_deque::iterator i = begin; i != end; i++)
+ functor(*i, &balance, &index, inverted);
+}
+
class format_account
{
std::ostream& output_stream;