From c892e8c7ad0aaf6c47ff6e9075149a76188ae670 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 21 Jun 2004 04:52:43 -0400 Subject: fixes to price history support --- amount.cc | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'amount.cc') diff --git a/amount.cc b/amount.cc index d6914c39..f2e1c871 100644 --- a/amount.cc +++ b/amount.cc @@ -56,11 +56,14 @@ class gmp_amount : public amount virtual amount * copy() const; virtual amount * value(const amount *) const; - virtual amount * street(bool get_quotes) const; + virtual void set_value(const amount * val); + virtual amount * street(std::time_t * when = NULL, + bool get_quotes = false) const; + virtual bool has_price() const { return priced; } - virtual void set_value(const amount * val); + virtual amount * per_item_price() const; virtual bool is_zero() const; virtual bool is_negative() const; @@ -158,6 +161,19 @@ amount * gmp_amount::copy() const return new_amt; } +amount * gmp_amount::per_item_price() const +{ + if (! priced) + return NULL; + + gmp_amount * new_amt = new gmp_amount(); + + mpz_set(new_amt->quantity, price); + new_amt->quantity_comm = price_comm; + + return new_amt; +} + amount * gmp_amount::value(const amount * pr) const { if (pr) { @@ -199,9 +215,11 @@ amount * gmp_amount::value(const amount * pr) const } } -amount * gmp_amount::street(bool get_quotes) const +amount * gmp_amount::street(std::time_t * when, bool get_quotes) const { static std::time_t now = std::time(NULL); + if (! when) + when = &now; amount * amt = copy(); @@ -210,7 +228,7 @@ amount * gmp_amount::street(bool get_quotes) const int max = 10; while (--max >= 0) { - amount * price = amt->commdty()->price(&now, get_quotes); + amount * price = amt->commdty()->price(when, get_quotes); if (! price) break; -- cgit v1.2.3