diff options
author | John Wiegley <johnw@newartisans.com> | 2004-06-21 04:52:43 -0400 |
---|---|---|
committer | johnw <johnw@newartisans.com> | 2004-06-21 04:52:43 -0400 |
commit | c892e8c7ad0aaf6c47ff6e9075149a76188ae670 (patch) | |
tree | c21e7f6145722e430439b00785ebe63f609823bd /amount.cc | |
parent | 39ee2ae3d846b4bffa4e42ba4f3a9bc320ca9270 (diff) | |
download | fork-ledger-c892e8c7ad0aaf6c47ff6e9075149a76188ae670.tar.gz fork-ledger-c892e8c7ad0aaf6c47ff6e9075149a76188ae670.tar.bz2 fork-ledger-c892e8c7ad0aaf6c47ff6e9075149a76188ae670.zip |
fixes to price history support
Diffstat (limited to 'amount.cc')
-rw-r--r-- | amount.cc | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -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; |