From ee4a16743960122bf2b626f62827b7332680ebf5 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 8 May 2007 00:19:48 +0000 Subject: Corrected memory crashes when running the register command. --- src/balance.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/balance.h') diff --git a/src/balance.h b/src/balance.h index 614bffc7..627c3ac6 100644 --- a/src/balance.h +++ b/src/balance.h @@ -111,6 +111,14 @@ public: *this += (*i).second; return *this; } + balance_t& operator+=(const amount_t& amt) { + amounts_map::iterator i = amounts.find(&amt.commodity()); + if (i != amounts.end()) + (*i).second += amt; + else if (! amt.is_realzero()) + amounts.insert(amounts_map::value_type(&amt.commodity(), amt)); + return *this; + } balance_t& operator-=(const balance_t& bal) { for (amounts_map::const_iterator i = bal.amounts.begin(); i != bal.amounts.end(); @@ -118,6 +126,18 @@ public: *this -= (*i).second; return *this; } + balance_t& operator-=(const amount_t& amt) { + amounts_map::iterator i = amounts.find(&amt.commodity()); + if (i != amounts.end()) { + (*i).second -= amt; + if ((*i).second.is_realzero()) + amounts.erase(i); + } + else if (! amt.is_realzero()) { + amounts.insert(amounts_map::value_type(&amt.commodity(), - amt)); + } + return *this; + } balance_t& operator*=(const amount_t& amt); balance_t& operator/=(const amount_t& amt); -- cgit v1.2.3