diff options
author | John Wiegley <johnw@newartisans.com> | 2006-02-28 10:24:21 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 02:41:27 -0400 |
commit | 2930b89ea3e4515e24739357598034db6cb842e0 (patch) | |
tree | a92eedcf89bf708250b12574e06eec138a71f9fc | |
parent | f741c1b62e2fa4ac78fa1034d3a8a7fdad909c0c (diff) | |
download | fork-ledger-2930b89ea3e4515e24739357598034db6cb842e0.tar.gz fork-ledger-2930b89ea3e4515e24739357598034db6cb842e0.tar.bz2 fork-ledger-2930b89ea3e4515e24739357598034db6cb842e0.zip |
*** empty log message ***
-rw-r--r-- | balance.cc | 21 | ||||
-rw-r--r-- | balance.h | 29 | ||||
-rw-r--r-- | walk.cc | 13 |
3 files changed, 34 insertions, 29 deletions
@@ -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; } @@ -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() && @@ -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; |