diff options
author | John Wiegley <johnw@newartisans.com> | 2008-07-24 09:13:03 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-07-24 09:13:03 -0400 |
commit | 171f79dda268b59d708f5002d1d616a71a30ecb5 (patch) | |
tree | 8f57eb53ade3a63b8155054a085c0267ea3f0cf3 | |
parent | 643f2d33cf24bbae4a13acfbfc6af5fe8439f905 (diff) | |
download | ledger-171f79dda268b59d708f5002d1d616a71a30ecb5.tar.gz ledger-171f79dda268b59d708f5002d1d616a71a30ecb5.tar.bz2 ledger-171f79dda268b59d708f5002d1d616a71a30ecb5.zip |
There are no more asserts or exceptions while parsing, but still there are
many balancing errors.
-rw-r--r-- | balance.h | 25 | ||||
-rw-r--r-- | value.cc | 28 |
2 files changed, 48 insertions, 5 deletions
@@ -314,6 +314,31 @@ public: return temp; } + balance_t round() const { + balance_t temp; + for (amounts_map::const_iterator i = amounts.begin(); + i != amounts.end(); + i++) + temp += i->second.round(); + return temp; + } + balance_t round(amount_t::precision_t prec) const { + balance_t temp; + for (amounts_map::const_iterator i = amounts.begin(); + i != amounts.end(); + i++) + temp += i->second.round(prec); + return temp; + } + balance_t unround() const { + balance_t temp; + for (amounts_map::const_iterator i = amounts.begin(); + i != amounts.end(); + i++) + temp += i->second.unround(); + return temp; + } + balance_t reduce() const { balance_t temp(*this); temp.in_place_reduce(); @@ -1006,24 +1006,38 @@ void value_t::in_place_cast(type_t cast_type) } break; - case AMOUNT: + case AMOUNT: { + const amount_t& amt(as_amount()); switch (cast_type) { case INTEGER: - set_long(as_amount().to_long()); + if (amt.is_null()) + set_long(0L); + else + set_long(as_amount().to_long()); return; case BALANCE: - set_balance(as_amount()); + if (amt.is_null()) + set_balance(balance_t()); + else + set_balance(as_amount()); return; case BALANCE_PAIR: - set_balance_pair(as_amount()); + if (amt.is_null()) + set_balance_pair(balance_pair_t()); + else + set_balance_pair(as_amount()); return; case STRING: - set_string(as_amount().to_string()); + if (amt.is_null()) + set_string(""); + else + set_string(as_amount().to_string()); return; default: break; } break; + } case BALANCE: switch (cast_type) { @@ -1244,6 +1258,10 @@ value_t value_t::round() const return *this; case AMOUNT: return as_amount().round(); + case BALANCE: + return as_balance().round(); + case BALANCE_PAIR: + return as_balance_pair().round(); default: break; } |