summaryrefslogtreecommitdiff
path: root/balance.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2006-03-04 14:17:26 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 05:48:44 -0400
commit6375730fc9af02c27ec774aa2b9929095f5ffbde (patch)
tree9f27f3ba154fd462d237f7eba670c9f87d703704 /balance.h
parent2034d6640c5ba7465cadda5da0060b55c7277d22 (diff)
downloadfork-ledger-6375730fc9af02c27ec774aa2b9929095f5ffbde.tar.gz
fork-ledger-6375730fc9af02c27ec774aa2b9929095f5ffbde.tar.bz2
fork-ledger-6375730fc9af02c27ec774aa2b9929095f5ffbde.zip
*** no comment ***
Diffstat (limited to 'balance.h')
-rw-r--r--balance.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/balance.h b/balance.h
index 83cf66b1..8f953fd5 100644
--- a/balance.h
+++ b/balance.h
@@ -97,10 +97,14 @@ class balance_t
}
balance_t& operator-=(const amount_t& amt) {
amounts_map::iterator i = amounts.find(&amt.commodity());
- if (i != amounts.end())
+ if (i != amounts.end()) {
(*i).second -= amt;
- else if (amt)
+ if (! (*i).second)
+ amounts.erase(&amt.commodity());
+ }
+ else if (amt) {
amounts.insert(amounts_pair(&amt.commodity(), - amt));
+ }
return *this;
}
template <typename T>
@@ -147,7 +151,10 @@ class balance_t
balance_t& operator*=(const amount_t& amt) {
// Multiplying by the null commodity causes all amounts to be
// increased by the same factor.
- if (amt.commodity().symbol.empty()) {
+ if (! amt) {
+ amounts.clear();
+ }
+ else if (! amt.commodity()) {
for (amounts_map::iterator i = amounts.begin();
i != amounts.end();
i++)
@@ -172,7 +179,7 @@ class balance_t
balance_t& operator/=(const amount_t& amt) {
// Dividing by the null commodity causes all amounts to be
// increased by the same factor.
- if (amt.commodity().symbol.empty()) {
+ if (! amt.commodity()) {
for (amounts_map::iterator i = amounts.begin();
i != amounts.end();
i++)