From 1091f0d07b8fae388202a449239e8de321545a2a Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 23 Aug 2004 02:11:58 -0400 Subject: slight cleanup --- format.cc | 3 +-- main.cc | 4 +++- valexpr.cc | 38 +++++++++++++++++++++++--------------- valexpr.h | 3 +-- value.h | 3 +-- walk.cc | 4 ++-- walk.h | 10 ++++++---- 7 files changed, 37 insertions(+), 28 deletions(-) diff --git a/format.cc b/format.cc index 9af56929..add2151d 100644 --- a/format.cc +++ b/format.cc @@ -375,6 +375,7 @@ bool format_account::disp_subaccounts_p(const account_t * account, bool matches = disp_pred(account); value_t acct_total; bool computed = false; + value_t result; to_show = NULL; @@ -384,9 +385,7 @@ bool format_account::disp_subaccounts_p(const account_t * account, if (! disp_pred((*i).second)) continue; - value_t result; format_t::compute_total(result, details_t((*i).second)); - if (! computed) { format_t::compute_total(acct_total, details_t(account)); computed = true; diff --git a/main.cc b/main.cc index 2bb58da3..30316bb8 100644 --- a/main.cc +++ b/main.cc @@ -19,6 +19,7 @@ using namespace ledger; #include #include +#include #include #include #include @@ -76,7 +77,8 @@ namespace std { static void regexps_to_predicate(std::list::const_iterator begin, std::list::const_iterator end, - config_t * config, const bool account_regexp = false, + config_t * config, + const bool account_regexp = false, const bool add_account_short_masks = false) { std::vector regexps(2); diff --git a/valexpr.cc b/valexpr.cc index 4c520419..64a0a0f9 100644 --- a/valexpr.cc +++ b/valexpr.cc @@ -66,8 +66,7 @@ bool mask_t::match(const std::string& str) const } -void value_expr_t::compute(value_t& result, const details_t& details, - value_t::type_t type) const +void value_expr_t::compute(value_t& result, const details_t& details) const { switch (kind) { case CONSTANT_I: @@ -249,7 +248,7 @@ void value_expr_t::compute(value_t& result, const details_t& details, case F_VALUE: { assert(left); - left->compute(result, details, value_t::BALANCE); + left->compute(result, details); std::time_t moment = now; if (right) { @@ -258,21 +257,33 @@ void value_expr_t::compute(value_t& result, const details_t& details, if (details.entry) moment = details.entry->date; break; - case CONSTANT_T: moment = right->constant_t; break; - default: throw compute_error("Invalid date passed to P(value,date)"); } } - result = (*((balance_t *)result.data)).value(moment); + + switch (result.type) { + case value_t::BOOLEAN: + case value_t::INTEGER: + break; + case value_t::AMOUNT: + result = ((amount_t *)result.data)->value(moment); + break; + case value_t::BALANCE: + result = ((balance_t *)result.data)->value(moment); + break; + case value_t::BALANCE_PAIR: + result = ((balance_pair_t *)result.data)->quantity.value(moment); + break; + } break; } case O_NOT: - left->compute(result, details, value_t::BOOLEAN); + left->compute(result, details); result.negate(); break; @@ -280,7 +291,7 @@ void value_expr_t::compute(value_t& result, const details_t& details, assert(left); assert(right); assert(right->kind == O_COL); - left->compute(result, details, value_t::BOOLEAN); + left->compute(result, details); if (result) right->left->compute(result, details); else @@ -290,17 +301,17 @@ void value_expr_t::compute(value_t& result, const details_t& details, case O_AND: assert(left); assert(right); - left->compute(result, details, value_t::BOOLEAN); + left->compute(result, details); if (result) - right->compute(result, details, value_t::BOOLEAN); + right->compute(result, details); break; case O_OR: assert(left); assert(right); - left->compute(result, details, value_t::BOOLEAN); + left->compute(result, details); if (! result) - right->compute(result, details, value_t::BOOLEAN); + right->compute(result, details); break; case O_EQ: @@ -348,9 +359,6 @@ void value_expr_t::compute(value_t& result, const details_t& details, assert(0); break; } - - if (type < value_t::ANY && type != result.type) - result.cast(type); } value_expr_t * parse_value_term(std::istream& in); diff --git a/valexpr.h b/valexpr.h index 4c7f503e..f5be229b 100644 --- a/valexpr.h +++ b/valexpr.h @@ -126,8 +126,7 @@ struct value_expr_t if (right) delete right; } - void compute(value_t& result, const details_t& details, - value_t::type_t type = value_t::ANY) const; + void compute(value_t& result, const details_t& details) const; }; value_expr_t * parse_value_expr(std::istream& in); diff --git a/value.h b/value.h index 11ac2481..e2fbda66 100644 --- a/value.h +++ b/value.h @@ -28,8 +28,7 @@ class value_t INTEGER, AMOUNT, BALANCE, - BALANCE_PAIR, - ANY + BALANCE_PAIR } type; value_t() { diff --git a/walk.cc b/walk.cc index 87680a79..6f4656c5 100644 --- a/walk.cc +++ b/walk.cc @@ -205,11 +205,11 @@ void subtotal_transactions::flush(const char * spec_fmt) entry->payee = buf; + value_t result; + for (balances_map::iterator i = balances.begin(); i != balances.end(); i++) { - value_t result; - entry->date = finish; { transaction_t temp((*i).first); diff --git a/walk.h b/walk.h index a456bd82..0e7d2e5e 100644 --- a/walk.h +++ b/walk.h @@ -39,20 +39,22 @@ struct item_handler { }; template -struct compare_items { +class compare_items { + value_t left_result; + value_t right_result; + const value_expr_t * sort_order; + public: compare_items(const value_expr_t * _sort_order) : sort_order(_sort_order) { assert(sort_order); } - bool operator()(const T * left, const T * right) const { + bool operator()(const T * left, const T * right) { assert(left); assert(right); - value_t left_result; sort_order->compute(left_result, details_t(left)); - value_t right_result; sort_order->compute(right_result, details_t(right)); return left_result < right_result; } -- cgit v1.2.3