diff options
-rw-r--r-- | src/chain.cc | 32 | ||||
-rw-r--r-- | src/filters.cc | 14 | ||||
-rw-r--r-- | src/filters.h | 152 | ||||
-rw-r--r-- | src/report.cc | 4 | ||||
-rw-r--r-- | src/report.h | 2 |
5 files changed, 61 insertions, 143 deletions
diff --git a/src/chain.cc b/src/chain.cc index 64881c6f..1d24aafb 100644 --- a/src/chain.cc +++ b/src/chain.cc @@ -195,16 +195,36 @@ xact_handler_ptr chain_xact_handlers(report_t& report, report)); } - if (report.HANDLED(comm_as_payee)) - handler.reset(new set_comm_as_payee(handler)); + if (report.HANDLED(set_account_)) + handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT, + report.session.master.get(), + report.HANDLER(set_account_).str(), + report)); + else if (report.HANDLED(set_payee_)) + handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE, + report.session.master.get(), + report.HANDLER(set_payee_).str(), + report)); + else if (report.HANDLED(comm_as_payee)) + handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE, + report.session.master.get(), + expr_t("commodity"), report)); else if (report.HANDLED(code_as_payee)) - handler.reset(new set_code_as_payee(handler)); + handler.reset(new transfer_details(handler, transfer_details::SET_PAYEE, + report.session.master.get(), + expr_t("code"), report)); else if (report.HANDLED(payee_as_account)) - handler.reset(new set_payee_as_account(handler, report.session.master.get())); + handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT, + report.session.master.get(), + expr_t("payee"), report)); else if (report.HANDLED(comm_as_account)) - handler.reset(new set_comm_as_account(handler, report.session.master.get())); + handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT, + report.session.master.get(), + expr_t("commodity"), report)); else if (report.HANDLED(code_as_account)) - handler.reset(new set_code_as_account(handler, report.session.master.get())); + handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT, + report.session.master.get(), + expr_t("code"), report)); return handler; } diff --git a/src/filters.cc b/src/filters.cc index 65fa92db..1deffffb 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -573,7 +573,19 @@ void transfer_details::operator()(xact_t& xact) temp.add_flags(ITEM_TEMP); entry.add_xact(&temp); - set_details(entry, temp); + bind_scope_t bound_scope(scope, temp); + + switch (which_element) { + case SET_PAYEE: + entry.payee = expr.calc(bound_scope).to_string(); + break; + case SET_ACCOUNT: + temp.account = master->find_account(expr.calc(bound_scope).to_string()); + break; + default: + assert(false); + break; + } item_handler<xact_t>::operator()(temp); } diff --git a/src/filters.h b/src/filters.h index 7335d817..7f5b6b47 100644 --- a/src/filters.h +++ b/src/filters.h @@ -639,21 +639,33 @@ class transfer_details : public item_handler<xact_t> { std::list<entry_t> entry_temps; std::list<xact_t> xact_temps; + account_t * master; + expr_t expr; + scope_t& scope; transfer_details(); public: - transfer_details(xact_handler_ptr handler) - : item_handler<xact_t>(handler) { - TRACE_CTOR(transfer_details, "xact_handler_ptr"); + enum element_t { + SET_PAYEE, + SET_ACCOUNT + } which_element; + + transfer_details(xact_handler_ptr handler, + element_t _which_element, + account_t * _master, + const expr_t& _expr, + scope_t& _scope) + : item_handler<xact_t>(handler), master(_master), + expr(_expr), scope(_scope), which_element(_which_element) { + TRACE_CTOR(transfer_details, + "xact_handler_ptr, element_t, account_t *, expr_t, scope_t&"); } virtual ~transfer_details() { TRACE_DTOR(transfer_details); clear_entries_xacts(entry_temps); } - virtual void set_details(entry_t& entry, xact_t& xact) = 0; - virtual void operator()(xact_t& xact); }; @@ -662,136 +674,6 @@ public: * * Long. */ -class set_comm_as_payee : public transfer_details -{ - set_comm_as_payee(); - -public: - set_comm_as_payee(xact_handler_ptr handler) - : transfer_details(handler) { - TRACE_CTOR(set_comm_as_payee, "xact_handler_ptr"); - } - virtual ~set_comm_as_payee() { - TRACE_DTOR(set_comm_as_payee); - } - - virtual void set_details(entry_t& entry, xact_t& xact) { - if (xact.amount.commodity()) - entry.payee = xact.amount.commodity().symbol(); - else - entry.payee = "<none>"; - } -}; - -/** - * @brief Brief - * - * Long. - */ -class set_code_as_payee : public transfer_details -{ - set_code_as_payee(); - -public: - set_code_as_payee(xact_handler_ptr handler) - : transfer_details(handler) { - TRACE_CTOR(set_code_as_payee, "xact_handler_ptr"); - } - virtual ~set_code_as_payee() { - TRACE_DTOR(set_code_as_payee); - } - - virtual void set_details(entry_t& entry, xact_t& xact) { - if (xact.entry->code) - entry.payee = *xact.entry->code; - else - entry.payee = "<none>"; - } -}; - -/** - * @brief Brief - * - * Long. - */ -class set_payee_as_account : public transfer_details -{ - account_t * master; - - set_payee_as_account(); - -public: - set_payee_as_account(xact_handler_ptr handler, - account_t * _master) - : transfer_details(handler), master(_master) { - TRACE_CTOR(set_payee_as_account, "xact_handler_ptr"); - } - virtual ~set_payee_as_account() { - TRACE_DTOR(set_payee_as_account); - } - - virtual void set_details(entry_t& entry, xact_t& xact) { - xact.account = master->find_account(entry.payee); - } -}; - -/** - * @brief Brief - * - * Long. - */ -class set_comm_as_account : public transfer_details -{ - account_t * master; - - set_comm_as_account(); - -public: - set_comm_as_account(xact_handler_ptr handler, - account_t * _master) - : transfer_details(handler), master(_master) { - TRACE_CTOR(set_comm_as_account, "xact_handler_ptr"); - } - virtual ~set_comm_as_account() { - TRACE_DTOR(set_comm_as_account); - } - - virtual void set_details(entry_t&, xact_t& xact) { - xact.account = master->find_account(xact.amount.commodity().symbol()); - } -}; - -/** - * @brief Brief - * - * Long. - */ -class set_code_as_account : public transfer_details -{ - account_t * master; - - set_code_as_account(); - -public: - set_code_as_account(xact_handler_ptr handler, - account_t * _master) - : transfer_details(handler), master(_master) { - TRACE_CTOR(set_code_as_account, "xact_handler_ptr"); - } - virtual ~set_code_as_account() { - TRACE_DTOR(set_code_as_account); - } - - virtual void set_details(entry_t& entry, xact_t& xact) { - xact.account = master->find_account(entry.code ? *entry.code : "<none>"); - } -}; - -/** - * @brief Brief - * - * Long. - */ class dow_xacts : public subtotal_xacts { xacts_list days_of_the_week[7]; diff --git a/src/report.cc b/src/report.cc index 59286a91..771e1950 100644 --- a/src/report.cc +++ b/src/report.cc @@ -470,7 +470,9 @@ option_t<report_t> * report_t::lookup_option(const char * p) else OPT(revalued_only); break; case 's': - OPT(set_price_); + OPT(set_account_); + else OPT(set_payee_); + else OPT(set_price_); else OPT(sort_); else OPT(sort_all_); else OPT(sort_entries_); diff --git a/src/report.h b/src/report.h index fc3afd3c..7c68c678 100644 --- a/src/report.h +++ b/src/report.h @@ -438,6 +438,8 @@ public: OPTION(report_t, related_all); OPTION(report_t, revalued); OPTION(report_t, revalued_only); + OPTION(report_t, set_account_); + OPTION(report_t, set_payee_); OPTION(report_t, set_price_); OPTION_(report_t, sort_, DO_(args) { // -S |