diff options
author | John Wiegley <johnw@newartisans.com> | 2010-05-30 02:20:34 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-05-30 02:38:30 -0600 |
commit | 8f17d01f5e48ae5097f4cb38d481b00577329b8c (patch) | |
tree | 2db7a0f4b156ec88cf4d785b9d7a4ea2dae60a07 | |
parent | 7ec52d2b395bf4cfc656eef52d72b9d83c1c1523 (diff) | |
download | fork-ledger-8f17d01f5e48ae5097f4cb38d481b00577329b8c.tar.gz fork-ledger-8f17d01f5e48ae5097f4cb38d481b00577329b8c.tar.bz2 fork-ledger-8f17d01f5e48ae5097f4cb38d481b00577329b8c.zip |
Added new required item_handler_t::clear() method
-rw-r--r-- | src/chain.h | 5 | ||||
-rw-r--r-- | src/filters.h | 168 | ||||
-rw-r--r-- | src/output.h | 29 | ||||
-rw-r--r-- | src/temps.cc | 45 | ||||
-rw-r--r-- | src/temps.h | 6 | ||||
-rw-r--r-- | src/xml.h | 8 |
6 files changed, 227 insertions, 34 deletions
diff --git a/src/chain.h b/src/chain.h index 94d54317..fbde9f0a 100644 --- a/src/chain.h +++ b/src/chain.h @@ -75,6 +75,11 @@ public: (*handler.get())(item); } } + + virtual void clear() { + if (handler) + handler->clear(); + } }; typedef shared_ptr<item_handler<post_t> > post_handler_ptr; diff --git a/src/filters.h b/src/filters.h index ced51f3f..3f3e3d34 100644 --- a/src/filters.h +++ b/src/filters.h @@ -88,6 +88,11 @@ public: virtual void operator()(post_t& post) { posts.push_back(&post); } + + virtual void clear() { + posts.clear(); + item_handler<post_t>::clear(); + } }; class posts_iterator; @@ -149,27 +154,34 @@ public: virtual void flush(); virtual void operator()(post_t& post); + + virtual void clear() { + completed = false; + posts.clear(); + xacts_seen = 0; + last_xact = NULL; + + item_handler<post_t>::clear(); + } }; class sort_posts : public item_handler<post_t> { typedef std::deque<post_t *> posts_deque; - posts_deque posts; - const expr_t sort_order; + posts_deque posts; + expr_t sort_order; sort_posts(); public: - sort_posts(post_handler_ptr handler, - const expr_t& _sort_order) + sort_posts(post_handler_ptr handler, const expr_t& _sort_order) : item_handler<post_t>(handler), sort_order(_sort_order) { TRACE_CTOR(sort_posts, "post_handler_ptr, const value_expr&"); } - sort_posts(post_handler_ptr handler, - const string& _sort_order) + sort_posts(post_handler_ptr handler, const string& _sort_order) : item_handler<post_t>(handler), sort_order(_sort_order) { TRACE_CTOR(sort_posts, @@ -189,6 +201,13 @@ public: virtual void operator()(post_t& post) { posts.push_back(&post); } + + virtual void clear() { + posts.clear(); + sort_order.mark_uncompiled(); + + item_handler<post_t>::clear(); + } }; class sort_xacts : public item_handler<post_t> @@ -199,14 +218,12 @@ class sort_xacts : public item_handler<post_t> sort_xacts(); public: - sort_xacts(post_handler_ptr handler, - const expr_t& _sort_order) + sort_xacts(post_handler_ptr handler, const expr_t& _sort_order) : sorter(handler, _sort_order) { TRACE_CTOR(sort_xacts, "post_handler_ptr, const value_expr&"); } - sort_xacts(post_handler_ptr handler, - const string& _sort_order) + sort_xacts(post_handler_ptr handler, const string& _sort_order) : sorter(handler, _sort_order) { TRACE_CTOR(sort_xacts, "post_handler_ptr, const string&"); @@ -228,6 +245,13 @@ public: last_xact = post.xact; } + + virtual void clear() { + sorter.clear(); + last_xact = NULL; + + item_handler<post_t>::clear(); + } }; class filter_posts : public item_handler<post_t> @@ -255,6 +279,11 @@ public: (*handler)(post); } } + + virtual void clear() { + pred.mark_uncompiled(); + item_handler<post_t>::clear(); + } }; class anonymize_posts : public item_handler<post_t> @@ -274,6 +303,13 @@ public: } virtual void operator()(post_t& post); + + virtual void clear() { + temps.clear(); + last_xact = NULL; + + item_handler<post_t>::clear(); + } }; class calc_posts : public item_handler<post_t> @@ -297,6 +333,13 @@ public: } virtual void operator()(post_t& post); + + virtual void clear() { + last_post = NULL; + amount_expr.mark_uncompiled(); + + item_handler<post_t>::clear(); + } }; class collapse_posts : public item_handler<post_t> @@ -334,13 +377,29 @@ public: } virtual void flush() { - report_subtotal(); + report_subtotal(); item_handler<post_t>::flush(); } void report_subtotal(); virtual void operator()(post_t& post); + + virtual void clear() { + amount_expr.mark_uncompiled(); + display_predicate.mark_uncompiled(); + only_predicate.mark_uncompiled(); + + subtotal = value_t(); + count = 0; + last_xact = NULL; + last_post = NULL; + + temps.clear(); + component_posts.clear(); + + item_handler<post_t>::clear(); + } }; class related_posts : public item_handler<post_t> @@ -367,6 +426,11 @@ public: post.xdata().add_flags(POST_EXT_RECEIVED); posts.push_back(&post); } + + virtual void clear() { + posts.clear(); + item_handler<post_t>::clear(); + } }; class changed_value_posts : public item_handler<post_t> @@ -410,6 +474,20 @@ public: void output_rounding(post_t& post); virtual void operator()(post_t& post); + + virtual void clear() { + display_amount_expr.mark_uncompiled(); + total_expr.mark_uncompiled(); + display_total_expr.mark_uncompiled(); + + last_post = NULL; + last_total = value_t(); + last_display_total = value_t(); + + temps.clear(); + + item_handler<post_t>::clear(); + } }; class subtotal_posts : public item_handler<post_t> @@ -471,10 +549,20 @@ public: item_handler<post_t>::flush(); } virtual void operator()(post_t& post); + + virtual void clear() { + amount_expr.mark_uncompiled(); + values.clear(); + temps.clear(); + component_posts.clear(); + + item_handler<post_t>::clear(); + } }; class interval_posts : public subtotal_posts { + date_interval_t start_interval; date_interval_t interval; date_interval_t last_interval; post_t * last_post; @@ -491,8 +579,9 @@ public: const date_interval_t& _interval, bool _exact_periods = false, bool _generate_empty_posts = false) - : subtotal_posts(_handler, amount_expr), interval(_interval), - last_post(NULL), empty_account(temps.create_account(_("<None>"))), + : subtotal_posts(_handler, amount_expr), start_interval(_interval), + interval(start_interval), last_post(NULL), + empty_account(temps.create_account(_("<None>"))), exact_periods(_exact_periods), generate_empty_posts(_generate_empty_posts) { TRACE_CTOR(interval_posts, @@ -512,6 +601,14 @@ public: } } virtual void operator()(post_t& post); + + virtual void clear() { + interval = start_interval; + last_interval = date_interval_t(); + last_post = NULL; + + item_handler<post_t>::clear(); + } }; class posts_as_equity : public subtotal_posts @@ -539,6 +636,11 @@ public: report_subtotal(); subtotal_posts::flush(); } + + virtual void clear() { + last_post = NULL; + item_handler<post_t>::clear(); + } }; class by_payee_posts : public item_handler<post_t> @@ -562,6 +664,13 @@ class by_payee_posts : public item_handler<post_t> virtual void flush(); virtual void operator()(post_t& post); + + virtual void clear() { + amount_expr.mark_uncompiled(); + payee_subtotals.clear(); + + item_handler<post_t>::clear(); + } }; class transfer_details : public item_handler<post_t> @@ -595,6 +704,13 @@ public: } virtual void operator()(post_t& post); + + virtual void clear() { + expr.mark_uncompiled(); + temps.clear(); + + item_handler<post_t>::clear(); + } }; class dow_posts : public subtotal_posts @@ -616,6 +732,13 @@ public: virtual void operator()(post_t& post) { days_of_the_week[post.date().day_of_week()].push_back(&post); } + + virtual void clear() { + for (int i = 0; i < 7; i++) + days_of_the_week[i].clear(); + + item_handler<post_t>::clear(); + } }; class generate_posts : public item_handler<post_t> @@ -642,6 +765,13 @@ public: void add_period_xacts(period_xacts_list& period_xacts); virtual void add_post(const date_interval_t& period, post_t& post); + + virtual void clear() { + pending_posts.clear(); + temps.clear(); + + item_handler<post_t>::clear(); + } }; class budget_posts : public generate_posts @@ -692,6 +822,11 @@ class forecast_posts : public generate_posts virtual void add_post(const date_interval_t& period, post_t& post); virtual void flush(); + + virtual void clear() { + pred.mark_uncompiled(); + item_handler<post_t>::clear(); + } }; ////////////////////////////////////////////////////////////////////// @@ -717,6 +852,13 @@ public: virtual ~pass_down_accounts() { TRACE_DTOR(pass_down_accounts); } + + virtual void clear() { + if (pred) + pred->mark_uncompiled(); + + item_handler<account_t>::clear(); + } }; } // namespace ledger diff --git a/src/output.h b/src/output.h index 00c664c1..f0e7f9a5 100644 --- a/src/output.h +++ b/src/output.h @@ -75,6 +75,13 @@ public: virtual void flush(); virtual void operator()(post_t& post); + + virtual void clear() { + last_xact = NULL; + last_post = NULL; + + item_handler<post_t>::clear(); + } }; class format_accounts : public item_handler<account_t> @@ -105,6 +112,13 @@ public: virtual void flush(); virtual void operator()(account_t& account); + + virtual void clear() { + disp_pred.mark_uncompiled(); + posted_accounts.clear(); + + item_handler<account_t>::clear(); + } }; class report_accounts : public item_handler<post_t> @@ -126,6 +140,11 @@ public: virtual void flush(); virtual void operator()(post_t& post); + + virtual void clear() { + accounts.clear(); + item_handler<post_t>::clear(); + } }; class report_payees : public item_handler<post_t> @@ -147,6 +166,11 @@ public: virtual void flush(); virtual void operator()(post_t& post); + + virtual void clear() { + payees.clear(); + item_handler<post_t>::clear(); + } }; class report_commodities : public item_handler<post_t> @@ -168,6 +192,11 @@ public: virtual void flush(); virtual void operator()(post_t& post); + + virtual void clear() { + commodities.clear(); + item_handler<post_t>::clear(); + } }; } // namespace ledger diff --git a/src/temps.cc b/src/temps.cc index dcaa9101..7a630176 100644 --- a/src/temps.cc +++ b/src/temps.cc @@ -38,26 +38,6 @@ namespace ledger { -temporaries_t::~temporaries_t() -{ - if (post_temps) { - foreach (post_t& post, *post_temps) { - if (! post.xact->has_flags(ITEM_TEMP)) - post.xact->remove_post(&post); - - if (post.account && ! post.account->has_flags(ACCOUNT_TEMP)) - post.account->remove_post(&post); - } - } - - if (acct_temps) { - foreach (account_t& acct, *acct_temps) { - if (acct.parent && ! acct.parent->has_flags(ACCOUNT_TEMP)) - acct.parent->remove_account(&acct); - } - } -} - xact_t& temporaries_t::copy_xact(xact_t& origin) { if (! xact_temps) @@ -134,4 +114,29 @@ account_t& temporaries_t::create_account(const string& name, return temp; } +void temporaries_t::clear() +{ + if (post_temps) { + foreach (post_t& post, *post_temps) { + if (! post.xact->has_flags(ITEM_TEMP)) + post.xact->remove_post(&post); + + if (post.account && ! post.account->has_flags(ACCOUNT_TEMP)) + post.account->remove_post(&post); + } + post_temps->clear(); + } + + if (xact_temps) + xact_temps->clear(); + + if (acct_temps) { + foreach (account_t& acct, *acct_temps) { + if (acct.parent && ! acct.parent->has_flags(ACCOUNT_TEMP)) + acct.parent->remove_account(&acct); + } + acct_temps->clear(); + } +} + } // namespace ledger diff --git a/src/temps.h b/src/temps.h index ac6d08cd..210bbf63 100644 --- a/src/temps.h +++ b/src/temps.h @@ -51,7 +51,9 @@ class temporaries_t optional<std::list<account_t> > acct_temps; public: - ~temporaries_t(); + ~temporaries_t() { + clear(); + } xact_t& copy_xact(xact_t& origin); xact_t& create_xact(); @@ -69,6 +71,8 @@ public: account_t& last_account() { return acct_temps->back(); } + + void clear(); }; } // namespace ledger @@ -83,6 +83,14 @@ public: virtual void flush(); virtual void operator()(post_t& post); + + virtual void clear() { + commodities.clear(); + transactions_set.clear(); + transactions.clear(); + + item_handler<post_t>::clear(); + } }; } // namespace ledger |