diff options
Diffstat (limited to 'src/balance.cc')
-rw-r--r-- | src/balance.cc | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/src/balance.cc b/src/balance.cc index 9b39a49a..7ce9d994 100644 --- a/src/balance.cc +++ b/src/balance.cc @@ -35,7 +35,7 @@ #include "commodity.h" #include "annotate.h" #include "pool.h" -#include "unistring.h" // for justify() +#include "unistring.h" // for justify() namespace ledger { @@ -71,7 +71,7 @@ balance_t& balance_t::operator+=(const amount_t& amt) { if (amt.is_null()) throw_(balance_error, - _("Cannot add an uninitialized amount to a balance")); + _("Cannot add an uninitialized amount to a balance")); if (amt.is_realzero()) return *this; @@ -96,7 +96,7 @@ balance_t& balance_t::operator-=(const amount_t& amt) { if (amt.is_null()) throw_(balance_error, - _("Cannot subtract an uninitialized amount from a balance")); + _("Cannot subtract an uninitialized amount from a balance")); if (amt.is_realzero()) return *this; @@ -116,7 +116,7 @@ balance_t& balance_t::operator*=(const amount_t& amt) { if (amt.is_null()) throw_(balance_error, - _("Cannot multiply a balance by an uninitialized amount")); + _("Cannot multiply a balance by an uninitialized amount")); if (is_realzero()) { ; @@ -138,12 +138,12 @@ balance_t& balance_t::operator*=(const amount_t& amt) amounts.begin()->second *= amt; else throw_(balance_error, - _("Cannot multiply a balance with annotated commodities by a commoditized amount")); + _("Cannot multiply a balance with annotated commodities by a commoditized amount")); } else { assert(amounts.size() > 1); throw_(balance_error, - _("Cannot multiply a multi-commodity balance by a commoditized amount")); + _("Cannot multiply a multi-commodity balance by a commoditized amount")); } return *this; } @@ -152,7 +152,7 @@ balance_t& balance_t::operator/=(const amount_t& amt) { if (amt.is_null()) throw_(balance_error, - _("Cannot divide a balance by an uninitialized amount")); + _("Cannot divide a balance by an uninitialized amount")); if (is_realzero()) { ; @@ -174,27 +174,25 @@ balance_t& balance_t::operator/=(const amount_t& amt) amounts.begin()->second /= amt; else throw_(balance_error, - _("Cannot divide a balance with annotated commodities by a commoditized amount")); + _("Cannot divide a balance with annotated commodities by a commoditized amount")); } else { assert(amounts.size() > 1); throw_(balance_error, - _("Cannot divide a multi-commodity balance by a commoditized amount")); + _("Cannot divide a multi-commodity balance by a commoditized amount")); } return *this; } optional<balance_t> -balance_t::value(const bool primary_only, - const optional<datetime_t>& moment, - const optional<commodity_t&>& in_terms_of) const +balance_t::value(const optional<datetime_t>& moment, + const optional<commodity_t&>& in_terms_of) const { balance_t temp; bool resolved = false; foreach (const amounts_map::value_type& pair, amounts) { - if (optional<amount_t> val = pair.second.value(primary_only, moment, - in_terms_of)) { + if (optional<amount_t> val = pair.second.value(moment, in_terms_of)) { temp += *val; resolved = true; } else { @@ -225,11 +223,11 @@ balance_t::commodity_amount(const optional<const commodity_t&>& commodity) const // Try stripping annotations before giving an error. balance_t temp(strip_annotations(keep_details_t())); if (temp.amounts.size() == 1) - return temp.commodity_amount(commodity); + return temp.commodity_amount(commodity); throw_(amount_error, - _("Requested amount of a balance with multiple commodities: %1") - << temp); + _("Requested amount of a balance with multiple commodities: %1") + << temp); } } else if (amounts.size() > 0) { @@ -252,11 +250,10 @@ balance_t::strip_annotations(const keep_details_t& what_to_keep) const return temp; } -void balance_t::print(std::ostream& out, - const int first_width, - const int latter_width, - const bool right_justify, - const bool colorize) const +void balance_t::print(std::ostream& out, + const int first_width, + const int latter_width, + const uint_least8_t flags) const { bool first = true; int lwidth = latter_width; @@ -272,7 +269,7 @@ void balance_t::print(std::ostream& out, sorted.push_back(&pair.second); std::stable_sort(sorted.begin(), sorted.end(), - commodity_t::compare_by_commodity()); + commodity_t::compare_by_commodity()); foreach (const amount_t * amount, sorted) { int width; @@ -285,14 +282,14 @@ void balance_t::print(std::ostream& out, } std::ostringstream buf; - buf << *amount; - justify(out, buf.str(), width, right_justify, - colorize && amount->sign() < 0); + amount->print(buf, flags); + justify(out, buf.str(), width, flags & AMOUNT_PRINT_RIGHT_JUSTIFY, + flags & AMOUNT_PRINT_COLORIZE && amount->sign() < 0); } if (first) { out.width(first_width); - if (right_justify) + if (flags & AMOUNT_PRINT_RIGHT_JUSTIFY) out << std::right; else out << std::left; |