diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-12 05:09:25 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-12 05:11:06 -0500 |
commit | 48dc654eda27c01d0bad88674d21d0e33e5472f6 (patch) | |
tree | bfb05ee0d302c68b36942741f65fa0a243b0a96e /src | |
parent | 0068ac8fc06d00ba5172e5ddbd4f00cc4168681d (diff) | |
download | fork-ledger-48dc654eda27c01d0bad88674d21d0e33e5472f6.tar.gz fork-ledger-48dc654eda27c01d0bad88674d21d0e33e5472f6.tar.bz2 fork-ledger-48dc654eda27c01d0bad88674d21d0e33e5472f6.zip |
Added has_xdata() methods for journal_t and xact_t
Diffstat (limited to 'src')
-rw-r--r-- | src/account.cc | 13 | ||||
-rw-r--r-- | src/account.h | 1 | ||||
-rw-r--r-- | src/journal.cc | 20 | ||||
-rw-r--r-- | src/journal.h | 1 | ||||
-rw-r--r-- | src/py_journal.cc | 1 | ||||
-rw-r--r-- | src/py_xact.cc | 1 | ||||
-rw-r--r-- | src/xact.cc | 9 | ||||
-rw-r--r-- | src/xact.h | 1 |
8 files changed, 45 insertions, 2 deletions
diff --git a/src/account.cc b/src/account.cc index 5cc7e070..da43745a 100644 --- a/src/account.cc +++ b/src/account.cc @@ -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. diff --git a/src/account.h b/src/account.h index 0ac1aeb6..1e56fe23 100644 --- a/src/account.h +++ b/src/account.h @@ -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) diff --git a/src/journal.cc b/src/journal.cc index c764dbce..2366ce30 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -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) diff --git a/src/journal.h b/src/journal.h index 68fde517..f7124736 100644 --- a/src/journal.h +++ b/src/journal.h @@ -172,6 +172,7 @@ public: const path * original_file = NULL, bool strict = false); + bool has_xdata(); void clear_xdata(); bool valid() const; diff --git a/src/py_journal.cc b/src/py_journal.cc index 7fc1561d..51979438 100644 --- a/src/py_journal.cc +++ b/src/py_journal.cc @@ -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) diff --git a/src/py_xact.cc b/src/py_xact.cc index 81847656..59c599d9 100644 --- a/src/py_xact.cc +++ b/src/py_xact.cc @@ -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) diff --git a/src/xact.cc b/src/xact.cc index 86b55dd5..1cece187 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -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) @@ -80,6 +80,7 @@ public: bool finalize(); bool verify(); + bool has_xdata(); void clear_xdata(); virtual bool valid() const { |