*** no comment ***
This commit is contained in:
parent
6375730fc9
commit
581b3d5b9a
3 changed files with 33 additions and 65 deletions
13
balance.h
13
balance.h
|
|
@ -97,14 +97,10 @@ class balance_t
|
||||||
}
|
}
|
||||||
balance_t& operator-=(const amount_t& amt) {
|
balance_t& operator-=(const amount_t& amt) {
|
||||||
amounts_map::iterator i = amounts.find(&amt.commodity());
|
amounts_map::iterator i = amounts.find(&amt.commodity());
|
||||||
if (i != amounts.end()) {
|
if (i != amounts.end())
|
||||||
(*i).second -= amt;
|
(*i).second -= amt;
|
||||||
if (! (*i).second)
|
else
|
||||||
amounts.erase(&amt.commodity());
|
|
||||||
}
|
|
||||||
else if (amt) {
|
|
||||||
amounts.insert(amounts_pair(&amt.commodity(), - amt));
|
amounts.insert(amounts_pair(&amt.commodity(), - amt));
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
@ -151,10 +147,7 @@ class balance_t
|
||||||
balance_t& operator*=(const amount_t& amt) {
|
balance_t& operator*=(const amount_t& amt) {
|
||||||
// Multiplying by the null commodity causes all amounts to be
|
// Multiplying by the null commodity causes all amounts to be
|
||||||
// increased by the same factor.
|
// increased by the same factor.
|
||||||
if (! amt) {
|
if (! amt.commodity()) {
|
||||||
amounts.clear();
|
|
||||||
}
|
|
||||||
else if (! amt.commodity()) {
|
|
||||||
for (amounts_map::iterator i = amounts.begin();
|
for (amounts_map::iterator i = amounts.begin();
|
||||||
i != amounts.end();
|
i != amounts.end();
|
||||||
i++)
|
i++)
|
||||||
|
|
|
||||||
28
value.cc
28
value.cc
|
|
@ -19,27 +19,6 @@ void value_t::destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void value_t::simplify()
|
|
||||||
{
|
|
||||||
if (! *this) {
|
|
||||||
*this = 0L;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == BALANCE_PAIR &&
|
|
||||||
(! ((balance_pair_t *) data)->cost ||
|
|
||||||
! *((balance_pair_t *) data)->cost))
|
|
||||||
cast(BALANCE);
|
|
||||||
|
|
||||||
if (type == BALANCE &&
|
|
||||||
((balance_t *) data)->amounts.size() == 1)
|
|
||||||
cast(AMOUNT);
|
|
||||||
|
|
||||||
if (type == AMOUNT &&
|
|
||||||
! ((amount_t *) data)->commodity())
|
|
||||||
cast(INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
value_t& value_t::operator=(const value_t& value)
|
value_t& value_t::operator=(const value_t& value)
|
||||||
{
|
{
|
||||||
if (this == &value)
|
if (this == &value)
|
||||||
|
|
@ -336,18 +315,11 @@ value_t& value_t::operator-=(const value_t& value)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
simplify();
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
value_t& value_t::operator*=(const value_t& value)
|
value_t& value_t::operator*=(const value_t& value)
|
||||||
{
|
{
|
||||||
if (! value) {
|
|
||||||
*this = 0L;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
|
|
|
||||||
27
value.h
27
value.h
|
|
@ -121,41 +121,44 @@ class value_t
|
||||||
return *this = amount_t(value);
|
return *this = amount_t(value);
|
||||||
}
|
}
|
||||||
value_t& operator=(const amount_t& value) {
|
value_t& operator=(const amount_t& value) {
|
||||||
if ((amount_t *) data != &value) {
|
if (type == AMOUNT &&
|
||||||
if (! value) {
|
(amount_t *) data == &value)
|
||||||
return *this = 0L;
|
return *this;
|
||||||
} else {
|
|
||||||
destroy();
|
destroy();
|
||||||
new((amount_t *)data) amount_t(value);
|
new((amount_t *)data) amount_t(value);
|
||||||
type = AMOUNT;
|
type = AMOUNT;
|
||||||
}
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
value_t& operator=(const balance_t& value) {
|
value_t& operator=(const balance_t& value) {
|
||||||
if ((balance_t *) data != &value) {
|
if (type == BALANCE &&
|
||||||
|
(balance_t *) data == &value)
|
||||||
|
return *this;
|
||||||
|
|
||||||
if (value.amounts.size() == 1) {
|
if (value.amounts.size() == 1) {
|
||||||
return *this = (*value.amounts.begin()).second;
|
return *this = (*value.amounts.begin()).second;
|
||||||
} else {
|
} else {
|
||||||
destroy();
|
destroy();
|
||||||
new((balance_t *)data) balance_t(value);
|
new((balance_t *)data) balance_t(value);
|
||||||
type = BALANCE;
|
type = BALANCE;
|
||||||
}
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
value_t& operator=(const balance_pair_t& value) {
|
value_t& operator=(const balance_pair_t& value) {
|
||||||
if ((balance_pair_t *) data != &value) {
|
if (type == BALANCE_PAIR &&
|
||||||
|
(balance_pair_t *) data == &value)
|
||||||
|
return *this;
|
||||||
|
|
||||||
if (! value.cost) {
|
if (! value.cost) {
|
||||||
return *this = value.quantity;
|
return *this = value.quantity;
|
||||||
} else {
|
} else {
|
||||||
destroy();
|
destroy();
|
||||||
new((balance_pair_t *)data) balance_pair_t(value);
|
new((balance_pair_t *)data) balance_pair_t(value);
|
||||||
type = BALANCE_PAIR;
|
type = BALANCE_PAIR;
|
||||||
}
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
value_t& operator+=(const value_t& value);
|
value_t& operator+=(const value_t& value);
|
||||||
value_t& operator-=(const value_t& value);
|
value_t& operator-=(const value_t& value);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue