slight cleanup
This commit is contained in:
parent
6365b8b7a8
commit
1091f0d07b
7 changed files with 37 additions and 28 deletions
|
|
@ -375,6 +375,7 @@ bool format_account::disp_subaccounts_p(const account_t * account,
|
||||||
bool matches = disp_pred(account);
|
bool matches = disp_pred(account);
|
||||||
value_t acct_total;
|
value_t acct_total;
|
||||||
bool computed = false;
|
bool computed = false;
|
||||||
|
value_t result;
|
||||||
|
|
||||||
to_show = NULL;
|
to_show = NULL;
|
||||||
|
|
||||||
|
|
@ -384,9 +385,7 @@ bool format_account::disp_subaccounts_p(const account_t * account,
|
||||||
if (! disp_pred((*i).second))
|
if (! disp_pred((*i).second))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
value_t result;
|
|
||||||
format_t::compute_total(result, details_t((*i).second));
|
format_t::compute_total(result, details_t((*i).second));
|
||||||
|
|
||||||
if (! computed) {
|
if (! computed) {
|
||||||
format_t::compute_total(acct_total, details_t(account));
|
format_t::compute_total(acct_total, details_t(account));
|
||||||
computed = true;
|
computed = true;
|
||||||
|
|
|
||||||
4
main.cc
4
main.cc
|
|
@ -19,6 +19,7 @@ using namespace ledger;
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
@ -76,7 +77,8 @@ namespace std {
|
||||||
static void
|
static void
|
||||||
regexps_to_predicate(std::list<std::string>::const_iterator begin,
|
regexps_to_predicate(std::list<std::string>::const_iterator begin,
|
||||||
std::list<std::string>::const_iterator end,
|
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)
|
const bool add_account_short_masks = false)
|
||||||
{
|
{
|
||||||
std::vector<std::string> regexps(2);
|
std::vector<std::string> regexps(2);
|
||||||
|
|
|
||||||
38
valexpr.cc
38
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,
|
void value_expr_t::compute(value_t& result, const details_t& details) const
|
||||||
value_t::type_t type) const
|
|
||||||
{
|
{
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case CONSTANT_I:
|
case CONSTANT_I:
|
||||||
|
|
@ -249,7 +248,7 @@ void value_expr_t::compute(value_t& result, const details_t& details,
|
||||||
|
|
||||||
case F_VALUE: {
|
case F_VALUE: {
|
||||||
assert(left);
|
assert(left);
|
||||||
left->compute(result, details, value_t::BALANCE);
|
left->compute(result, details);
|
||||||
|
|
||||||
std::time_t moment = now;
|
std::time_t moment = now;
|
||||||
if (right) {
|
if (right) {
|
||||||
|
|
@ -258,21 +257,33 @@ void value_expr_t::compute(value_t& result, const details_t& details,
|
||||||
if (details.entry)
|
if (details.entry)
|
||||||
moment = details.entry->date;
|
moment = details.entry->date;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CONSTANT_T:
|
case CONSTANT_T:
|
||||||
moment = right->constant_t;
|
moment = right->constant_t;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw compute_error("Invalid date passed to P(value,date)");
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case O_NOT:
|
case O_NOT:
|
||||||
left->compute(result, details, value_t::BOOLEAN);
|
left->compute(result, details);
|
||||||
result.negate();
|
result.negate();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -280,7 +291,7 @@ void value_expr_t::compute(value_t& result, const details_t& details,
|
||||||
assert(left);
|
assert(left);
|
||||||
assert(right);
|
assert(right);
|
||||||
assert(right->kind == O_COL);
|
assert(right->kind == O_COL);
|
||||||
left->compute(result, details, value_t::BOOLEAN);
|
left->compute(result, details);
|
||||||
if (result)
|
if (result)
|
||||||
right->left->compute(result, details);
|
right->left->compute(result, details);
|
||||||
else
|
else
|
||||||
|
|
@ -290,17 +301,17 @@ void value_expr_t::compute(value_t& result, const details_t& details,
|
||||||
case O_AND:
|
case O_AND:
|
||||||
assert(left);
|
assert(left);
|
||||||
assert(right);
|
assert(right);
|
||||||
left->compute(result, details, value_t::BOOLEAN);
|
left->compute(result, details);
|
||||||
if (result)
|
if (result)
|
||||||
right->compute(result, details, value_t::BOOLEAN);
|
right->compute(result, details);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_OR:
|
case O_OR:
|
||||||
assert(left);
|
assert(left);
|
||||||
assert(right);
|
assert(right);
|
||||||
left->compute(result, details, value_t::BOOLEAN);
|
left->compute(result, details);
|
||||||
if (! result)
|
if (! result)
|
||||||
right->compute(result, details, value_t::BOOLEAN);
|
right->compute(result, details);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case O_EQ:
|
case O_EQ:
|
||||||
|
|
@ -348,9 +359,6 @@ void value_expr_t::compute(value_t& result, const details_t& details,
|
||||||
assert(0);
|
assert(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type < value_t::ANY && type != result.type)
|
|
||||||
result.cast(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
value_expr_t * parse_value_term(std::istream& in);
|
value_expr_t * parse_value_term(std::istream& in);
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,7 @@ struct value_expr_t
|
||||||
if (right) delete right;
|
if (right) delete right;
|
||||||
}
|
}
|
||||||
|
|
||||||
void compute(value_t& result, const details_t& details,
|
void compute(value_t& result, const details_t& details) const;
|
||||||
value_t::type_t type = value_t::ANY) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
value_expr_t * parse_value_expr(std::istream& in);
|
value_expr_t * parse_value_expr(std::istream& in);
|
||||||
|
|
|
||||||
3
value.h
3
value.h
|
|
@ -28,8 +28,7 @@ class value_t
|
||||||
INTEGER,
|
INTEGER,
|
||||||
AMOUNT,
|
AMOUNT,
|
||||||
BALANCE,
|
BALANCE,
|
||||||
BALANCE_PAIR,
|
BALANCE_PAIR
|
||||||
ANY
|
|
||||||
} type;
|
} type;
|
||||||
|
|
||||||
value_t() {
|
value_t() {
|
||||||
|
|
|
||||||
4
walk.cc
4
walk.cc
|
|
@ -205,11 +205,11 @@ void subtotal_transactions::flush(const char * spec_fmt)
|
||||||
|
|
||||||
entry->payee = buf;
|
entry->payee = buf;
|
||||||
|
|
||||||
|
value_t result;
|
||||||
|
|
||||||
for (balances_map::iterator i = balances.begin();
|
for (balances_map::iterator i = balances.begin();
|
||||||
i != balances.end();
|
i != balances.end();
|
||||||
i++) {
|
i++) {
|
||||||
value_t result;
|
|
||||||
|
|
||||||
entry->date = finish;
|
entry->date = finish;
|
||||||
{
|
{
|
||||||
transaction_t temp((*i).first);
|
transaction_t temp((*i).first);
|
||||||
|
|
|
||||||
10
walk.h
10
walk.h
|
|
@ -39,20 +39,22 @@ struct item_handler {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct compare_items {
|
class compare_items {
|
||||||
|
value_t left_result;
|
||||||
|
value_t right_result;
|
||||||
|
|
||||||
const value_expr_t * sort_order;
|
const value_expr_t * sort_order;
|
||||||
|
|
||||||
|
public:
|
||||||
compare_items(const value_expr_t * _sort_order)
|
compare_items(const value_expr_t * _sort_order)
|
||||||
: sort_order(_sort_order) {
|
: sort_order(_sort_order) {
|
||||||
assert(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(left);
|
||||||
assert(right);
|
assert(right);
|
||||||
value_t left_result;
|
|
||||||
sort_order->compute(left_result, details_t(left));
|
sort_order->compute(left_result, details_t(left));
|
||||||
value_t right_result;
|
|
||||||
sort_order->compute(right_result, details_t(right));
|
sort_order->compute(right_result, details_t(right));
|
||||||
return left_result < right_result;
|
return left_result < right_result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue