Moved xdata clearing code into each type proper

This commit is contained in:
John Wiegley 2009-11-05 02:23:49 -05:00
parent 40a430139e
commit 3dc200983d
13 changed files with 48 additions and 62 deletions

View file

@ -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)) {

View file

@ -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();

View file

@ -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;
/**

View file

@ -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()) {

View file

@ -177,6 +177,8 @@ public:
const path * original_file = NULL,
bool strict = false);
void clear_xdata();
bool valid() const;
#if defined(HAVE_BOOST_SERIALIZATION)

View file

@ -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();

View file

@ -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)
;
}

View file

@ -122,6 +122,8 @@ void export_xact()
.def("lookup", &xact_t::lookup)
.def("clear_xdata", &xact_t::clear_xdata)
.def("valid", &xact_t::valid)
;

View file

@ -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)

View file

@ -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) {

View file

@ -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);

View file

@ -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

View file

@ -85,6 +85,9 @@ public:
}
virtual bool finalize();
void clear_xdata();
virtual bool valid() const {
return true;
}