diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-05 02:23:49 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-05 02:27:39 -0500 |
commit | 3dc200983d5057a7760aeb9e864479c902d7e1d7 (patch) | |
tree | 6f754a113f97af3dd856cd7e507f91da9e9e0402 | |
parent | 40a430139edd12d9f580f5616571bc3ed8709d73 (diff) | |
download | fork-ledger-3dc200983d5057a7760aeb9e864479c902d7e1d7.tar.gz fork-ledger-3dc200983d5057a7760aeb9e864479c902d7e1d7.tar.bz2 fork-ledger-3dc200983d5057a7760aeb9e864479c902d7e1d7.zip |
Moved xdata clearing code into each type proper
-rw-r--r-- | src/account.cc | 9 | ||||
-rw-r--r-- | src/account.h | 4 | ||||
-rw-r--r-- | src/filters.h | 26 | ||||
-rw-r--r-- | src/journal.cc | 17 | ||||
-rw-r--r-- | src/journal.h | 2 | ||||
-rw-r--r-- | src/precmd.cc | 2 | ||||
-rw-r--r-- | src/py_journal.cc | 2 | ||||
-rw-r--r-- | src/py_xact.cc | 2 | ||||
-rw-r--r-- | src/report.cc | 9 | ||||
-rw-r--r-- | src/session.cc | 19 | ||||
-rw-r--r-- | src/session.h | 8 | ||||
-rw-r--r-- | src/xact.cc | 7 | ||||
-rw-r--r-- | src/xact.h | 3 |
13 files changed, 48 insertions, 62 deletions
diff --git a/src/account.cc b/src/account.cc index 2a75a6ac..43b7cd56 100644 --- a/src/account.cc +++ b/src/account.cc @@ -382,6 +382,15 @@ account_t::xdata_t::details_t::operator+=(const details_t& other) return *this; } +void account_t::clear_xdata() +{ + xdata_ = none; + + foreach (accounts_map::value_type& pair, accounts) + if (! pair.second->has_flags(ACCOUNT_TEMP)) + pair.second->clear_xdata(); +} + value_t account_t::amount(const optional<expr_t&>& expr) const { if (xdata_ && xdata_->has_flags(ACCOUNT_EXT_VISITED)) { diff --git a/src/account.h b/src/account.h index 3452bba7..dc1d6c9a 100644 --- a/src/account.h +++ b/src/account.h @@ -230,9 +230,7 @@ public: bool has_xdata() const { return xdata_; } - void clear_xdata() { - xdata_ = none; - } + void clear_xdata(); xdata_t& xdata() { if (! xdata_) xdata_ = xdata_t(); diff --git a/src/filters.h b/src/filters.h index 0dcf5e41..42503945 100644 --- a/src/filters.h +++ b/src/filters.h @@ -70,19 +70,6 @@ public: virtual void operator()(post_t&) {} }; -/** - * @brief Brief - * - * Long. - */ -class clear_post_xdata : public item_handler<post_t> -{ -public: - virtual void operator()(post_t& post) { - post.clear_xdata(); - } -}; - class posts_iterator; /** @@ -790,19 +777,6 @@ class forecast_posts : public generate_posts // Account filters // -/** - * @brief Brief - * - * Long. - */ -class clear_account_xdata : public item_handler<account_t> -{ -public: - virtual void operator()(account_t& acct) { - acct.clear_xdata(); - } -}; - class accounts_iterator; /** diff --git a/src/journal.cc b/src/journal.cc index 4b5172f5..4d6e084e 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -134,6 +134,23 @@ bool journal_t::remove_xact(xact_t * xact) return true; } +void journal_t::clear_xdata() +{ + foreach (xact_t * xact, xacts) + if (! xact->has_flags(ITEM_TEMP)) + xact->clear_xdata(); + + foreach (auto_xact_t * xact, auto_xacts) + if (! xact->has_flags(ITEM_TEMP)) + xact->clear_xdata(); + + foreach (period_xact_t * xact, period_xacts) + if (! xact->has_flags(ITEM_TEMP)) + xact->clear_xdata(); + + master->clear_xdata(); +} + bool journal_t::valid() const { if (! master->valid()) { diff --git a/src/journal.h b/src/journal.h index 551f9142..60d703e6 100644 --- a/src/journal.h +++ b/src/journal.h @@ -177,6 +177,8 @@ public: const path * original_file = NULL, bool strict = false); + void clear_xdata(); + bool valid() const; #if defined(HAVE_BOOST_SERIALIZATION) diff --git a/src/precmd.cc b/src/precmd.cc index 479d7c2d..4cf541f4 100644 --- a/src/precmd.cc +++ b/src/precmd.cc @@ -67,7 +67,7 @@ namespace { { std::istringstream in(str); report.session.journal->parse(in, report.session); - report.session.clean_accounts(); + report.session.journal->clear_xdata(); } } xact_t * first = report.session.journal->xacts.front(); diff --git a/src/py_journal.cc b/src/py_journal.cc index 0f800077..bc79101b 100644 --- a/src/py_journal.cc +++ b/src/py_journal.cc @@ -231,6 +231,8 @@ void export_journal() .def("sources", range<return_internal_reference<> > (&journal_t::sources_begin, &journal_t::sources_end)) + .def("clear_xdata", &journal_t::clear_xdata) + .def("valid", &journal_t::valid) ; } diff --git a/src/py_xact.cc b/src/py_xact.cc index 3755dcd1..86e2e067 100644 --- a/src/py_xact.cc +++ b/src/py_xact.cc @@ -122,6 +122,8 @@ void export_xact() .def("lookup", &xact_t::lookup) + .def("clear_xdata", &xact_t::clear_xdata) + .def("valid", &xact_t::valid) ; diff --git a/src/report.cc b/src/report.cc index 883b324a..e6f3ccb4 100644 --- a/src/report.cc +++ b/src/report.cc @@ -50,7 +50,7 @@ void report_t::posts_report(post_handler_ptr handler) { journal_posts_iterator walker(*session.journal.get()); pass_down_posts(chain_post_handlers(*this, handler), walker); - session.clean_posts(); + session.journal->clear_xdata(); } void report_t::generate_report(post_handler_ptr handler) @@ -70,7 +70,7 @@ void report_t::xact_report(post_handler_ptr handler, xact_t& xact) { xact_posts_iterator walker(xact); pass_down_posts(chain_post_handlers(*this, handler), walker); - session.clean_posts(xact); + xact.clear_xdata(); } void report_t::accounts_report(acct_handler_ptr handler) @@ -101,15 +101,14 @@ void report_t::accounts_report(acct_handler_ptr handler) else pass_down_accounts(handler, *iter.get()); - session.clean_posts(); - session.clean_accounts(); + session.journal->clear_xdata(); } void report_t::commodities_report(post_handler_ptr handler) { posts_commodities_iterator walker(*session.journal.get()); pass_down_posts(chain_post_handlers(*this, handler), walker); - session.clean_posts(); + session.journal->clear_xdata(); } value_t report_t::fn_amount_expr(call_scope_t& scope) diff --git a/src/session.cc b/src/session.cc index 67f19ca9..8cbef1e6 100644 --- a/src/session.cc +++ b/src/session.cc @@ -224,25 +224,6 @@ void session_t::close_journal_files() amount_t::initialize(journal->commodity_pool); } -void session_t::clean_posts() -{ - journal_posts_iterator walker(*journal.get()); - pass_down_posts(post_handler_ptr(new clear_post_xdata), walker); -} - -void session_t::clean_posts(xact_t& xact) -{ - xact_posts_iterator walker(xact); - pass_down_posts(post_handler_ptr(new clear_post_xdata), walker); -} - -void session_t::clean_accounts() -{ - basic_accounts_iterator acct_walker(*journal->master); - pass_down_accounts(acct_handler_ptr(new clear_account_xdata), acct_walker); - journal->master->clear_xdata(); -} - option_t<session_t> * session_t::lookup_option(const char * p) { switch (*p) { diff --git a/src/session.h b/src/session.h index 972a97ba..8e73b660 100644 --- a/src/session.h +++ b/src/session.h @@ -93,14 +93,6 @@ public: void read_journal_files(); void close_journal_files(); - void clean_posts(); - void clean_posts(xact_t& xact); - void clean_accounts(); - void clean_all() { - clean_posts(); - clean_accounts(); - } - void report_options(std::ostream& out) { HANDLER(account_).report(out); diff --git a/src/xact.cc b/src/xact.cc index 473837b6..9e5f504e 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -76,6 +76,13 @@ bool xact_base_t::remove_post(post_t * post) return true; } +void xact_base_t::clear_xdata() +{ + foreach (post_t * post, posts) + if (! post->has_flags(ITEM_TEMP)) + post->clear_xdata(); +} + bool xact_base_t::finalize() { // Scan through and compute the total balance for the xact. This is used @@ -85,6 +85,9 @@ public: } virtual bool finalize(); + + void clear_xdata(); + virtual bool valid() const { return true; } |