diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/account.cc | 11 | ||||
-rw-r--r-- | src/account.h | 2 | ||||
-rw-r--r-- | src/chain.cc | 11 | ||||
-rw-r--r-- | src/filters.cc | 20 | ||||
-rw-r--r-- | src/filters.h | 49 | ||||
-rw-r--r-- | src/report.cc | 4 | ||||
-rw-r--r-- | src/xact.cc | 12 | ||||
-rw-r--r-- | src/xact.h | 2 |
8 files changed, 54 insertions, 57 deletions
diff --git a/src/account.cc b/src/account.cc index b6681c54..339d1ef4 100644 --- a/src/account.cc +++ b/src/account.cc @@ -246,13 +246,12 @@ bool account_t::valid() const return true; } -void account_t::calculate_sums(expr_t& amount_expr, - scope_t& scope) +void account_t::calculate_sums(expr_t& amount_expr) { xdata_t& xd(xdata()); foreach (accounts_map::value_type& pair, accounts) { - (*pair.second).calculate_sums(amount_expr, scope); + (*pair.second).calculate_sums(amount_expr); xdata_t& child_xd((*pair.second).xdata()); if (! child_xd.total.is_null()) { @@ -264,10 +263,8 @@ void account_t::calculate_sums(expr_t& amount_expr, } } - bind_scope_t bound_scope(scope, *this); - call_scope_t args(bound_scope); - - value_t amount(amount_expr.calc(args)); + bind_scope_t bound_scope(*amount_expr.get_context(), *this); + value_t amount(amount_expr.calc(bound_scope)); if (! amount.is_null()) { add_or_set_value(xd.total, amount); diff --git a/src/account.h b/src/account.h index 18792154..24414403 100644 --- a/src/account.h +++ b/src/account.h @@ -178,7 +178,7 @@ class account_t : public scope_t return *xdata_; } - void calculate_sums(expr_t& amount_expr, scope_t& scope); + void calculate_sums(expr_t& amount_expr); }; std::ostream& operator<<(std::ostream& out, const account_t& account); diff --git a/src/chain.cc b/src/chain.cc index c953366a..ed800c47 100644 --- a/src/chain.cc +++ b/src/chain.cc @@ -92,7 +92,7 @@ xact_handler_ptr chain_xact_handlers(report_t& report, // collapse_xacts causes entries with multiple xacts to appear as entries // with a subtotaled xact for each commodity used. if (report.HANDLED(collapse)) - handler.reset(new collapse_xacts(handler, report.session)); + handler.reset(new collapse_xacts(handler, expr)); // subtotal_xacts combines all the xacts it receives into one subtotal // entry, which has one xact for each commodity in each account. @@ -103,17 +103,18 @@ xact_handler_ptr chain_xact_handlers(report_t& report, // dow_xacts is like period_xacts, except that it reports all the xacts // that fall on each subsequent day of the week. if (report.HANDLED(subtotal)) - handler.reset(new subtotal_xacts(handler)); + handler.reset(new subtotal_xacts(handler, expr)); if (report.HANDLED(dow)) - handler.reset(new dow_xacts(handler)); + handler.reset(new dow_xacts(handler, expr)); else if (report.HANDLED(by_payee)) - handler.reset(new by_payee_xacts(handler)); + handler.reset(new by_payee_xacts(handler, expr)); // interval_xacts groups xacts together based on a time period, such as // weekly or monthly. if (report.HANDLED(period_)) { - handler.reset(new interval_xacts(handler, report.HANDLER(period_).str())); + handler.reset(new interval_xacts(handler, expr, + report.HANDLER(period_).str())); handler.reset(new sort_xacts(handler, "d")); } } diff --git a/src/filters.cc b/src/filters.cc index 4fcada4b..fbca7a0b 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -32,7 +32,6 @@ #include "filters.h" #include "iterators.h" #include "compare.h" -#include "session.h" #include "format.h" namespace ledger { @@ -102,7 +101,7 @@ void set_account_value::operator()(xact_t& xact) account_t::xdata_t& xdata(acct->xdata()); DEBUG("account.sums", "Account value was = " << xdata.value); - xact.add_to_value(xdata.value); + xact.add_to_value(xdata.value, amount_expr); DEBUG("account.sums", "Account value is = " << xdata.value); xdata.count++; @@ -190,13 +189,7 @@ void calc_xacts::operator()(xact_t& xact) if (last_xact && last_xact->has_xdata()) add_or_set_value(xdata.total, last_xact->xdata().total); - if (! xdata.has_flags(XACT_EXT_NO_TOTAL)) { - bind_scope_t bound_scope(*amount_expr.get_context(), xact); - if (xdata.total.is_null()) - xdata.total = amount_expr.calc(bound_scope); - else - xdata.total += amount_expr.calc(bound_scope); - } + xact.add_to_value(xdata.total, amount_expr); item_handler<xact_t>::operator()(xact); @@ -316,7 +309,7 @@ void collapse_xacts::operator()(xact_t& xact) if (last_entry != xact.entry && count > 0) report_subtotal(); - xact.add_to_value(subtotal); + xact.add_to_value(subtotal, amount_expr); count++; last_entry = xact.entry; @@ -427,12 +420,12 @@ void subtotal_xacts::operator()(xact_t& xact) values_map::iterator i = values.find(acct->fullname()); if (i == values.end()) { value_t temp; - xact.add_to_value(temp); + xact.add_to_value(temp, amount_expr); std::pair<values_map::iterator, bool> result = values.insert(values_pair(acct->fullname(), acct_value_t(acct, temp))); assert(result.second); } else { - xact.add_to_value((*i).second.value); + xact.add_to_value((*i).second.value, amount_expr); } // If the account for this xact is all virtual, mark it as @@ -520,7 +513,8 @@ void by_payee_xacts::operator()(xact_t& xact) { payee_subtotals_map::iterator i = payee_subtotals.find(xact.entry->payee); if (i == payee_subtotals.end()) { - payee_subtotals_pair temp(xact.entry->payee, new subtotal_xacts(handler)); + payee_subtotals_pair temp(xact.entry->payee, + new subtotal_xacts(handler, amount_expr)); std::pair<payee_subtotals_map::iterator, bool> result = payee_subtotals.insert(temp); diff --git a/src/filters.h b/src/filters.h index 06698a22..6d8a2758 100644 --- a/src/filters.h +++ b/src/filters.h @@ -167,9 +167,11 @@ public: */ class set_account_value : public item_handler<xact_t> { + expr_t& amount_expr; + public: - set_account_value(xact_handler_ptr handler = xact_handler_ptr()) - : item_handler<xact_t>(handler) {} + set_account_value(expr_t& _amount_expr) + : item_handler<xact_t>(), amount_expr(_amount_expr) {} virtual void operator()(xact_t& xact); }; @@ -373,6 +375,7 @@ inline void clear_entries_xacts(std::list<entry_t>& entries_list) { */ class collapse_xacts : public item_handler<xact_t> { + expr_t& amount_expr; value_t subtotal; std::size_t count; entry_t * last_entry; @@ -385,9 +388,9 @@ class collapse_xacts : public item_handler<xact_t> collapse_xacts(); public: - collapse_xacts(xact_handler_ptr handler, session_t& session) - : item_handler<xact_t>(handler), count(0), - last_entry(NULL), last_xact(NULL), + collapse_xacts(xact_handler_ptr handler, expr_t& _amount_expr) + : item_handler<xact_t>(handler), amount_expr(_amount_expr), + count(0), last_entry(NULL), last_xact(NULL), totals_account(NULL, "<Total>") { TRACE_CTOR(collapse_xacts, "xact_handler_ptr"); } @@ -520,6 +523,7 @@ class subtotal_xacts : public item_handler<xact_t> subtotal_xacts(); protected: + expr_t& amount_expr; values_map values; optional<string> date_format; std::list<entry_t> entry_temps; @@ -529,11 +533,12 @@ public: date_t start; date_t finish; - subtotal_xacts(xact_handler_ptr handler, - optional<string> _date_format = none) - : item_handler<xact_t>(handler), date_format(_date_format) { + subtotal_xacts(xact_handler_ptr handler, expr_t& _amount_expr, + const optional<string>& _date_format = none) + : item_handler<xact_t>(handler), amount_expr(_amount_expr), + date_format(_date_format) { TRACE_CTOR(subtotal_xacts, - "xact_handler_ptr, bool"); + "xact_handler_ptr, expr_t&, const optional<string>&"); } virtual ~subtotal_xacts() { TRACE_DTOR(subtotal_xacts); @@ -557,23 +562,23 @@ public: */ class interval_xacts : public subtotal_xacts { - interval_t interval; - xact_t * last_xact; - bool started; + interval_t interval; + xact_t * last_xact; + bool started; interval_xacts(); public: - interval_xacts(xact_handler_ptr _handler, + interval_xacts(xact_handler_ptr _handler, expr_t& amount_expr, const interval_t& _interval) - : subtotal_xacts(_handler), interval(_interval), + : subtotal_xacts(_handler, amount_expr), interval(_interval), last_xact(NULL), started(false) { TRACE_CTOR(interval_xacts, "xact_handler_ptr, const interval_t&, bool"); } - interval_xacts(xact_handler_ptr _handler, + interval_xacts(xact_handler_ptr _handler, expr_t& amount_expr, const string& _interval) - : subtotal_xacts(_handler), interval(_interval), + : subtotal_xacts(_handler, amount_expr), interval(_interval), last_xact(NULL), started(false) { TRACE_CTOR(interval_xacts, "xact_handler_ptr, const string&, bool"); @@ -602,15 +607,15 @@ class by_payee_xacts : public item_handler<xact_t> typedef std::map<string, subtotal_xacts *> payee_subtotals_map; typedef std::pair<string, subtotal_xacts *> payee_subtotals_pair; + expr_t& amount_expr; payee_subtotals_map payee_subtotals; by_payee_xacts(); public: - by_payee_xacts(xact_handler_ptr handler) - : item_handler<xact_t>(handler) { - TRACE_CTOR(by_payee_xacts, - "xact_handler_ptr, bool"); + by_payee_xacts(xact_handler_ptr handler, expr_t& _amount_expr) + : item_handler<xact_t>(handler), amount_expr(_amount_expr) { + TRACE_CTOR(by_payee_xacts, "xact_handler_ptr, expr_t&"); } virtual ~by_payee_xacts(); @@ -680,8 +685,8 @@ class dow_xacts : public subtotal_xacts dow_xacts(); public: - dow_xacts(xact_handler_ptr handler) - : subtotal_xacts(handler) { + dow_xacts(xact_handler_ptr handler, expr_t& amount_expr) + : subtotal_xacts(handler, amount_expr) { TRACE_CTOR(dow_xacts, "xact_handler_ptr, bool"); } virtual ~dow_xacts() throw() { diff --git a/src/report.cc b/src/report.cc index 9966a339..96304494 100644 --- a/src/report.cc +++ b/src/report.cc @@ -112,8 +112,8 @@ void report_t::sum_all_accounts() session_xacts_iterator walker(session); pass_down_xacts - (chain_xact_handlers(*this, xact_handler_ptr(new set_account_value), false), - walker); + (chain_xact_handlers(*this, xact_handler_ptr(new set_account_value(expr)), + false), walker); expr.mark_uncompiled(); // recompile, throw away xact_t bindings session.master->calculate_sums(expr); diff --git a/src/xact.cc b/src/xact.cc index 06f4d465..b9fb0e2f 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -245,18 +245,18 @@ bool xact_t::valid() const return true; } -void xact_t::add_to_value(value_t& value) +void xact_t::add_to_value(value_t& value, expr_t& expr) { if (xdata_ && xdata_->has_flags(XACT_EXT_COMPOUND)) { add_or_set_value(value, xdata_->value); } - else if (cost || (! value.is_null() && ! value.is_realzero())) { + + if (! xdata_ || ! xdata_->has_flags(XACT_EXT_NO_TOTAL)) { + bind_scope_t bound_scope(*expr.get_context(), *this); if (value.is_null()) value = amount_t(); - value.add(amount, cost); - } - else { - value = amount; + + value += expr.calc(bound_scope); } } @@ -174,7 +174,7 @@ public: return *xdata_; } - void add_to_value(value_t& value); + void add_to_value(value_t& value, expr_t& expr); date_t reported_date() const { if (xdata_ && is_valid(xdata_->date)) |