summaryrefslogtreecommitdiff
path: root/value.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2006-03-04 14:46:04 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 05:48:44 -0400
commit581b3d5b9a3eebdd8f396d910386cadd9426b915 (patch)
treec7493496010c811cf276a1e68d7c10bc87e7abbd /value.h
parent6375730fc9af02c27ec774aa2b9929095f5ffbde (diff)
downloadledger-581b3d5b9a3eebdd8f396d910386cadd9426b915.tar.gz
ledger-581b3d5b9a3eebdd8f396d910386cadd9426b915.tar.bz2
ledger-581b3d5b9a3eebdd8f396d910386cadd9426b915.zip
*** no comment ***
Diffstat (limited to 'value.h')
-rw-r--r--value.h57
1 files changed, 30 insertions, 27 deletions
diff --git a/value.h b/value.h
index fc1517ed..59752dec 100644
--- a/value.h
+++ b/value.h
@@ -121,40 +121,43 @@ class value_t
return *this = amount_t(value);
}
value_t& operator=(const amount_t& value) {
- if ((amount_t *) data != &value) {
- if (! value) {
- return *this = 0L;
- } else {
- destroy();
- new((amount_t *)data) amount_t(value);
- type = AMOUNT;
- }
- }
+ if (type == AMOUNT &&
+ (amount_t *) data == &value)
+ return *this;
+
+ destroy();
+ new((amount_t *)data) amount_t(value);
+ type = AMOUNT;
+
return *this;
}
value_t& operator=(const balance_t& value) {
- if ((balance_t *) data != &value) {
- if (value.amounts.size() == 1) {
- return *this = (*value.amounts.begin()).second;
- } else {
- destroy();
- new((balance_t *)data) balance_t(value);
- type = BALANCE;
- }
+ if (type == BALANCE &&
+ (balance_t *) data == &value)
+ return *this;
+
+ if (value.amounts.size() == 1) {
+ return *this = (*value.amounts.begin()).second;
+ } else {
+ destroy();
+ new((balance_t *)data) balance_t(value);
+ type = BALANCE;
+ return *this;
}
- return *this;
}
value_t& operator=(const balance_pair_t& value) {
- if ((balance_pair_t *) data != &value) {
- if (! value.cost) {
- return *this = value.quantity;
- } else {
- destroy();
- new((balance_pair_t *)data) balance_pair_t(value);
- type = BALANCE_PAIR;
- }
+ if (type == BALANCE_PAIR &&
+ (balance_pair_t *) data == &value)
+ return *this;
+
+ if (! value.cost) {
+ return *this = value.quantity;
+ } else {
+ destroy();
+ new((balance_pair_t *)data) balance_pair_t(value);
+ type = BALANCE_PAIR;
+ return *this;
}
- return *this;
}
value_t& operator+=(const value_t& value);