Added argument to amount_t::value() for request a market value in terms of a

specific commodity.
This commit is contained in:
John Wiegley 2009-01-19 17:47:46 -04:00
parent 60f9748da1
commit dc91fdeff2
2 changed files with 11 additions and 8 deletions

View file

@ -663,11 +663,11 @@ amount_t& amount_t::in_place_unreduce()
return *this;
}
optional<amount_t> amount_t::value(const optional<datetime_t>& moment) const
optional<amount_t> amount_t::value(const optional<datetime_t>& moment,
const optional<commodity_t&>& in_terms_of) const
{
if (quantity) {
// jww (2008-09-21): 'none' is not the right argument here.
optional<price_point_t> point(commodity().find_price(none, moment));
optional<price_point_t> point(commodity().find_price(in_terms_of, moment));
if (point)
return (point->price * number()).round();
} else {

View file

@ -354,10 +354,11 @@ public:
* compact form greater than 1.0. That is, 3599s will unreduce to
* 59.98m, while 3601 unreduces to 1h.
*
* value(optional<datetime_t>) returns the historical value for an
* amount -- the default moment returns the most recently known
* price -- based on the price history of its commodity. For
* example, if the amount were 10 AAPL, and on Apr 10, 2000 each
* value(optional<datetime_t>, optional<commodity_t>) returns the
* historical value for an amount -- the default moment returns the
* most recently known price -- based on the price history for the
* given commodity (or determined automatically, if none is provided).
* For example, if the amount were 10 AAPL, and on Apr 10, 2000 each
* share of AAPL was worth $10, then call value() for that moment in
* time would yield the amount $100.00.
*
@ -419,7 +420,9 @@ public:
}
amount_t& in_place_unreduce();
optional<amount_t> value(const optional<datetime_t>& moment = none) const;
optional<amount_t>
value(const optional<datetime_t>& moment = none,
const optional<commodity_t&>& in_terms_of = none) const;
/**
* Truth tests. An amount may be truth test in several ways: