slight cleanup

This commit is contained in:
John Wiegley 2004-08-23 02:11:58 -04:00
parent 6365b8b7a8
commit 1091f0d07b
7 changed files with 37 additions and 28 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -28,8 +28,7 @@ class value_t
INTEGER,
AMOUNT,
BALANCE,
BALANCE_PAIR,
ANY
BALANCE_PAIR
} type;
value_t() {

View file

@ -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);

10
walk.h
View file

@ -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;
}