From de6de07bac1337b0dd87b41c853369dc8432c2af Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 22 Feb 2009 22:22:07 -0400 Subject: Many fixes to --market and --exchange Also, --exchange now accepted multiple, comma-separated commodities. --- src/amount.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/amount.cc') diff --git a/src/amount.cc b/src/amount.cc index 84e77f41..dde1f96c 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -515,12 +515,25 @@ amount_t::value(const bool primary_only, const optional& in_terms_of) const { if (quantity) { +#if defined(DEBUG_ON) + DEBUG("commodity.prices.find", + "amount_t::value of " << commodity().symbol()); + if (moment) + DEBUG("commodity.prices.find", + "amount_t::value: moment = " << *moment); + if (in_terms_of) + DEBUG("commodity.prices.find", + "amount_t::value: in_terms_of = " << in_terms_of->symbol()); +#endif if (has_commodity() && - (! primary_only || commodity().has_flags(COMMODITY_PRIMARY)) && - (! in_terms_of || commodity() != *in_terms_of)) { - optional point(commodity().find_price(in_terms_of, moment)); - if (point) + (! primary_only || ! commodity().has_flags(COMMODITY_PRIMARY))) { + if (in_terms_of && commodity() == *in_terms_of) { + return *this; + } + else if (optional point = + commodity().find_price(in_terms_of, moment)) { return (point->price * number()).rounded(); + } } } else { throw_(amount_error, "Cannot determine value of an uninitialized amount"); @@ -996,7 +1009,7 @@ void amount_t::print(std::ostream& _out) const if (comm.annotated) { annotated_commodity_t& ann(static_cast(comm)); - assert(&*ann.details.price != this); + assert(! ann.details.price || &*ann.details.price != this); ann.write_annotations(out); } -- cgit v1.2.3