diff options
-rw-r--r-- | src/amount.cc | 9 | ||||
-rw-r--r-- | src/amount.h | 6 | ||||
-rw-r--r-- | src/value.cc | 19 | ||||
-rw-r--r-- | src/value.h | 7 |
4 files changed, 32 insertions, 9 deletions
diff --git a/src/amount.cc b/src/amount.cc index 13630eb2..2f28e2d4 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -434,7 +434,7 @@ amount_t::precision_t amount_t::display_precision() const return quantity->prec; } -amount_t& amount_t::in_place_negate() +void amount_t::in_place_negate() { if (quantity) { _dup(); @@ -442,7 +442,6 @@ amount_t& amount_t::in_place_negate() } else { throw_(amount_error, "Cannot negate an uninitialized amount"); } - return *this; } amount_t amount_t::inverted() const @@ -485,7 +484,7 @@ amount_t amount_t::unrounded() const return t; } -amount_t& amount_t::in_place_reduce() +void amount_t::in_place_reduce() { if (! quantity) throw_(amount_error, "Cannot reduce an uninitialized amount"); @@ -494,10 +493,9 @@ amount_t& amount_t::in_place_reduce() *this *= commodity().smaller()->number(); commodity_ = commodity().smaller()->commodity_; } - return *this; } -amount_t& amount_t::in_place_unreduce() +void amount_t::in_place_unreduce() { if (! quantity) throw_(amount_error, "Cannot unreduce an uninitialized amount"); @@ -508,7 +506,6 @@ amount_t& amount_t::in_place_unreduce() if (abs() < amount_t(1L)) break; } - return *this; } optional<amount_t> amount_t::value(const optional<datetime_t>& moment, diff --git a/src/amount.h b/src/amount.h index 8042dd6b..0943a4c0 100644 --- a/src/amount.h +++ b/src/amount.h @@ -296,7 +296,7 @@ public: temp.in_place_negate(); return temp; } - amount_t& in_place_negate(); + void in_place_negate(); amount_t operator-() const { return negate(); @@ -335,7 +335,7 @@ public: temp.in_place_reduce(); return temp; } - amount_t& in_place_reduce(); + void in_place_reduce(); /** unreduce(), if used with a "scaling commodity", yields the most compact form greater than one. That is, \c 3599s will unreduce to @@ -346,7 +346,7 @@ public: temp.in_place_unreduce(); return temp; } - amount_t& in_place_unreduce(); + void in_place_unreduce(); /** Returns the historical value for an amount -- the default moment returns the most recently known price -- based on the price history diff --git a/src/value.cc b/src/value.cc index 4b9f5756..4cfee747 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1404,6 +1404,25 @@ void value_t::in_place_reduce() //throw_(value_error, "Cannot reduce " << label()); } +void value_t::in_place_unreduce() +{ + switch (type()) { + case AMOUNT: + as_amount_lval().in_place_unreduce(); + return; + case BALANCE: + as_balance_lval().in_place_unreduce(); + return; + case BALANCE_PAIR: + as_balance_pair_lval().in_place_unreduce(); + return; + default: + return; + } + + //throw_(value_error, "Cannot reduce " << label()); +} + value_t value_t::abs() const { switch (type()) { diff --git a/src/value.h b/src/value.h index 17ac4378..a1d85892 100644 --- a/src/value.h +++ b/src/value.h @@ -421,6 +421,13 @@ public: } void in_place_reduce(); // exists for efficiency's sake + value_t unreduce() const { + value_t temp(*this); + temp.in_place_unreduce(); + return temp; + } + void in_place_unreduce(); // exists for efficiency's sake + // Return the "market value" of a given value at a specific time. value_t value(const optional<datetime_t>& moment = none, const optional<commodity_t&>& in_terms_of = none) const; |