summaryrefslogtreecommitdiff
path: root/src/account.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-03-03 17:08:11 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-03-03 17:08:11 -0400
commiteb45a0a4f46577c6615695256e5f6866a27ef20e (patch)
tree7839ad1f692df20276921ec182a78a14b13c61b9 /src/account.cc
parentcf2548c29cbd10c41bd23d119394489e1ced8e2a (diff)
downloadfork-ledger-eb45a0a4f46577c6615695256e5f6866a27ef20e.tar.gz
fork-ledger-eb45a0a4f46577c6615695256e5f6866a27ef20e.tar.bz2
fork-ledger-eb45a0a4f46577c6615695256e5f6866a27ef20e.zip
Normalized how account totals are calculated
Diffstat (limited to 'src/account.cc')
-rw-r--r--src/account.cc48
1 files changed, 11 insertions, 37 deletions
diff --git a/src/account.cc b/src/account.cc
index 9bc96564..3e39045f 100644
--- a/src/account.cc
+++ b/src/account.cc
@@ -167,26 +167,29 @@ namespace {
}
value_t get_total(account_t& account) {
- assert(account.xdata_);
- if (account.xdata_->total.is_null())
+ if (! account.xdata_ || account.xdata_->total.is_null())
return 0L;
else
return account.xdata_->total;
}
value_t get_count(account_t& account) {
- assert(account.xdata_);
- return long(account.xdata_->total_count);
+ if (account.xdata_)
+ return long(account.xdata_->total_count);
+ else
+ return 0L;
}
value_t get_subcount(account_t& account) {
- assert(account.xdata_);
- return long(account.xdata_->count);
+ if (account.xdata_)
+ return long(account.xdata_->count);
+ else
+ return 0L;
}
value_t get_amount(account_t& account) {
- assert(account.xdata_);
- if (account.xdata_->value.is_null())
+ if (! account.xdata_ ||
+ account.xdata_->value.is_null())
return 0L;
else
return account.xdata_->value;
@@ -314,33 +317,4 @@ std::size_t account_t::children_with_flags(xdata_t::flags_t flags) const
return count;
}
-void account_t::calculate_sums(expr_t& amount_expr)
-{
- xdata_t& xd(xdata());
-
- foreach (accounts_map::value_type& pair, accounts) {
- (*pair.second).calculate_sums(amount_expr);
-
- xdata_t& child_xd((*pair.second).xdata());
- if (! child_xd.total.is_null()) {
- add_or_set_value(xd.total, child_xd.total);
- xd.total_count += child_xd.total_count;
- } else {
- assert(child_xd.total_count == 0);
- assert(child_xd.count == 0);
- }
- }
-
- bind_scope_t bound_scope(*amount_expr.get_context(), *this);
- value_t amount(amount_expr.calc(bound_scope));
-
- if (! amount.is_null()) {
- DEBUG("account.sums", "Added " << amount << " to " << fullname());
- add_or_set_value(xd.total, amount);
- xd.total_count += xd.count;
- } else {
- assert(xd.count == 0);
- }
-}
-
} // namespace ledger