diff options
author | John Wiegley <johnw@newartisans.com> | 2004-08-23 02:11:58 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-08-23 02:11:58 -0400 |
commit | 1091f0d07b8fae388202a449239e8de321545a2a (patch) | |
tree | c96ec5bc1d63f80b31284c502094db969720f741 | |
parent | 6365b8b7a807351209330ba65b05e612c5901908 (diff) | |
download | fork-ledger-1091f0d07b8fae388202a449239e8de321545a2a.tar.gz fork-ledger-1091f0d07b8fae388202a449239e8de321545a2a.tar.bz2 fork-ledger-1091f0d07b8fae388202a449239e8de321545a2a.zip |
slight cleanup
-rw-r--r-- | format.cc | 3 | ||||
-rw-r--r-- | main.cc | 4 | ||||
-rw-r--r-- | valexpr.cc | 38 | ||||
-rw-r--r-- | valexpr.h | 3 | ||||
-rw-r--r-- | value.h | 3 | ||||
-rw-r--r-- | walk.cc | 4 | ||||
-rw-r--r-- | walk.h | 10 |
7 files changed, 37 insertions, 28 deletions
@@ -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; @@ -19,6 +19,7 @@ using namespace ledger; #include <iostream> #include <fstream> +#include <sstream> #include <memory> #include <algorithm> #include <iterator> @@ -76,7 +77,8 @@ namespace std { static void regexps_to_predicate(std::list<std::string>::const_iterator begin, std::list<std::string>::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<std::string> regexps(2); @@ -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); @@ -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); @@ -28,8 +28,7 @@ class value_t INTEGER, AMOUNT, BALANCE, - BALANCE_PAIR, - ANY + BALANCE_PAIR } type; value_t() { @@ -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); @@ -39,20 +39,22 @@ struct item_handler { }; template <typename T> -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; } |