item_predicate now operates on scope_t

This means item_predicate is no longer a template.
This commit is contained in:
John Wiegley 2009-02-15 20:56:48 -04:00
parent 5d4ac67920
commit 78e57ac4cf
8 changed files with 35 additions and 38 deletions

View file

@ -51,8 +51,8 @@ xact_handler_ptr chain_xact_handlers(report_t& report,
// `display_predicate'. // `display_predicate'.
if (report.HANDLED(display_)) if (report.HANDLED(display_))
handler.reset(new filter_xacts handler.reset(new filter_xacts
(handler, item_predicate<xact_t>(report.HANDLER(display_).str(), (handler, item_predicate(report.HANDLER(display_).str(),
report.what_to_keep()))); report.what_to_keep())));
// calc_xacts computes the running total. When this appears will // calc_xacts computes the running total. When this appears will
// determine, for example, whether filtered xacts are included or excluded // determine, for example, whether filtered xacts are included or excluded
@ -66,8 +66,8 @@ xact_handler_ptr chain_xact_handlers(report_t& report,
// `secondary_predicate'. // `secondary_predicate'.
if (report.HANDLED(only_)) if (report.HANDLED(only_))
handler.reset(new filter_xacts handler.reset(new filter_xacts
(handler, item_predicate<xact_t> (handler, item_predicate(report.HANDLER(only_).str(),
(report.HANDLER(only_).str(), report.what_to_keep()))); report.what_to_keep())));
// sort_xacts will sort all the xacts it sees, based on the `sort_order' // sort_xacts will sort all the xacts it sees, based on the `sort_order'
// value expression. // value expression.
@ -138,8 +138,8 @@ xact_handler_ptr chain_xact_handlers(report_t& report,
DEBUG("report.predicate", DEBUG("report.predicate",
"Report predicate expression = " << report.HANDLER(limit_).str()); "Report predicate expression = " << report.HANDLER(limit_).str());
handler.reset(new filter_xacts handler.reset(new filter_xacts
(handler, item_predicate<xact_t>(report.HANDLER(limit_).str(), (handler, item_predicate(report.HANDLER(limit_).str(),
report.what_to_keep()))); report.what_to_keep())));
} }
// budget_xacts takes a set of xacts from a data file and uses them to // budget_xacts takes a set of xacts from a data file and uses them to
@ -161,22 +161,22 @@ xact_handler_ptr chain_xact_handlers(report_t& report,
// the filter get reported. // the filter get reported.
if (report.HANDLED(limit_)) if (report.HANDLED(limit_))
handler.reset(new filter_xacts handler.reset(new filter_xacts
(handler, item_predicate<xact_t> (handler, item_predicate(report.HANDLER(limit_).str(),
(report.HANDLER(limit_).str(), report.what_to_keep()))); report.what_to_keep())));
} }
else if (report.HANDLED(forecast_)) { else if (report.HANDLED(forecast_)) {
forecast_xacts * forecast_handler forecast_xacts * forecast_handler
= new forecast_xacts(handler, = new forecast_xacts(handler,
item_predicate<xact_t> item_predicate(report.HANDLER(forecast_).str(),
(report.HANDLER(forecast_).str(), report.what_to_keep())); report.what_to_keep()));
forecast_handler->add_period_entries(report.session.journal->period_entries); forecast_handler->add_period_entries(report.session.journal->period_entries);
handler.reset(forecast_handler); handler.reset(forecast_handler);
// See above, under budget_xacts. // See above, under budget_xacts.
if (report.HANDLED(limit_)) if (report.HANDLED(limit_))
handler.reset(new filter_xacts handler.reset(new filter_xacts
(handler, item_predicate<xact_t> (handler, item_predicate(report.HANDLER(limit_).str(),
(report.HANDLER(limit_).str(), report.what_to_keep()))); report.what_to_keep())));
} }
if (report.HANDLED(comm_as_payee)) if (report.HANDLED(comm_as_payee))

View file

