diff options
author | John Wiegley <johnw@newartisans.com> | 2007-05-08 00:19:48 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:38:40 -0400 |
commit | ee4a16743960122bf2b626f62827b7332680ebf5 (patch) | |
tree | dab8682d742718a86f0529dd86a0c832ffeb0102 /src/balance.h | |
parent | 30978b7fe5ee93413b2e05b54942f6550832b222 (diff) | |
download | fork-ledger-ee4a16743960122bf2b626f62827b7332680ebf5.tar.gz fork-ledger-ee4a16743960122bf2b626f62827b7332680ebf5.tar.bz2 fork-ledger-ee4a16743960122bf2b626f62827b7332680ebf5.zip |
Corrected memory crashes when running the register command.
Diffstat (limited to 'src/balance.h')
-rw-r--r-- | src/balance.h | 20 |
1 files changed, 20 insertions, 0 deletions
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); |