summaryrefslogtreecommitdiff
path: root/walk.cc
blob: ee915164d3b9f609eb278a3de1ea46c5738b9e14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "walk.h"

namespace ledger {

struct sum_in_account : public item_handler<transaction_t> {
  virtual void operator()(transaction_t * xact) const {
    xact->account->value += *xact;
  }
};

void calc__accounts(account_t * account,
		    const item_predicate<transaction_t>& pred,
		    unsigned int flags)
{
  sum_in_account handler;

  for (transactions_list::iterator i = account->transactions.begin();
       i != account->transactions.end();
       i++)
    if (pred(*i))
      handle_transaction(*i, handler, flags);

  for (accounts_map::iterator i = account->accounts.begin();
       i != account->accounts.end();
       i++)
    calc__accounts((*i).second, pred, flags);
}

} // namespace ledger