Changed several pointers to references in filters
This commit is contained in:
parent
ae8b57f157
commit
20965d9fa3
3 changed files with 48 additions and 50 deletions
|
|
@ -82,14 +82,7 @@ post_handler_ptr chain_post_handlers(report_t& report,
|
||||||
// changes in market value of commodities, which otherwise would affect
|
// changes in market value of commodities, which otherwise would affect
|
||||||
// the running total unpredictably.
|
// the running total unpredictably.
|
||||||
if (report.HANDLED(revalued))
|
if (report.HANDLED(revalued))
|
||||||
handler.reset(new changed_value_posts
|
handler.reset(new changed_value_posts(handler, report));
|
||||||
(handler,
|
|
||||||
report.HANDLER(display_amount_).expr,
|
|
||||||
report.HANDLED(revalued_total_) ?
|
|
||||||
report.HANDLER(revalued_total_).expr :
|
|
||||||
report.HANDLER(display_total_).expr,
|
|
||||||
report.HANDLER(display_total_).expr,
|
|
||||||
report, report.HANDLED(revalued_only)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// calc_posts computes the running total. When this appears will determine,
|
// calc_posts computes the running total. When this appears will determine,
|
||||||
|
|
|
||||||
|
|
@ -239,19 +239,20 @@ void calc_posts::operator()(post_t& post)
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
typedef function<void (post_t *)> post_functor_t;
|
typedef function<void (post_t&)> post_functor_t;
|
||||||
|
|
||||||
void handle_value(const value_t& value,
|
void handle_value(const value_t& value,
|
||||||
account_t * account,
|
account_t * account,
|
||||||
xact_t * xact,
|
xact_t * xact,
|
||||||
temporaries_t& temps,
|
temporaries_t& temps,
|
||||||
item_handler<post_t>& handler,
|
post_handler_ptr handler,
|
||||||
const date_t& date = date_t(),
|
const date_t& date = date_t(),
|
||||||
const value_t& total = value_t(),
|
const value_t& total = value_t(),
|
||||||
const bool direct_amount = false,
|
const bool direct_amount = false,
|
||||||
const optional<post_functor_t>& functor = none)
|
const optional<post_functor_t>& functor = none)
|
||||||
{
|
{
|
||||||
post_t& post = temps.create_post(*xact, account);
|
post_t& post = temps.create_post(*xact, account);
|
||||||
|
post.add_flags(ITEM_GENERATED);
|
||||||
|
|
||||||
// If the account for this post is all virtual, then report the post as
|
// If the account for this post is all virtual, then report the post as
|
||||||
// such. This allows subtotal reports to show "(Account)" for accounts
|
// such. This allows subtotal reports to show "(Account)" for accounts
|
||||||
|
|
@ -302,11 +303,11 @@ namespace {
|
||||||
xdata.add_flags(POST_EXT_DIRECT_AMT);
|
xdata.add_flags(POST_EXT_DIRECT_AMT);
|
||||||
|
|
||||||
if (functor)
|
if (functor)
|
||||||
(*functor)(&post);
|
(*functor)(post);
|
||||||
|
|
||||||
DEBUG("filter.changed_value.rounding", "post.amount = " << post.amount);
|
DEBUG("filter.changed_value.rounding", "post.amount = " << post.amount);
|
||||||
|
|
||||||
handler(post);
|
(*handler)(post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -344,7 +345,7 @@ void collapse_posts::report_subtotal()
|
||||||
earliest_date : last_xact->_date);
|
earliest_date : last_xact->_date);
|
||||||
DEBUG("filter.collapse", "Pseudo-xact date = " << *xact._date);
|
DEBUG("filter.collapse", "Pseudo-xact date = " << *xact._date);
|
||||||
|
|
||||||
handle_value(subtotal, &totals_account, &xact, temps, *handler);
|
handle_value(subtotal, &totals_account, &xact, temps, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
component_posts.clear();
|
component_posts.clear();
|
||||||
|
|
@ -404,30 +405,46 @@ void related_posts::flush()
|
||||||
item_handler<post_t>::flush();
|
item_handler<post_t>::flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changed_value_posts::changed_value_posts(post_handler_ptr handler,
|
||||||
|
report_t& _report)
|
||||||
|
: item_handler<post_t>(handler), report(_report), last_post(NULL),
|
||||||
|
revalued_account(temps.create_account(_("<Revalued>"))),
|
||||||
|
rounding_account(temps.create_account(_("<Rounding>")))
|
||||||
|
{
|
||||||
|
TRACE_CTOR(changed_value_posts, "post_handler_ptr, report_t&, bool");
|
||||||
|
|
||||||
|
display_amount_expr = report.HANDLER(display_amount_).expr;
|
||||||
|
total_expr = (report.HANDLED(revalued_total_) ?
|
||||||
|
report.HANDLER(revalued_total_).expr :
|
||||||
|
report.HANDLER(display_total_).expr);
|
||||||
|
display_total_expr = report.HANDLER(display_total_).expr;
|
||||||
|
changed_values_only = report.HANDLED(revalued_only);
|
||||||
|
}
|
||||||
|
|
||||||
void changed_value_posts::flush()
|
void changed_value_posts::flush()
|
||||||
{
|
{
|
||||||
if (last_post && last_post->date() <= report.terminus.date()) {
|
if (last_post && last_post->date() <= report.terminus.date()) {
|
||||||
output_revaluation(last_post, report.terminus.date());
|
output_revaluation(*last_post, report.terminus.date());
|
||||||
last_post = NULL;
|
last_post = NULL;
|
||||||
}
|
}
|
||||||
item_handler<post_t>::flush();
|
item_handler<post_t>::flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void changed_value_posts::output_revaluation(post_t * post, const date_t& date)
|
void changed_value_posts::output_revaluation(post_t& post, const date_t& date)
|
||||||
{
|
{
|
||||||
if (is_valid(date))
|
if (is_valid(date))
|
||||||
post->xdata().date = date;
|
post.xdata().date = date;
|
||||||
|
|
||||||
value_t repriced_total;
|
value_t repriced_total;
|
||||||
try {
|
try {
|
||||||
bind_scope_t bound_scope(report, *post);
|
bind_scope_t bound_scope(report, post);
|
||||||
repriced_total = total_expr.calc(bound_scope);
|
repriced_total = total_expr.calc(bound_scope);
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
post->xdata().date = date_t();
|
post.xdata().date = date_t();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
post->xdata().date = date_t();
|
post.xdata().date = date_t();
|
||||||
|
|
||||||
DEBUG("filter.changed_value",
|
DEBUG("filter.changed_value",
|
||||||
"output_revaluation(last_balance) = " << last_total);
|
"output_revaluation(last_balance) = " << last_total);
|
||||||
|
|
@ -441,9 +458,9 @@ void changed_value_posts::output_revaluation(post_t * post, const date_t& date)
|
||||||
|
|
||||||
xact_t& xact = temps.create_xact();
|
xact_t& xact = temps.create_xact();
|
||||||
xact.payee = _("Commodities revalued");
|
xact.payee = _("Commodities revalued");
|
||||||
xact._date = is_valid(date) ? date : post->date();
|
xact._date = is_valid(date) ? date : post.date();
|
||||||
|
|
||||||
handle_value(diff, &revalued_account, &xact, temps, *handler,
|
handle_value(diff, &revalued_account, &xact, temps, handler,
|
||||||
*xact._date, repriced_total, false,
|
*xact._date, repriced_total, false,
|
||||||
optional<post_functor_t>
|
optional<post_functor_t>
|
||||||
(bind(&changed_value_posts::output_rounding, this, _1)));
|
(bind(&changed_value_posts::output_rounding, this, _1)));
|
||||||
|
|
@ -451,9 +468,9 @@ void changed_value_posts::output_revaluation(post_t * post, const date_t& date)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void changed_value_posts::output_rounding(post_t * post)
|
void changed_value_posts::output_rounding(post_t& post)
|
||||||
{
|
{
|
||||||
bind_scope_t bound_scope(report, *post);
|
bind_scope_t bound_scope(report, post);
|
||||||
value_t new_display_total(display_total_expr.calc(bound_scope));
|
value_t new_display_total(display_total_expr.calc(bound_scope));
|
||||||
|
|
||||||
DEBUG("filter.changed_value.rounding",
|
DEBUG("filter.changed_value.rounding",
|
||||||
|
|
@ -478,9 +495,9 @@ void changed_value_posts::output_rounding(post_t * post)
|
||||||
|
|
||||||
xact_t& xact = temps.create_xact();
|
xact_t& xact = temps.create_xact();
|
||||||
xact.payee = _("Commodity rounding");
|
xact.payee = _("Commodity rounding");
|
||||||
xact._date = post->date();
|
xact._date = post.date();
|
||||||
|
|
||||||
handle_value(diff, &rounding_account, &xact, temps, *handler,
|
handle_value(diff, &rounding_account, &xact, temps, handler,
|
||||||
*xact._date, precise_display_total, true);
|
*xact._date, precise_display_total, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -491,12 +508,12 @@ void changed_value_posts::output_rounding(post_t * post)
|
||||||
void changed_value_posts::operator()(post_t& post)
|
void changed_value_posts::operator()(post_t& post)
|
||||||
{
|
{
|
||||||
if (last_post)
|
if (last_post)
|
||||||
output_revaluation(last_post, post.date());
|
output_revaluation(*last_post, post.date());
|
||||||
|
|
||||||
if (changed_values_only)
|
if (changed_values_only)
|
||||||
post.xdata().add_flags(POST_EXT_DISPLAYED);
|
post.xdata().add_flags(POST_EXT_DISPLAYED);
|
||||||
|
|
||||||
output_rounding(&post);
|
output_rounding(post);
|
||||||
|
|
||||||
item_handler<post_t>::operator()(post);
|
item_handler<post_t>::operator()(post);
|
||||||
|
|
||||||
|
|
@ -543,7 +560,7 @@ void subtotal_posts::report_subtotal(const char * spec_fmt,
|
||||||
|
|
||||||
foreach (values_map::value_type& pair, values)
|
foreach (values_map::value_type& pair, values)
|
||||||
handle_value(pair.second.value, pair.second.account, &xact, temps,
|
handle_value(pair.second.value, pair.second.account, &xact, temps,
|
||||||
*handler);
|
handler);
|
||||||
|
|
||||||
values.clear();
|
values.clear();
|
||||||
}
|
}
|
||||||
|
|
@ -653,10 +670,10 @@ void posts_as_equity::report_subtotal()
|
||||||
foreach (balance_t::amounts_map::value_type amount_pair,
|
foreach (balance_t::amounts_map::value_type amount_pair,
|
||||||
pair.second.value.as_balance().amounts)
|
pair.second.value.as_balance().amounts)
|
||||||
handle_value(amount_pair.second, pair.second.account, &xact, temps,
|
handle_value(amount_pair.second, pair.second.account, &xact, temps,
|
||||||
*handler);
|
handler);
|
||||||
} else {
|
} else {
|
||||||
handle_value(pair.second.value, pair.second.account, &xact, temps,
|
handle_value(pair.second.value, pair.second.account, &xact, temps,
|
||||||
*handler);
|
handler);
|
||||||
}
|
}
|
||||||
total += pair.second.value;
|
total += pair.second.value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -382,7 +382,7 @@ class changed_value_posts : public item_handler<post_t>
|
||||||
post_t * last_post;
|
post_t * last_post;
|
||||||
value_t last_total;
|
value_t last_total;
|
||||||
value_t last_display_total;
|
value_t last_display_total;
|
||||||
temporaries_t temps;
|
temporaries_t temps;
|
||||||
account_t& revalued_account;
|
account_t& revalued_account;
|
||||||
account_t& rounding_account;
|
account_t& rounding_account;
|
||||||
|
|
||||||
|
|
@ -390,28 +390,16 @@ class changed_value_posts : public item_handler<post_t>
|
||||||
|
|
||||||
public:
|
public:
|
||||||
changed_value_posts(post_handler_ptr handler,
|
changed_value_posts(post_handler_ptr handler,
|
||||||
const expr_t& _display_amount_expr,
|
report_t& _report);
|
||||||
const expr_t& _total_expr,
|
|
||||||
const expr_t& _display_total_expr,
|
|
||||||
report_t& _report,
|
|
||||||
bool _changed_values_only)
|
|
||||||
: item_handler<post_t>(handler),
|
|
||||||
display_amount_expr(_display_amount_expr), total_expr(_total_expr),
|
|
||||||
display_total_expr(_display_total_expr), report(_report),
|
|
||||||
changed_values_only(_changed_values_only), last_post(NULL),
|
|
||||||
revalued_account(temps.create_account(_("<Revalued>"))),
|
|
||||||
rounding_account(temps.create_account(_("<Rounding>"))) {
|
|
||||||
TRACE_CTOR(changed_value_posts,
|
|
||||||
"post_handler_ptr, const expr_t&, const expr_t&, report_t&, bool");
|
|
||||||
}
|
|
||||||
virtual ~changed_value_posts() {
|
virtual ~changed_value_posts() {
|
||||||
TRACE_DTOR(changed_value_posts);
|
TRACE_DTOR(changed_value_posts);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void flush();
|
virtual void flush();
|
||||||
|
|
||||||
void output_revaluation(post_t * post, const date_t& current);
|
void output_revaluation(post_t& post, const date_t& current);
|
||||||
void output_rounding(post_t * post);
|
void output_rounding(post_t& post);
|
||||||
|
|
||||||
virtual void operator()(post_t& post);
|
virtual void operator()(post_t& post);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue