Added methods for getting the cost of an xact.

This commit is contained in:
John Wiegley 2009-01-19 22:23:45 -04:00
parent 091144e5e8
commit 14b3eb89f5

View file

@ -84,6 +84,29 @@ namespace {
}
}
value_t get_cost(xact_t& xact) {
if (xact.has_xdata() &&
xact.xdata().has_flags(XACT_EXT_COMPOUND)) {
return xact.xdata().value.cost();
} else {
if (xact.cost)
return *xact.cost;
else
return xact.amount;
}
}
#if 0
value_t get_price(xact_t& xact) {
if (xact.has_xdata() &&
xact.xdata().has_flags(XACT_EXT_COMPOUND)) {
return xact.xdata().value;
} else {
return xact.amount;
}
}
#endif
value_t get_total(xact_t& xact) {
if (xact.xdata_)
return xact.xdata_->total;
@ -91,8 +114,13 @@ namespace {
return xact.amount;
}
value_t get_cost(xact_t& xact) {
return xact.cost ? *xact.cost : xact.amount;
value_t get_total_cost(xact_t& xact) {
if (xact.xdata_)
return xact.xdata_->total.cost();
else if (xact.cost)
return *xact.cost;
else
return xact.amount;
}
value_t get_account(call_scope_t& scope)
@ -140,16 +168,24 @@ expr_t::ptr_op_t xact_t::lookup(const string& name)
case 'c':
if (name == "code")
return WRAP_FUNCTOR(get_wrapper<&get_code>);
else if (name == "cost")
return WRAP_FUNCTOR(get_wrapper<&get_cost>);
break;
case 'p':
if (name == "payee")
return WRAP_FUNCTOR(get_wrapper<&get_payee>);
#if 0
else if (name == "price")
return WRAP_FUNCTOR(get_wrapper<&get_price>);
#endif
break;
case 't':
if (name[1] == '\0' || name == "total")
return WRAP_FUNCTOR(get_wrapper<&get_total>);
else if (name == "total_cost")
return WRAP_FUNCTOR(get_wrapper<&get_total_cost>);
break;
}