summaryrefslogtreecommitdiff
path: root/account.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-08-04 16:24:41 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-08-04 16:24:41 -0400
commit9c9a34388a0697c4c4c4bd126ec8dd7e1244cd48 (patch)
treea06ae88d3464a2fd6c4a3e184e7973768cf0d392 /account.cc
parent966b231f23a0c74db105784ba1291c860ced483e (diff)
downloadfork-ledger-9c9a34388a0697c4c4c4bd126ec8dd7e1244cd48.tar.gz
fork-ledger-9c9a34388a0697c4c4c4bd126ec8dd7e1244cd48.tar.bz2
fork-ledger-9c9a34388a0697c4c4c4bd126ec8dd7e1244cd48.zip
First round of work to get the balance report working again.
Diffstat (limited to 'account.cc')
-rw-r--r--account.cc37
1 files changed, 34 insertions, 3 deletions
diff --git a/account.cc b/account.cc
index 9fee7145..d3b19ad0 100644
--- a/account.cc
+++ b/account.cc
@@ -112,10 +112,33 @@ std::ostream& operator<<(std::ostream& out, const account_t& account)
return out;
}
+namespace {
+ value_t get_total(account_t& account) {
+ assert(account.xdata_);
+ return account.xdata_->total;
+ }
+
+ template <value_t (*Func)(account_t&)>
+ value_t get_wrapper(call_scope_t& scope) {
+ return (*Func)(find_scope<account_t>(scope));
+ }
+}
+
expr_t::ptr_op_t account_t::lookup(const string& name)
{
switch (name[0]) {
- case 'a':
+ case 'f':
+ if (name.find("fmt_") == 0) {
+ switch (name[4]) {
+ case 'T':
+ return WRAP_FUNCTOR(get_wrapper<&get_total>);
+ }
+ }
+ break;
+
+ case 't':
+ if (name == "total")
+ return WRAP_FUNCTOR(get_wrapper<&get_total>);
break;
}
return expr_t::ptr_op_t();
@@ -150,7 +173,11 @@ void account_t::calculate_sums()
foreach (accounts_map::value_type& pair, accounts) {
(*pair.second).calculate_sums();
- xd.total += (*pair.second).xdata().total;
+ if (xd.total.is_null())
+ xd.total = (*pair.second).xdata().total;
+ else
+ xd.total += (*pair.second).xdata().total;
+
xd.total_count += ((*pair.second).xdata().total_count +
(*pair.second).xdata().count);
}
@@ -159,8 +186,12 @@ void account_t::calculate_sums()
#if 0
compute_amount(result, details_t(account));
#endif
- if (! result.is_realzero())
+
+ if (xd.total.is_null())
+ xd.total = result;
+ else
xd.total += result;
+
xd.total_count += xd.count;
}