diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-19 21:57:17 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-19 21:57:17 -0400 |
commit | 2694335e54316606ab169e957034ba71e8274144 (patch) | |
tree | 6c0c4ab3a4f525b0afee911a674b47abf1bbc324 /src | |
parent | 7fb328707cab288a49bd84c16c2b9eb7a02c5196 (diff) | |
download | fork-ledger-2694335e54316606ab169e957034ba71e8274144.tar.gz fork-ledger-2694335e54316606ab169e957034ba71e8274144.tar.bz2 fork-ledger-2694335e54316606ab169e957034ba71e8274144.zip |
Simplify account total values before comparison
This way, if two account values are BALANCE types containing only a
single AMOUNT, then it will do the sorting comparison of the amounts --
since otherwise balances are ignored for the purposes of sorting.
Diffstat (limited to 'src')
-rw-r--r-- | src/compare.cc | 9 | ||||
-rw-r--r-- | src/iterators.cc | 7 | ||||
-rw-r--r-- | src/value.cc | 5 |
3 files changed, 16 insertions, 5 deletions
diff --git a/src/compare.cc b/src/compare.cc index 6b0cbe0d..015c28bc 100644 --- a/src/compare.cc +++ b/src/compare.cc @@ -53,10 +53,12 @@ namespace { sort_values.push_back(sort_value_t()); sort_values.back().inverted = inverted; - sort_values.back().value = expr_t(node).calc(*scope).reduced(); + sort_values.back().value = + expr_t(node).calc(*scope).reduced().simplified(); if (sort_values.back().value.is_null()) - throw calc_error("Could not determine sorting value based an expression"); + throw_(calc_error, + "Could not determine sorting value based an expression"); } } } @@ -107,6 +109,9 @@ bool compare_items<account_t>::operator()(account_t * left, account_t * right) rxdata.add_flags(ACCOUNT_EXT_SORT_CALC); } + DEBUG("value.sort", "Comparing accounts " << left->fullname() + << " <> " << right->fullname()); + return sort_value_is_less_than(lxdata.sort_values, rxdata.sort_values); } diff --git a/src/iterators.cc b/src/iterators.cc index a01c4918..835fec9d 100644 --- a/src/iterators.cc +++ b/src/iterators.cc @@ -177,6 +177,13 @@ void sorted_accounts_iterator::sort_accounts(account_t& account, std::stable_sort(deque.begin(), deque.end(), compare_items<account_t>(sort_cmp)); + +#if defined(DEBUG_ON) + if (SHOW_DEBUG("accounts.sorted")) { + foreach (account_t * account, deque) + DEBUG("accounts.sorted", "Account: " << account->fullname()); + } +#endif } void sorted_accounts_iterator::push_all(account_t& account) diff --git a/src/value.cc b/src/value.cc index c2ae0b29..f17f2b61 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1422,13 +1422,12 @@ bool sort_value_is_less_than(const std::list<sort_value_t>& left_values, std::list<sort_value_t>::const_iterator left_iter = left_values.begin(); std::list<sort_value_t>::const_iterator right_iter = right_values.begin(); - while (left_iter != left_values.end() && - right_iter != right_values.end()) { + while (left_iter != left_values.end() && right_iter != right_values.end()) { // Don't even try to sort balance values if (! (*left_iter).value.is_balance() && ! (*right_iter).value.is_balance()) { DEBUG("value.sort", - "Comparing " << (*left_iter).value << " < " << (*right_iter).value); + " Comparing " << (*left_iter).value << " < " << (*right_iter).value); if ((*left_iter).value < (*right_iter).value) { DEBUG("value.sort", " is less"); return ! (*left_iter).inverted; |