Added has_xdata() methods for journal_t and xact_t

This commit is contained in:
John Wiegley 2009-11-12 05:09:25 -05:00
parent 0068ac8fc0
commit 48dc654eda
8 changed files with 45 additions and 2 deletions

View file

@ -327,16 +327,25 @@ bool account_t::valid() const
return true;
}
bool account_t::children_with_xdata() const
{
foreach (const accounts_map::value_type& pair, accounts)
if (pair.second->has_xdata() ||
pair.second->children_with_xdata())
return true;
return false;
}
std::size_t account_t::children_with_flags(xdata_t::flags_t flags) const
{
std::size_t count = 0;
bool grandchildren_visited = false;
foreach (const accounts_map::value_type& pair, accounts) {
foreach (const accounts_map::value_type& pair, accounts)
if (pair.second->has_xflags(flags) ||
pair.second->children_with_flags(flags))
count++;
}
// Although no immediately children were visited, if any progeny at all were
// visited, it counts as one.

View file

@ -241,6 +241,7 @@ public:
bool has_xflags(xdata_t::flags_t flags) const {
return xdata_ && xdata_->has_flags(flags);
}
bool children_with_xdata() const;
std::size_t children_with_flags(xdata_t::flags_t flags) const;
#if defined(HAVE_BOOST_SERIALIZATION)

View file

@ -211,6 +211,26 @@ std::size_t journal_t::read(const path& pathname,
return count;
}
bool journal_t::has_xdata()
{
foreach (xact_t * xact, xacts)
if (xact->has_xdata())
return true;
foreach (auto_xact_t * xact, auto_xacts)
if (xact->has_xdata())
return true;
foreach (period_xact_t * xact, period_xacts)
if (xact->has_xdata())
return true;
if (master->has_xdata() || master->children_with_xdata())
return true;
return false;
}
void journal_t::clear_xdata()
{
foreach (xact_t * xact, xacts)

View file

@ -172,6 +172,7 @@ public:
const path * original_file = NULL,
bool strict = false);
bool has_xdata();
void clear_xdata();
bool valid() const;

View file

@ -197,6 +197,7 @@ void export_journal()
.def("read", py_read)
.def("has_xdata", &journal_t::has_xdata)
.def("clear_xdata", &journal_t::clear_xdata)
.def("valid", &journal_t::valid)

View file

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

View file

@ -76,6 +76,15 @@ bool xact_base_t::remove_post(post_t * post)
return true;
}
bool xact_base_t::has_xdata()
{
foreach (post_t * post, posts)
if (post->has_xdata())
return true;
return false;
}
void xact_base_t::clear_xdata()
{
foreach (post_t * post, posts)

View file

@ -80,6 +80,7 @@ public:
bool finalize();
bool verify();
bool has_xdata();
void clear_xdata();
virtual bool valid() const {