From c59018c29ddfc7a46aeb951fbcd5cb5b93f47ec0 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 3 May 2007 06:11:04 +0000 Subject: Revised how commodities are dealt with. --- src/balance.h | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src/balance.h') diff --git a/src/balance.h b/src/balance.h index 38693bda..62f9ba86 100644 --- a/src/balance.h +++ b/src/balance.h @@ -93,15 +93,19 @@ public: bool operator<(const balance_t& bal) const { for (amounts_map::const_iterator i = bal.amounts.begin(); i != bal.amounts.end(); - i++) - if (! (amount(*(*i).first) < (*i).second)) + i++) { + optional amt = amount(*(*i).first); + if (amt && ! (*amt < (*i).second)) return false; + } for (amounts_map::const_iterator i = amounts.begin(); i != amounts.end(); - i++) - if (! ((*i).second < bal.amount(*(*i).first))) + i++) { + optional amt = bal.amount(*(*i).first); + if (amt && ! ((*i).second < *amt)) return false; + } if (bal.amounts.size() == 0 && amounts.size() == 0) return false; @@ -146,13 +150,10 @@ public: return true; } - amount_t amount(const commodity_t& commodity = - *commodity_t::null_commodity) const; - balance_t value(const moment_t& moment = now) const; - - optional price() const; - optional date() const; - optional tag() const; + optional amount(const optional& commodity = + optional()) const; + optional value(const optional& moment = + optional()) const; balance_t strip_annotations(const bool keep_price = amount_t::keep_price, @@ -335,24 +336,15 @@ public: return temp; } - amount_t amount(const commodity_t& commodity = - *commodity_t::null_commodity) const { + optional amount(const optional& commodity = + optional()) const { return quantity.amount(commodity); } - balance_t value(const moment_t& moment = now) const { + optional value(const optional& moment = + optional()) const { return quantity.value(moment); } - optional price() const { - return quantity.price(); - } - optional date() const { - return quantity.date(); - } - optional tag() const { - return quantity.tag(); - } - balance_t strip_annotations(const bool keep_price = amount_t::keep_price, const bool keep_date = amount_t::keep_date, -- cgit v1.2.3