*** 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;
|
*cost /= bal_pair.cost ? *bal_pair.cost : bal_pair.quantity;
|
||||||
|
|
||||||
if (bal_pair.price && *bal_pair.price && price)
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
29
balance.h
29
balance.h
|
|
@ -541,7 +541,7 @@ class balance_pair_t
|
||||||
if (! price)
|
if (! price)
|
||||||
price = new balance_t(*bal_pair.price);
|
price = new balance_t(*bal_pair.price);
|
||||||
else
|
else
|
||||||
price += *bal_pair.price;
|
*price += *bal_pair.price;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
@ -574,7 +574,7 @@ class balance_pair_t
|
||||||
price = new balance_t(*bal_pair.price);
|
price = new balance_t(*bal_pair.price);
|
||||||
price->negate();
|
price->negate();
|
||||||
} else {
|
} else {
|
||||||
price -= *bal_pair.price;
|
*price -= *bal_pair.price;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
|
@ -827,7 +827,7 @@ class balance_pair_t
|
||||||
void negate() {
|
void negate() {
|
||||||
quantity.negate();
|
quantity.negate();
|
||||||
if (price) price->negate();
|
if (price) price->negate();
|
||||||
if (cost) cost->negate();
|
if (cost) cost->negate();
|
||||||
}
|
}
|
||||||
balance_pair_t negated() const {
|
balance_pair_t negated() const {
|
||||||
balance_pair_t temp = *this;
|
balance_pair_t temp = *this;
|
||||||
|
|
@ -852,7 +852,7 @@ class balance_pair_t
|
||||||
void abs() {
|
void abs() {
|
||||||
quantity.abs();
|
quantity.abs();
|
||||||
if (price) price->abs();
|
if (price) price->abs();
|
||||||
if (cost) cost->abs();
|
if (cost) cost->abs();
|
||||||
}
|
}
|
||||||
|
|
||||||
amount_t amount(const commodity_t& commodity) const {
|
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 {
|
balance_t value(const std::time_t moment) const {
|
||||||
return quantity.value(moment);
|
return quantity.value(moment);
|
||||||
}
|
}
|
||||||
void write(std::ostream& out,
|
void write(std::ostream& out, const int first_width,
|
||||||
const int first_width,
|
const int latter_width = -1) const {
|
||||||
const int latter_width = -1) const {
|
|
||||||
quantity.write(out, first_width, latter_width);
|
quantity.write(out, first_width, latter_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
balance_pair_t& add(const amount_t& amount,
|
balance_pair_t& add(const amount_t& amount,
|
||||||
const amount_t * a_price = NULL,
|
const amount_t * a_price = NULL,
|
||||||
const amount_t * a_cost = 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool valid() {
|
bool valid() {
|
||||||
return (quantity.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;
|
value += transaction_xdata_(xact).composite_amount;
|
||||||
}
|
}
|
||||||
else if (xact.cost || xact.amount.commodity().price || value) {
|
else if (xact.cost || xact.amount.commodity().price || value) {
|
||||||
std::auto_ptr<amount_t> price;
|
if (xact.amount.commodity().price) {
|
||||||
amount_t * cost = xact.cost;
|
amount_t price(*xact.amount.commodity().price);
|
||||||
if (xact.amount.commodity().price)
|
price *= xact.amount;
|
||||||
price.reset(new amount_t(*xact.amount.commodity().price *
|
value.add(base_amount(xact.amount), &price, xact.cost);
|
||||||
xact.amount));
|
} else {
|
||||||
value.add(base_amount(xact.amount), price.get(), cost);
|
value.add(base_amount(xact.amount), NULL, xact.cost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
value = xact.amount;
|
value = xact.amount;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue