diff options
Diffstat (limited to 'src/value.cc')
-rw-r--r-- | src/value.cc | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/value.cc b/src/value.cc index f4df3329..7d079caf 100644 --- a/src/value.cc +++ b/src/value.cc @@ -861,7 +861,7 @@ bool value_t::is_less_than(const value_t& val) const return as_amount() < val.as_amount(); } catch (const amount_error&) { - return compare_amount_commodities()(&as_amount(), &val.as_amount()); + return commodity_t::compare_by_commodity()(&as_amount(), &val.as_amount()); } default: break; @@ -1114,18 +1114,18 @@ void value_t::in_place_cast(type_t cast_type) break; } - case BALANCE: + case BALANCE: { + const balance_t& bal(as_balance()); switch (cast_type) { case AMOUNT: { - const balance_t& temp(as_balance()); - if (temp.amounts.size() == 1) { + if (bal.amounts.size() == 1) { // Because we are changing the current balance value to an amount // value, and because set_amount takes a reference (and that memory is // about to be repurposed), we must pass in a copy. - set_amount(amount_t((*temp.amounts.begin()).second)); + set_amount(amount_t((*bal.amounts.begin()).second)); return; } - else if (temp.amounts.size() == 0) { + else if (bal.amounts.size() == 0) { set_amount(0L); return; } @@ -1135,10 +1135,17 @@ void value_t::in_place_cast(type_t cast_type) } break; } + case STRING: + if (bal.is_empty()) + set_string(""); + else + set_string(as_balance().to_string()); + return; default: break; } break; + } case STRING: switch (cast_type) { @@ -1353,7 +1360,8 @@ value_t value_t::exchange_commodities(const std::string& commodities, p; p = std::strtok(NULL, ",")) { if (commodity_t * commodity = - amount_t::current_pool->parse_price_expression(p, add_prices, moment)) { + commodity_pool_t::current_pool->parse_price_expression(p, add_prices, + moment)) { value_t result = value(false, moment, *commodity); if (! result.is_null()) return result; @@ -1523,10 +1531,10 @@ void value_t::annotate(const annotation_t& details) throw_(value_error, _("Cannot annotate %1") << label()); } -bool value_t::is_annotated() const +bool value_t::has_annotation() const { if (is_amount()) - return as_amount().is_annotated(); + return as_amount().has_annotation(); else throw_(value_error, _("Cannot determine whether %1 is annotated") << label()); |