diff options
author | John Wiegley <johnw@newartisans.com> | 2019-01-30 11:09:08 -0800 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2019-01-30 11:09:08 -0800 |
commit | 557ab32d30bcca3622e06a6809a541a015e84aa3 (patch) | |
tree | 0ce7f56328fc86b6705966a52e89f75c3d40cbc1 /src/balance.cc | |
parent | 2c61d41deaab0343f29b424dbcd1a751928b3056 (diff) | |
download | fork-ledger-557ab32d30bcca3622e06a6809a541a015e84aa3.tar.gz fork-ledger-557ab32d30bcca3622e06a6809a541a015e84aa3.tar.bz2 fork-ledger-557ab32d30bcca3622e06a6809a541a015e84aa3.zip |
Expose a new utility function for balances: sorted_amounts
Diffstat (limited to 'src/balance.cc')
-rw-r--r-- | src/balance.cc | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/balance.cc b/src/balance.cc index fa1bc20c..478ceb45 100644 --- a/src/balance.cc +++ b/src/balance.cc @@ -240,6 +240,14 @@ balance_t::strip_annotations(const keep_details_t& what_to_keep) const return temp; } +void balance_t::sorted_amounts(amounts_array& sorted) const +{ + foreach (const amounts_map::value_type& pair, amounts) + sorted.push_back(&pair.second); + std::stable_sort(sorted.begin(), sorted.end(), + commodity_t::compare_by_commodity()); +} + void balance_t::map_sorted_amounts(function<void(const amount_t&)> fn) const { if (! amounts.empty()) { @@ -249,16 +257,8 @@ void balance_t::map_sorted_amounts(function<void(const amount_t&)> fn) const fn(amount); } else { - typedef std::vector<const amount_t *> amounts_array; amounts_array sorted; - - foreach (const amounts_map::value_type& pair, amounts) - if (pair.second) - sorted.push_back(&pair.second); - - std::stable_sort(sorted.begin(), sorted.end(), - commodity_t::compare_by_commodity()); - + sorted_amounts(sorted); foreach (const amount_t * amount, sorted) fn(*amount); } |