summaryrefslogtreecommitdiff
path: root/src/balance.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-05-08 00:19:48 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:40 -0400
commitee4a16743960122bf2b626f62827b7332680ebf5 (patch)
treedab8682d742718a86f0529dd86a0c832ffeb0102 /src/balance.h
parent30978b7fe5ee93413b2e05b54942f6550832b222 (diff)
downloadfork-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.h20
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);