@ -126,7 +126,7 @@ struct entry_finalizer_t {
class auto_entry_t : public entry_base_t class auto_entry_t : public entry_base_t
{ {
public: public:
item_predicate<xact_t> predicate; item_predicate predicate;
auto_entry_t() { auto_entry_t() {
TRACE_CTOR(auto_entry_t, ""); TRACE_CTOR(auto_entry_t, "");
@ -135,7 +135,7 @@ public:
: entry_base_t(), predicate(other.predicate) { : entry_base_t(), predicate(other.predicate) {
TRACE_CTOR(auto_entry_t, "copy"); TRACE_CTOR(auto_entry_t, "copy");
} }
auto_entry_t(const item_predicate<xact_t>& _predicate) auto_entry_t(const item_predicate& _predicate)
: predicate(_predicate) : predicate(_predicate)
{ {
TRACE_CTOR(auto_entry_t, "const item_predicate<xact_t>&"); TRACE_CTOR(auto_entry_t, "const item_predicate<xact_t>&");

View file

@ -787,10 +787,9 @@ void forecast_xacts::flush()
item_handler<xact_t>::flush(); item_handler<xact_t>::flush();
} }
pass_down_accounts::pass_down_accounts pass_down_accounts::pass_down_accounts(acct_handler_ptr handler,
(acct_handler_ptr handler, accounts_iterator& iter,
accounts_iterator& iter, const optional<item_predicate>& predicate)
const optional<item_predicate<account_t> >& predicate)
: item_handler<account_t>(handler), pred(predicate) : item_handler<account_t>(handler), pred(predicate)
{ {
TRACE_CTOR(pass_down_accounts, TRACE_CTOR(pass_down_accounts,

View file

@ -272,13 +272,13 @@ public:
*/ */
class filter_xacts : public item_handler<xact_t> class filter_xacts : public item_handler<xact_t>
{ {
item_predicate<xact_t> pred; item_predicate pred;
filter_xacts(); filter_xacts();
public: public:
filter_xacts(xact_handler_ptr handler, filter_xacts(xact_handler_ptr handler,
const item_predicate<xact_t>& predicate) const item_predicate& predicate)
: item_handler<xact_t>(handler), pred(predicate) { : item_handler<xact_t>(handler), pred(predicate) {
TRACE_CTOR(filter_xacts, TRACE_CTOR(filter_xacts,
"xact_handler_ptr, const item_predicate<xact_t>&"); "xact_handler_ptr, const item_predicate<xact_t>&");
@ -770,11 +770,11 @@ public:
*/ */
class forecast_xacts : public generate_xacts class forecast_xacts : public generate_xacts
{ {
item_predicate<xact_t> pred; item_predicate pred;
public: public:
forecast_xacts(xact_handler_ptr handler, forecast_xacts(xact_handler_ptr handler,
const item_predicate<xact_t>& predicate) const item_predicate& predicate)
: generate_xacts(handler), pred(predicate) { : generate_xacts(handler), pred(predicate) {
TRACE_CTOR(forecast_xacts, TRACE_CTOR(forecast_xacts,
"xact_handler_ptr, const item_predicate<xact_t>&"); "xact_handler_ptr, const item_predicate<xact_t>&");
@ -817,12 +817,12 @@ class pass_down_accounts : public item_handler<account_t>
{ {
pass_down_accounts(); pass_down_accounts();
optional<item_predicate<account_t> > pred; optional<item_predicate> pred;
public: public:
pass_down_accounts(acct_handler_ptr handler, pass_down_accounts(acct_handler_ptr handler,
accounts_iterator& iter, accounts_iterator& iter,
const optional<item_predicate<account_t> >& predicate = none); const optional<item_predicate>& predicate = none);
virtual ~pass_down_accounts() { virtual ~pass_down_accounts() {
TRACE_DTOR(pass_down_accounts); TRACE_DTOR(pass_down_accounts);

View file

@ -149,10 +149,10 @@ class format_entries : public format_xacts
class format_accounts : public item_handler<account_t> class format_accounts : public item_handler<account_t>
{ {
protected: protected:
report_t& report; report_t& report;
format_t format; format_t format;
item_predicate<account_t> disp_pred; item_predicate disp_pred;
bool print_final_total; bool print_final_total;
bool disp_subaccounts_p(account_t& account, account_t *& to_show); bool disp_subaccounts_p(account_t& account, account_t *& to_show);
bool display_account(account_t& account); bool display_account(account_t& account);

View file

@ -56,7 +56,6 @@ namespace ledger {
* *
* Long. * Long.
*/ */
template <typename T>
class item_predicate class item_predicate
{ {
public: public:
@ -84,7 +83,7 @@ public:
TRACE_DTOR(item_predicate); TRACE_DTOR(item_predicate);
} }
bool operator()(T& item) { bool operator()(scope_t& item) {
return ! predicate || predicate.calc(item).strip_annotations(what_to_keep); return ! predicate || predicate.calc(item).strip_annotations(what_to_keep);
} }
}; };

View file

@ -128,11 +128,11 @@ void report_t::accounts_report(acct_handler_ptr handler)
if (! HANDLED(sort_)) { if (! HANDLED(sort_)) {
basic_accounts_iterator walker(*session.master); basic_accounts_iterator walker(*session.master);
pass_down_accounts(handler, walker, pass_down_accounts(handler, walker,
item_predicate<account_t>("total", what_to_keep())); item_predicate("total", what_to_keep()));
} else { } else {
sorted_accounts_iterator walker(*session.master, HANDLER(sort_).str()); sorted_accounts_iterator walker(*session.master, HANDLER(sort_).str());
pass_down_accounts(handler, walker, pass_down_accounts(handler, walker,
item_predicate<account_t>("total", what_to_keep())); item_predicate("total", what_to_keep()));
} }
session.clean_xacts(); session.clean_xacts();

View file

@ -519,10 +519,9 @@ void instance_t::automated_entry_directive(char * line)
istream_pos_type pos = curr_pos; istream_pos_type pos = curr_pos;
std::size_t lnum = linenum; std::size_t lnum = linenum;
std::auto_ptr<auto_entry_t> std::auto_ptr<auto_entry_t> ae
ae(new auto_entry_t(item_predicate<xact_t> (new auto_entry_t(item_predicate(skip_ws(line + 1),
(skip_ws(line + 1), keep_details_t(true, true, true, true))));
keep_details_t(true, true, true, true))));
if (parse_xacts(account_stack.front(), *ae.get(), "automated")) { if (parse_xacts(account_stack.front(), *ae.get(), "automated")) {
journal.auto_entries.push_back(ae.get()); journal.auto_entries.push_back(ae.get());