Gather account details in a details_t structure

This commit is contained in:
John Wiegley 2009-03-03 20:28:09 -04:00
parent eb45a0a4f4
commit 1540ccec01
7 changed files with 49 additions and 35 deletions

View file

@ -167,32 +167,32 @@ namespace {
} }
value_t get_total(account_t& account) { value_t get_total(account_t& account) {
if (! account.xdata_ || account.xdata_->total.is_null()) if (! account.xdata_ || account.xdata_->family_details.total.is_null())
return 0L; return 0L;
else else
return account.xdata_->total; return account.xdata_->family_details.total;
} }
value_t get_count(account_t& account) { value_t get_count(account_t& account) {
if (account.xdata_) if (account.xdata_)
return long(account.xdata_->total_count); return long(account.xdata_->family_details.posts_count);
else else
return 0L; return 0L;
} }
value_t get_subcount(account_t& account) { value_t get_subcount(account_t& account) {
if (account.xdata_) if (account.xdata_)
return long(account.xdata_->count); return long(account.xdata_->self_details.posts_count);
else else
return 0L; return 0L;
} }
value_t get_amount(account_t& account) { value_t get_amount(account_t& account) {
if (! account.xdata_ || if (! account.xdata_ ||
account.xdata_->value.is_null()) account.xdata_->self_details.total.is_null())
return 0L; return 0L;
else else
return account.xdata_->value; return account.xdata_->self_details.total;
} }
value_t get_depth(account_t& account) { value_t get_depth(account_t& account) {

View file

@ -128,26 +128,31 @@ class account_t : public scope_t
#define ACCOUNT_EXT_MATCHING 0x10 #define ACCOUNT_EXT_MATCHING 0x10
#define ACCOUNT_EXT_DISPLAYED 0x20 #define ACCOUNT_EXT_DISPLAYED 0x20
value_t value; struct details_t
value_t total; {
std::size_t count; // posts counted toward amount value_t total;
std::size_t total_count; // posts counted toward total
std::size_t virtuals; std::size_t posts_count;
std::size_t total_virtuals; std::size_t posts_virtuals_count;
details_t()
: posts_count(0),
posts_virtuals_count(0) {}
};
details_t self_details;
details_t family_details;
std::list<sort_value_t> sort_values; std::list<sort_value_t> sort_values;
xdata_t() : supports_flags<>(), count(0), total_count(0), virtuals(0) xdata_t() : supports_flags<>()
{ {
TRACE_CTOR(account_t::xdata_t, ""); TRACE_CTOR(account_t::xdata_t, "");
} }
xdata_t(const xdata_t& other) xdata_t(const xdata_t& other)
: supports_flags<>(other.flags()), : supports_flags<>(other.flags()),
value(other.value), self_details(other.self_details),
total(other.total), family_details(other.family_details),
count(other.count),
total_count(other.total_count),
virtuals(other.virtuals),
sort_values(other.sort_values) sort_values(other.sort_values)
{ {
TRACE_CTOR(account_t::xdata_t, "copy"); TRACE_CTOR(account_t::xdata_t, "copy");

View file

@ -200,25 +200,29 @@ void calc_posts::operator()(post_t& post)
xdata.count = 1; xdata.count = 1;
} }
post.add_to_value(xdata.total, amount_expr); value_t amount;
post.add_to_value(amount, amount_expr);
add_or_set_value(xdata.total, amount);
if (calc_totals) { if (calc_totals) {
account_t * acct = post.reported_account(); account_t * acct = post.reported_account();
account_t::xdata_t * acct_xdata = &acct->xdata(); account_t::xdata_t * acct_xdata = &acct->xdata();
post.add_to_value(acct_xdata->value, amount_expr); add_or_set_value(acct_xdata->self_details.total, amount);
acct_xdata->self_details.posts_count++;
acct_xdata->self_details.posts_virtuals_count++;
acct_xdata->count++;
acct_xdata->virtuals++;
acct_xdata->add_flags(ACCOUNT_EXT_VISITED); acct_xdata->add_flags(ACCOUNT_EXT_VISITED);
while (true) { while (true) {
post.add_to_value(acct_xdata->total, amount_expr); add_or_set_value(acct_xdata->family_details.total, amount);
acct_xdata->family_details.posts_count++;
acct_xdata->total_count++;
if (post.has_flags(POST_VIRTUAL)) if (post.has_flags(POST_VIRTUAL))
acct_xdata->total_virtuals++; acct_xdata->family_details.posts_virtuals_count++;
acct = acct->parent; acct = acct->parent;
if (acct) if (acct)

View file

@ -290,8 +290,10 @@ void format_accounts::flush()
if (report.session.master->has_xdata()) { if (report.session.master->has_xdata()) {
account_t::xdata_t& xdata(report.session.master->xdata()); account_t::xdata_t& xdata(report.session.master->xdata());
if (! report.HANDLED(no_total) && top_displayed > 1 && xdata.total) { if (! report.HANDLED(no_total) && top_displayed > 1 &&
xdata.value = xdata.total; xdata.family_details.total) {
xdata.self_details.total = xdata.family_details.total;
bind_scope_t bound_scope(report, *report.session.master); bind_scope_t bound_scope(report, *report.session.master);
separator_format.format(out, bound_scope); separator_format.format(out, bound_scope);
total_line_format.format(out, bound_scope); total_line_format.format(out, bound_scope);

View file

@ -232,10 +232,10 @@ namespace {
DEBUG("post.account_amount", "Found account: " << account->fullname()); DEBUG("post.account_amount", "Found account: " << account->fullname());
if (account->xdata().value.is_null()) if (account->xdata().self_details.total.is_null())
return 0L; return 0L;
else else
return account->xdata().value.simplified(); return account->xdata().self_details.total.simplified();
} }
value_t get_account_depth(post_t& post) { value_t get_account_depth(post_t& post) {

View file

@ -1013,20 +1013,21 @@ post_t * instance_t::parse_post(char * line,
amount_t& amt(*post->assigned_amount); amount_t& amt(*post->assigned_amount);
DEBUG("post.assign", "line " << linenum << ": " DEBUG("post.assign", "line " << linenum << ": "
"account balance = " << xdata.value); "account balance = " << xdata.self_details.total);
DEBUG("post.assign", "line " << linenum << ": " DEBUG("post.assign", "line " << linenum << ": "
"post amount = " << amt); "post amount = " << amt);
amount_t diff; amount_t diff;
switch (xdata.value.type()) { switch (xdata.self_details.total.type()) {
case value_t::AMOUNT: case value_t::AMOUNT:
diff = amt - xdata.value.as_amount(); diff = amt - xdata.self_details.total.as_amount();
break; break;
case value_t::BALANCE: case value_t::BALANCE:
if (optional<amount_t> comm_bal = if (optional<amount_t> comm_bal =
xdata.value.as_balance().commodity_amount(amt.commodity())) xdata.self_details.total.as_balance()
.commodity_amount(amt.commodity()))
diff = amt - *comm_bal; diff = amt - *comm_bal;
else else
diff = amt; diff = amt;

View file

@ -317,11 +317,13 @@ bool xact_base_t::finalize()
post->amount.in_place_reduce(); post->amount.in_place_reduce();
add_or_set_value(post->account->xdata().value, post->amount); add_or_set_value(post->account->xdata().self_details.total,
post->amount);
DEBUG("xact.finalize.totals", DEBUG("xact.finalize.totals",
"Total for " << post->account->fullname() << " + " "Total for " << post->account->fullname() << " + "
<< post->amount << ": " << post->account->xdata().value); << post->amount << ": "
<< post->account->xdata().self_details.total);
} else { } else {
some_null = true; some_null = true;
} }