summaryrefslogtreecommitdiff
path: root/walk.h
diff options
context:
space:
mode:
Diffstat (limited to 'walk.h')
-rw-r--r--walk.h93
1 files changed, 41 insertions, 52 deletions
diff --git a/walk.h b/walk.h
index 3eedbae9..de98d071 100644
--- a/walk.h
+++ b/walk.h
@@ -4,7 +4,6 @@
#include "journal.h"
#include "balance.h"
#include "valexpr.h"
-#include "datetime.h"
#include <iostream>
#include <fstream>
@@ -18,13 +17,13 @@ struct item_handler {
public:
item_handler() : handler(NULL) {
- DEBUG_PRINT("ledger.memory.ctors", "ctor item_handler<T>");
+ DEBUG("ledger.memory.ctors", "ctor item_handler<T>");
}
item_handler(item_handler * _handler) : handler(_handler) {
- DEBUG_PRINT("ledger.memory.ctors", "ctor item_handler<T>");
+ DEBUG("ledger.memory.ctors", "ctor item_handler<T>");
}
virtual ~item_handler() {
- DEBUG_PRINT("ledger.memory.dtors", "dtor item_handler<T>");
+ DEBUG("ledger.memory.dtors", "dtor item_handler<T>");
}
virtual void flush() {
@@ -39,12 +38,9 @@ struct item_handler {
template <typename T>
class compare_items {
- const value_expr_t * sort_order;
+ value_expr sort_order;
public:
- compare_items(const value_expr_t * _sort_order)
- : sort_order(_sort_order) {
- assert(sort_order);
- }
+ compare_items(value_expr _sort_order) : sort_order(_sort_order) {}
bool operator()(const T * left, const T * right);
};
@@ -56,8 +52,8 @@ bool compare_items<T>::operator()(const T * left, const T * right)
value_t left_result;
value_t right_result;
- guarded_compute(sort_order, left_result, details_t(*left));
- guarded_compute(sort_order, right_result, details_t(*right));
+ sort_order.compute(left_result, details_t(*left));
+ sort_order.compute(right_result, details_t(*right));
return left_result < right_result;
}
@@ -99,11 +95,11 @@ struct transaction_xdata_t
transaction_xdata_t()
: index(0), dflags(0),
account(NULL), ptr(NULL), component_xacts(NULL) {
- DEBUG_PRINT("ledger.memory.ctors", "ctor transaction_xdata_t " << this);
+ DEBUG("ledger.memory.ctors", "ctor transaction_xdata_t " << this);
}
~transaction_xdata_t() {
- DEBUG_PRINT("ledger.memory.dtors", "dtor transaction_xdata_t " << this);
+ DEBUG("ledger.memory.dtors", "dtor transaction_xdata_t " << this);
if (component_xacts)
delete component_xacts;
}
@@ -245,26 +241,19 @@ class sort_transactions : public item_handler<transaction_t>
{
typedef std::deque<transaction_t *> transactions_deque;
- transactions_deque transactions;
- const value_expr_t * sort_order;
+ transactions_deque transactions;
+ const value_expr sort_order;
public:
sort_transactions(item_handler<transaction_t> * handler,
- const value_expr_t * _sort_order)
+ const value_expr& _sort_order)
: item_handler<transaction_t>(handler),
- sort_order(_sort_order->acquire()) {}
+ sort_order(_sort_order) {}
sort_transactions(item_handler<transaction_t> * handler,
- const std::string& _sort_order)
- : item_handler<transaction_t>(handler) {
- assert(! _sort_order.empty());
- sort_order = parse_value_expr(_sort_order)->acquire();
- }
-
- virtual ~sort_transactions() {
- assert(sort_order);
- sort_order->release();
- }
+ const string& _sort_order)
+ : item_handler<transaction_t>(handler),
+ sort_order(_sort_order) {}
virtual void post_accumulated_xacts();
@@ -285,11 +274,11 @@ class sort_entries : public item_handler<transaction_t>
public:
sort_entries(item_handler<transaction_t> * handler,
- const value_expr_t * _sort_order)
+ const value_expr& _sort_order)
: sorter(handler, _sort_order) {}
sort_entries(item_handler<transaction_t> * handler,
- const std::string& _sort_order)
+ const string& _sort_order)
: sorter(handler, _sort_order) {}
virtual void flush() {
@@ -313,11 +302,11 @@ class filter_transactions : public item_handler<transaction_t>
public:
filter_transactions(item_handler<transaction_t> * handler,
- const value_expr_t * predicate)
+ const value_expr& predicate)
: item_handler<transaction_t>(handler), pred(predicate) {}
filter_transactions(item_handler<transaction_t> * handler,
- const std::string& predicate)
+ const string& predicate)
: item_handler<transaction_t>(handler), pred(predicate) {}
virtual void operator()(transaction_t& xact) {
@@ -393,11 +382,11 @@ class component_transactions : public item_handler<transaction_t>
public:
component_transactions(item_handler<transaction_t> * handler,
- const value_expr_t * predicate)
+ const value_expr& predicate)
: item_handler<transaction_t>(handler), pred(predicate) {}
component_transactions(item_handler<transaction_t> * handler,
- const std::string& predicate)
+ const string& predicate)
: item_handler<transaction_t>(handler), pred(predicate) {}
virtual void operator()(transaction_t& xact);
@@ -445,7 +434,7 @@ class changed_value_transactions : public item_handler<transaction_t>
virtual void flush() {
if (last_xact) {
- output_diff(datetime_t::now);
+ output_diff(current_moment);
last_xact = NULL;
}
item_handler<transaction_t>::flush();
@@ -470,8 +459,8 @@ class subtotal_transactions : public item_handler<transaction_t>
: account(av.account), value(av.value) {}
};
- typedef std::map<std::string, acct_value_t> values_map;
- typedef std::pair<std::string, acct_value_t> values_pair;
+ typedef std::map<string, acct_value_t> values_map;
+ typedef std::pair<string, acct_value_t> values_pair;
protected:
values_map values;
@@ -490,7 +479,7 @@ class subtotal_transactions : public item_handler<transaction_t>
remember_components(_remember_components) {}
#ifdef DEBUG_ENABLED
subtotal_transactions(const subtotal_transactions&) {
- assert(0);
+ assert(false);
}
#endif
virtual ~subtotal_transactions() {
@@ -509,7 +498,7 @@ class subtotal_transactions : public item_handler<transaction_t>
class interval_expr_error : public error {
public:
- interval_expr_error(const std::string& reason,
+ interval_expr_error(const string& reason,
error_context * ctxt = NULL) throw()
: error(reason, ctxt) {}
virtual ~interval_expr_error() throw() {}
@@ -529,7 +518,7 @@ class interval_transactions : public subtotal_transactions
interval(_interval), last_xact(NULL), started(false) {}
interval_transactions(item_handler<transaction_t> * _handler,
- const std::string& _interval,
+ const string& _interval,
bool remember_components = false)
: subtotal_transactions(_handler, remember_components),
interval(_interval), last_xact(NULL), started(false) {}
@@ -546,8 +535,8 @@ class interval_transactions : public subtotal_transactions
class by_payee_transactions : public item_handler<transaction_t>
{
- typedef std::map<std::string, subtotal_transactions *> payee_subtotals_map;
- typedef std::pair<std::string, subtotal_transactions *> payee_subtotals_pair;
+ typedef std::map<string, subtotal_transactions *> payee_subtotals_map;
+ typedef std::pair<string, subtotal_transactions *> payee_subtotals_pair;
payee_subtotals_map payee_subtotals;
bool remember_components;
@@ -606,7 +595,7 @@ class dow_transactions : public subtotal_transactions
virtual void flush();
virtual void operator()(transaction_t& xact) {
- days_of_the_week[xact.date().wday()].push_back(&xact);
+ days_of_the_week[xact.date().date().day_of_week()].push_back(&xact);
}
};
@@ -657,11 +646,11 @@ class forecast_transactions : public generate_transactions
public:
forecast_transactions(item_handler<transaction_t> * handler,
- const value_expr_t * predicate)
+ const value_expr& predicate)
: generate_transactions(handler), pred(predicate) {}
forecast_transactions(item_handler<transaction_t> * handler,
- const std::string& predicate)
+ const string& predicate)
: generate_transactions(handler), pred(predicate) {}
virtual void add_transaction(const interval_t& period,
@@ -721,19 +710,19 @@ void sum_accounts(account_t& account);
typedef std::deque<account_t *> accounts_deque;
-void sort_accounts(account_t& account,
- const value_expr_t * sort_order,
- accounts_deque& accounts);
-void walk_accounts(account_t& account,
- item_handler<account_t>& handler,
- const value_expr_t * sort_order = NULL);
+void sort_accounts(account_t& account,
+ const value_expr& sort_order,
+ accounts_deque& accounts);
+void walk_accounts(account_t& account,
+ item_handler<account_t>& handler,
+ const optional<value_expr>& sort_order = none);
void walk_accounts(account_t& account,
item_handler<account_t>& handler,
- const std::string& sort_string);
+ const string& sort_string);
//////////////////////////////////////////////////////////////////////
-void walk_commodities(commodities_map& commodities,
+void walk_commodities(commodity_pool_t::commodities_by_ident& commodities,
item_handler<transaction_t>& handler);
inline void clear_journal_xdata(journal_t * journal) {