summaryrefslogtreecommitdiff
path: root/src/compare.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-10-26 18:52:26 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-10-26 18:52:26 -0400
commit151a8d87ee299b54da262346471aa71a729a6eb2 (patch)
treee2151c34eb1a2756e5e4324465ebf629ef4859e6 /src/compare.cc
parentd85a415bc5119d4271ca7355fe3e0ce3951c0d23 (diff)
downloadfork-ledger-151a8d87ee299b54da262346471aa71a729a6eb2.tar.gz
fork-ledger-151a8d87ee299b54da262346471aa71a729a6eb2.tar.bz2
fork-ledger-151a8d87ee299b54da262346471aa71a729a6eb2.zip
Fixed sorting in bal reports when --flat is used
Note that sorting on the "total" is not the same thing as sorting on the "display_total" when multiple commodities are in use and the -X flag is selected! One should always sort on display_total, since that's the value which is shown in the report. 'T' is a synonym for display_total.
Diffstat (limited to 'src/compare.cc')
-rw-r--r--src/compare.cc60
1 files changed, 27 insertions, 33 deletions
diff --git a/src/compare.cc b/src/compare.cc
index cca22691..65e6a1e3 100644
--- a/src/compare.cc
+++ b/src/compare.cc
@@ -38,41 +38,31 @@
namespace ledger {
-namespace {
- template <typename T>
- void push_sort_value(std::list<sort_value_t>& sort_values,
- expr_t::ptr_op_t node, T * scope)
- {
- if (node->kind == expr_t::op_t::O_CONS) {
- push_sort_value(sort_values, node->left(), scope);
- push_sort_value(sort_values, node->right(), scope);
- }
- else {
- bool inverted = false;
+void push_sort_value(std::list<sort_value_t>& sort_values,
+ expr_t::ptr_op_t node, scope_t& scope)
+{
+ if (node->kind == expr_t::op_t::O_CONS) {
+ push_sort_value(sort_values, node->left(), scope);
+ push_sort_value(sort_values, node->right(), scope);
+ }
+ else {
+ bool inverted = false;
- if (node->kind == expr_t::op_t::O_NEG) {
- inverted = true;
- node = node->left();
- }
+ if (node->kind == expr_t::op_t::O_NEG) {
+ inverted = true;
+ node = node->left();
+ }
- sort_values.push_back(sort_value_t());
- sort_values.back().inverted = inverted;
- sort_values.back().value = expr_t(node).calc(*scope).simplified();
+ sort_values.push_back(sort_value_t());
+ sort_values.back().inverted = inverted;
+ sort_values.back().value = expr_t(node).calc(scope).simplified();
- if (sort_values.back().value.is_null())
- throw_(calc_error,
- _("Could not determine sorting value based an expression"));
- }
+ if (sort_values.back().value.is_null())
+ throw_(calc_error,
+ _("Could not determine sorting value based an expression"));
}
}
-template <typename T>
-void compare_items<T>::find_sort_values(std::list<sort_value_t>& sort_values,
- T * scope)
-{
- push_sort_value(sort_values, sort_order.get_op(), scope);
-}
-
template <>
bool compare_items<post_t>::operator()(post_t * left, post_t * right)
{
@@ -81,13 +71,15 @@ bool compare_items<post_t>::operator()(post_t * left, post_t * right)
post_t::xdata_t& lxdata(left->xdata());
if (! lxdata.has_flags(POST_EXT_SORT_CALC)) {
- find_sort_values(lxdata.sort_values, left);
+ bind_scope_t bound_scope(*sort_order.get_context(), *left);
+ find_sort_values(lxdata.sort_values, bound_scope);
lxdata.add_flags(POST_EXT_SORT_CALC);
}
post_t::xdata_t& rxdata(right->xdata());
if (! rxdata.has_flags(POST_EXT_SORT_CALC)) {
- find_sort_values(rxdata.sort_values, right);
+ bind_scope_t bound_scope(*sort_order.get_context(), *right);
+ find_sort_values(rxdata.sort_values, bound_scope);
rxdata.add_flags(POST_EXT_SORT_CALC);
}
@@ -102,13 +94,15 @@ bool compare_items<account_t>::operator()(account_t * left, account_t * right)
account_t::xdata_t& lxdata(left->xdata());
if (! lxdata.has_flags(ACCOUNT_EXT_SORT_CALC)) {
- find_sort_values(lxdata.sort_values, left);
+ bind_scope_t bound_scope(*sort_order.get_context(), *left);
+ find_sort_values(lxdata.sort_values, bound_scope);
lxdata.add_flags(ACCOUNT_EXT_SORT_CALC);
}
account_t::xdata_t& rxdata(right->xdata());
if (! rxdata.has_flags(ACCOUNT_EXT_SORT_CALC)) {
- find_sort_values(rxdata.sort_values, right);
+ bind_scope_t bound_scope(*sort_order.get_context(), *right);
+ find_sort_values(rxdata.sort_values, bound_scope);
rxdata.add_flags(ACCOUNT_EXT_SORT_CALC);
}