diff options
author | John Wiegley <johnw@newartisans.com> | 2008-09-21 07:56:23 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-09-21 07:56:23 -0400 |
commit | 79a8fc5a8748ade2e15892e2eb8e199ec0939fb4 (patch) | |
tree | 66ef74f24c8eb7d3cfebc84c83918b1b6ca58da4 /src/commodity.h | |
parent | 697f6a6bce46e75fcb37c38da9f16ca2f1a8e9a3 (diff) | |
download | fork-ledger-79a8fc5a8748ade2e15892e2eb8e199ec0939fb4.tar.gz fork-ledger-79a8fc5a8748ade2e15892e2eb8e199ec0939fb4.tar.bz2 fork-ledger-79a8fc5a8748ade2e15892e2eb8e199ec0939fb4.zip |
Created several alternate 'value' methods to support the upcoming commodity
valuation changes.
Diffstat (limited to 'src/commodity.h')
-rw-r--r-- | src/commodity.h | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/commodity.h b/src/commodity.h index 06e64a7f..6b1001cd 100644 --- a/src/commodity.h +++ b/src/commodity.h @@ -201,21 +201,34 @@ public: return *base->varied_history; return none; } - optional<history_t&> history(const commodity_t& comm) const { - if (base->varied_history) { - history_by_commodity_map::iterator i = base->varied_history->find(&comm); - if (i != base->varied_history->end()) - return (*i).second; - } - return none; - } + + optional<history_t&> + history(const optional<const commodity_t&>& commodity) const; + optional<history_t&> + history(const std::vector<const commodity_t *>& commodities) const; void add_price(const datetime_t& date, const amount_t& price); bool remove_price(const datetime_t& date, const commodity_t& comm); optional<amount_t> - value(const optional<datetime_t>& moment = none, - const optional<std::vector<const commodity_t *> >& commodities = none); + value(const history_t& history, + const optional<datetime_t>& moment = none); + + optional<amount_t> + value(const optional<const commodity_t&>& commodity = none, + const optional<datetime_t>& moment = none) { + if (optional<history_t&> hist = history(commodity)) + return value(*hist, moment); + return none; + } + + optional<amount_t> + value(const std::vector<const commodity_t *>& commodities, + const optional<datetime_t>& moment = none) { + if (optional<history_t&> hist = history(commodities)) + return value(*hist, moment); + return none; + } static void exchange(commodity_t& commodity, const amount_t& per_unit_cost, |