*** empty log message ***
This commit is contained in:
parent
f741c1b62e
commit
2930b89ea3
3 changed files with 34 additions and 29 deletions
21
balance.cc
21
balance.cc
|
|
@ -166,7 +166,26 @@ balance_pair_t& balance_pair_t::operator/=(const balance_pair_t& bal_pair)
|
|||
*cost /= bal_pair.cost ? *bal_pair.cost : bal_pair.quantity;
|
||||
|
||||
if (bal_pair.price && *bal_pair.price && price)
|
||||
*price /= *bal_pair.price;
|
||||
*price /= *bal_pair.price;
|
||||
return *this;
|
||||
}
|
||||
|
||||
balance_pair_t& balance_pair_t::add(const amount_t& amount,
|
||||
const amount_t * a_price,
|
||||
const amount_t * a_cost)
|
||||
{
|
||||
if (a_cost && ! cost)
|
||||
cost = new balance_t(quantity);
|
||||
quantity += amount;
|
||||
if (cost)
|
||||
*cost += a_cost ? *a_cost : amount;
|
||||
|
||||
if (a_price) {
|
||||
if (! price)
|
||||
price = new balance_t(*a_price);
|
||||
else
|
||||
*price += *a_price;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
29
balance.h
29
balance.h
|
|
@ -541,7 +541,7 @@ class balance_pair_t
|
|||
if (! price)
|
||||
price = new balance_t(*bal_pair.price);
|
||||
else
|
||||
price += *bal_pair.price;
|
||||
*price += *bal_pair.price;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -574,7 +574,7 @@ class balance_pair_t
|
|||
price = new balance_t(*bal_pair.price);
|
||||
price->negate();
|
||||
} else {
|
||||
price -= *bal_pair.price;
|
||||
*price -= *bal_pair.price;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
|
|
@ -827,7 +827,7 @@ class balance_pair_t
|
|||
void negate() {
|
||||
quantity.negate();
|
||||
if (price) price->negate();
|
||||
if (cost) cost->negate();
|
||||
if (cost) cost->negate();
|
||||
}
|
||||
balance_pair_t negated() const {
|
||||
balance_pair_t temp = *this;
|
||||
|
|
@ -852,7 +852,7 @@ class balance_pair_t
|
|||
void abs() {
|
||||
quantity.abs();
|
||||
if (price) price->abs();
|
||||
if (cost) cost->abs();
|
||||
if (cost) cost->abs();
|
||||
}
|
||||
|
||||
amount_t amount(const commodity_t& commodity) const {
|
||||
|
|
@ -861,29 +861,14 @@ class balance_pair_t
|
|||
balance_t value(const std::time_t moment) const {
|
||||
return quantity.value(moment);
|
||||
}
|
||||
void write(std::ostream& out,
|
||||
const int first_width,
|
||||
const int latter_width = -1) const {
|
||||
void write(std::ostream& out, const int first_width,
|
||||
const int latter_width = -1) const {
|
||||
quantity.write(out, first_width, latter_width);
|
||||
}
|
||||
|
||||
balance_pair_t& add(const amount_t& amount,
|
||||
const amount_t * a_price = NULL,
|
||||
const amount_t * a_cost = NULL) {
|
||||
if (a_cost && ! cost)
|
||||
cost = new balance_t(quantity);
|
||||
quantity += amount;
|
||||
if (cost)
|
||||
*cost += a_cost ? *a_cost : amount;
|
||||
|
||||
if (a_price) {
|
||||
if (! price)
|
||||
price = new balance_t(*a_price);
|
||||
else
|
||||
price += *a_price;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
const amount_t * a_cost = NULL);
|
||||
|
||||
bool valid() {
|
||||
return (quantity.valid() &&
|
||||
|
|
|
|||
13
walk.cc
13
walk.cc
|
|
@ -45,12 +45,13 @@ void add_transaction_to(const transaction_t& xact, value_t& value)
|
|||
value += transaction_xdata_(xact).composite_amount;
|
||||
}
|
||||
else if (xact.cost || xact.amount.commodity().price || value) {
|
||||
std::auto_ptr<amount_t> price;
|
||||
amount_t * cost = xact.cost;
|
||||
if (xact.amount.commodity().price)
|
||||
price.reset(new amount_t(*xact.amount.commodity().price *
|
||||
xact.amount));
|
||||
value.add(base_amount(xact.amount), price.get(), cost);
|
||||
if (xact.amount.commodity().price) {
|
||||
amount_t price(*xact.amount.commodity().price);
|
||||
price *= xact.amount;
|
||||
value.add(base_amount(xact.amount), &price, xact.cost);
|
||||
} else {
|
||||
value.add(base_amount(xact.amount), NULL, xact.cost);
|
||||
}
|
||||
}
|
||||
else {
|
||||
value = xact.amount;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue