diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-19 16:53:25 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-19 16:53:25 -0400 |
commit | 9805abbf2b38d64308bac536eea40e544e8f7cfe (patch) | |
tree | 32f6b6ae629409a118efdbc99f377fa86640e33d /src/iterators.cc | |
parent | d67c9fee0f0f576481065c7d50182a04bf5df37e (diff) | |
download | fork-ledger-9805abbf2b38d64308bac536eea40e544e8f7cfe.tar.gz fork-ledger-9805abbf2b38d64308bac536eea40e544e8f7cfe.tar.bz2 fork-ledger-9805abbf2b38d64308bac536eea40e544e8f7cfe.zip |
Allow for sorting of the balance report
Sorting is repeated at each level of the hierarchy, unless --flat was
specified in which case it applies to the entire applicable accounts
list.
Diffstat (limited to 'src/iterators.cc')
-rw-r--r-- | src/iterators.cc | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/iterators.cc b/src/iterators.cc index 01f678d0..3a59c7aa 100644 --- a/src/iterators.cc +++ b/src/iterators.cc @@ -179,6 +179,33 @@ void sorted_accounts_iterator::sort_accounts(account_t& account, compare_items<account_t>(sort_cmp)); } +void sorted_accounts_iterator::push_all(account_t& account) +{ + accounts_deque_t& deque(accounts_list.back()); + + foreach (accounts_map::value_type& pair, account.accounts) { + deque.push_back(pair.second); + push_all(*pair.second); + } +} + +void sorted_accounts_iterator::push_back(account_t& account) +{ + accounts_list.push_back(accounts_deque_t()); + + if (flatten_all) { + push_all(account); + std::stable_sort(accounts_list.back().begin(), + accounts_list.back().end(), + compare_items<account_t>(sort_cmp)); + } else { + sort_accounts(account, accounts_list.back()); + } + + sorted_accounts_i.push_back(accounts_list.back().begin()); + sorted_accounts_end.push_back(accounts_list.back().end()); +} + account_t * sorted_accounts_iterator::operator()() { while (! sorted_accounts_i.empty() && @@ -195,9 +222,10 @@ account_t * sorted_accounts_iterator::operator()() assert(account); // If this account has children, queue them up to be iterated next. - if (! account->accounts.empty()) + if (! flatten_all && ! account->accounts.empty()) push_back(*account); + // Make sure the sorting value gets recalculated for this account account->xdata().drop_flags(ACCOUNT_EXT_SORT_CALC); return account; } |