diff options
Diffstat (limited to 'walk.cc')
-rw-r--r-- | walk.cc | 136 |
1 files changed, 70 insertions, 66 deletions
@@ -11,43 +11,43 @@ void sort_transactions::flush() for (std::deque<transaction_t *>::iterator i = transactions.begin(); i != transactions.end(); i++) - (*handler)(*i); + (*handler)(**i); transactions.clear(); item_handler<transaction_t>::flush(); } -void calc_transactions::operator()(transaction_t * xact) +void calc_transactions::operator()(transaction_t& xact) { - if (! xact->data) - xact->data = new transaction_data_t; + if (! xact.data) + xact.data = new transaction_data_t; if (last_xact && last_xact->data) { - XACT_DATA(xact)->total += XACT_DATA(last_xact)->total; - XACT_DATA(xact)->index = XACT_DATA(last_xact)->index + 1; + XACT_DATA_(xact)->total += XACT_DATA(last_xact)->total; + XACT_DATA_(xact)->index = XACT_DATA(last_xact)->index + 1; } else { - XACT_DATA(xact)->index = 0; + XACT_DATA_(xact)->index = 0; } if (inverted) { - xact->amount.negate(); - if (xact->cost) - xact->cost->negate(); + xact.amount.negate(); + if (xact.cost) + xact.cost->negate(); } - if (! (XACT_DATA(xact)->dflags & TRANSACTION_NO_TOTAL)) - XACT_DATA(xact)->total += *xact; + if (! (XACT_DATA_(xact)->dflags & TRANSACTION_NO_TOTAL)) + add_transaction_to(xact, XACT_DATA_(xact)->total); (*handler)(xact); if (inverted) { - xact->amount.negate(); - if (xact->cost) - xact->cost->negate(); + xact.amount.negate(); + if (xact.cost) + xact.cost->negate(); } - last_xact = xact; + last_xact = &xact; } @@ -65,7 +65,7 @@ static void handle_value(const value_t& value, account_t * account, transaction_t * xact = new transaction_t(account); temps.push_back(xact); - xact->entry = entry; + xact->entry = entry; switch (value.type) { case value_t::BOOLEAN: xact->amount = *((bool *) value.data); @@ -87,7 +87,7 @@ static void handle_value(const value_t& value, account_t * account, XACT_DATA(xact)->dflags |= flags; } - (*handler)(xact); + (*handler)(*xact); break; } @@ -114,7 +114,7 @@ static void handle_value(const value_t& value, account_t * account, XACT_DATA(xact)->dflags |= flags; } - (*handler)(xact); + (*handler)(*xact); } break; @@ -127,7 +127,7 @@ static void handle_value(const value_t& value, account_t * account, void collapse_transactions::report_cumulative_subtotal() { if (count == 1) { - (*handler)(last_xact); + (*handler)(*last_xact); } else { assert(count > 1); @@ -135,7 +135,7 @@ void collapse_transactions::report_cumulative_subtotal() totals_account->data = new account_data_t; ACCT_DATA(totals_account)->total = subtotal; value_t result; - format_t::compute_total(result, details_t(totals_account)); + format_t::compute_total(result, details_t(*totals_account)); handle_value(result, totals_account, last_entry, 0, xact_temps, handler); } @@ -143,44 +143,45 @@ void collapse_transactions::report_cumulative_subtotal() count = 0; } -void changed_value_transactions::operator()(transaction_t * xact) +void changed_value_transactions::output_diff(const std::time_t current) { - if (last_xact) { - value_t prev_bal; - value_t cur_bal; - std::time_t current = xact ? xact->entry->date : std::time(NULL); - std::time_t prev_date = last_xact->entry->date; + value_t prev_bal; + value_t cur_bal; + std::time_t prev_date = last_xact->entry->date; - format_t::compute_total(prev_bal, details_t(last_xact)); + format_t::compute_total(prev_bal, details_t(*last_xact)); - last_xact->entry->date = current; - format_t::compute_total(cur_bal, details_t(last_xact)); - last_xact->entry->date = prev_date; + last_xact->entry->date = current; + format_t::compute_total(cur_bal, details_t(*last_xact)); + last_xact->entry->date = prev_date; - cur_bal -= prev_bal; - if (cur_bal) { - entry_t * entry = new entry_t; - entry_temps.push_back(entry); + cur_bal -= prev_bal; + if (cur_bal) { + entry_t * entry = new entry_t; + entry_temps.push_back(entry); - entry->payee = "Commodities revalued"; - entry->date = current; + entry->payee = "Commodities revalued"; + entry->date = current; - handle_value(cur_bal, NULL, entry, TRANSACTION_NO_TOTAL, xact_temps, - handler); - } + handle_value(cur_bal, NULL, entry, TRANSACTION_NO_TOTAL, xact_temps, + handler); } +} - if (xact) { - if (changed_values_only) { - if (! xact->data) - xact->data = new transaction_data_t; - XACT_DATA(xact)->dflags |= TRANSACTION_DISPLAYED; - } +void changed_value_transactions::operator()(transaction_t& xact) +{ + if (last_xact) + output_diff(xact.entry->date); - (*handler)(xact); + if (changed_values_only) { + if (! xact.data) + xact.data = new transaction_data_t; + XACT_DATA_(xact)->dflags |= TRANSACTION_DISPLAYED; } - last_xact = xact; + (*handler)(xact); + + last_xact = &xact; } void subtotal_transactions::flush(const char * spec_fmt) @@ -218,7 +219,7 @@ void subtotal_transactions::flush(const char * spec_fmt) std::auto_ptr<transaction_data_t> xact_data(new transaction_data_t); temp.data = xact_data.get(); ((transaction_data_t *) temp.data)->total = (*i).second; - format_t::compute_total(result, details_t(&temp)); + format_t::compute_total(result, details_t(temp)); } temp.data = NULL; } @@ -232,28 +233,31 @@ void subtotal_transactions::flush(const char * spec_fmt) item_handler<transaction_t>::flush(); } -void subtotal_transactions::operator()(transaction_t * xact) +void subtotal_transactions::operator()(transaction_t& xact) { if (balances.size() == 0) { - start = finish = xact->entry->date; + start = finish = xact.entry->date; } else { - if (std::difftime(xact->entry->date, start) < 0) - start = xact->entry->date; - if (std::difftime(xact->entry->date, finish) > 0) - finish = xact->entry->date; + if (std::difftime(xact.entry->date, start) < 0) + start = xact.entry->date; + if (std::difftime(xact.entry->date, finish) > 0) + finish = xact.entry->date; } - balances_map::iterator i = balances.find(xact->account); - if (i == balances.end()) - balances.insert(balances_pair(xact->account, *xact)); - else - (*i).second += *xact; + balances_map::iterator i = balances.find(xact.account); + if (i == balances.end()) { + balance_pair_t temp; + add_transaction_to(xact, temp); + balances.insert(balances_pair(xact.account, temp)); + } else { + add_transaction_to(xact, (*i).second); + } } -void interval_transactions::operator()(transaction_t * xact) +void interval_transactions::operator()(transaction_t& xact) { std::time_t quant = interval.increment(begin); - if (std::difftime(xact->entry->date, quant) > 0) { + if (std::difftime(xact.entry->date, quant) > 0) { if (last_xact) { start = begin; finish = quant; @@ -261,7 +265,7 @@ void interval_transactions::operator()(transaction_t * xact) } if (! interval.seconds) { - struct std::tm * desc = std::localtime(&xact->entry->date); + struct std::tm * desc = std::localtime(&xact.entry->date); if (interval.years) desc->tm_mon = 0; desc->tm_mday = 1; @@ -272,7 +276,7 @@ void interval_transactions::operator()(transaction_t * xact) } std::time_t temp; - while (std::difftime(xact->entry->date, + while (std::difftime(xact.entry->date, temp = interval.increment(quant)) > 0) quant = temp; begin = quant; @@ -280,7 +284,7 @@ void interval_transactions::operator()(transaction_t * xact) subtotal_transactions::operator()(xact); - last_xact = xact; + last_xact = &xact; } void dow_transactions::flush() @@ -289,7 +293,7 @@ void dow_transactions::flush() for (std::deque<transaction_t *>::iterator d = days_of_the_week[i].begin(); d != days_of_the_week[i].end(); d++) - subtotal_transactions::operator()(*d); + subtotal_transactions::operator()(**d); subtotal_transactions::flush("%As"); days_of_the_week[i].clear(); } |