diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-04 05:22:30 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-05 05:03:52 -0600 |
commit | 5d8cb30774cf630cddd26407202c1cad8568bbef (patch) | |
tree | c97ae3166261d9a0feb78144d380d8cc78f743dd /src/history.h | |
parent | e9108783122ae4d775046ced646b14552f1e184d (diff) | |
download | fork-ledger-5d8cb30774cf630cddd26407202c1cad8568bbef.tar.gz fork-ledger-5d8cb30774cf630cddd26407202c1cad8568bbef.tar.bz2 fork-ledger-5d8cb30774cf630cddd26407202c1cad8568bbef.zip |
Implemented first cut at price conversion logic
Diffstat (limited to 'src/history.h')
-rw-r--r-- | src/history.h | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/history.h b/src/history.h index f94d12c3..70831445 100644 --- a/src/history.h +++ b/src/history.h @@ -83,18 +83,20 @@ public: reftime(_reftime), oldest(_oldest) { } template <typename Edge> - bool operator()(const Edge& e) const { + bool operator()(const Edge& e) const + { const price_map_t& prices(get(ratios, e)); + if (prices.empty()) + return false; + price_map_t::const_iterator low = prices.upper_bound(reftime); - if (prices.empty() || - (low != prices.end() && low == prices.begin())) { + if (low != prices.end() && low == prices.begin()) { return false; } else { - if (low == prices.end()) - --low; + --low; assert(((*low).first <= reftime)); - if (oldest && (*low).first <= *oldest) + if (oldest && (*low).first < *oldest) return false; long secs = (reftime - (*low).first).total_seconds(); @@ -175,8 +177,16 @@ public: optional<price_point_t> find_price(const commodity_t& source, const datetime_t& moment, - const optional<datetime_t>& oldest = none, - const optional<commodity_t&>& commodity = none); + const optional<datetime_t>& oldest = none); + + optional<price_point_t> + find_price(const commodity_t& source, + const commodity_t& target, + const datetime_t& moment, + const optional<datetime_t>& oldest = none); + + void print_map(std::ostream& out, + const optional<datetime_t>& moment = none); }; } // namespace ledger |