summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/account.h20
-rw-r--r--src/journal.h26
-rw-r--r--src/py_account.cc9
-rw-r--r--src/py_journal.cc12
-rw-r--r--src/py_xact.cc9
-rw-r--r--src/system.hh.in1
-rw-r--r--src/xact.h7
7 files changed, 78 insertions, 6 deletions
diff --git a/src/account.h b/src/account.h
index 7d51a08e..3452bba7 100644
--- a/src/account.h
+++ b/src/account.h
@@ -114,11 +114,31 @@ public:
account_t * find_account(const string& name, bool auto_create = true);
account_t * find_account_re(const string& regexp);
+ typedef transform_iterator<function<account_t *(accounts_map::value_type&)>,
+ accounts_map::iterator>
+ accounts_map_seconds_iterator;
+
+ accounts_map_seconds_iterator accounts_begin() {
+ return make_transform_iterator
+ (accounts.begin(), bind(&accounts_map::value_type::second, _1));
+ }
+ accounts_map_seconds_iterator accounts_end() {
+ return make_transform_iterator
+ (accounts.end(), bind(&accounts_map::value_type::second, _1));
+ }
+
void add_post(post_t * post) {
posts.push_back(post);
}
bool remove_post(post_t * post);
+ posts_list::iterator posts_begin() {
+ return posts.begin();
+ }
+ posts_list::iterator posts_end() {
+ return posts.end();
+ }
+
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
diff --git a/src/journal.h b/src/journal.h
index 7a7c4ec9..551f9142 100644
--- a/src/journal.h
+++ b/src/journal.h
@@ -128,6 +128,13 @@ public:
journal_t();
~journal_t();
+ std::list<fileinfo_t>::iterator sources_begin() {
+ return sources.begin();
+ }
+ std::list<fileinfo_t>::iterator sources_end() {
+ return sources.end();
+ }
+
// These four methods are delegated to the current session, since all
// accounts processed are gathered together at the session level.
void add_account(account_t * acct);
@@ -138,6 +145,25 @@ public:
bool add_xact(xact_t * xact);
bool remove_xact(xact_t * xact);
+ xacts_list::iterator xacts_begin() {
+ return xacts.begin();
+ }
+ xacts_list::iterator xacts_end() {
+ return xacts.end();
+ }
+ auto_xacts_list::iterator auto_xacts_begin() {
+ return auto_xacts.begin();
+ }
+ auto_xacts_list::iterator auto_xacts_end() {
+ return auto_xacts.end();
+ }
+ period_xacts_list::iterator period_xacts_begin() {
+ return period_xacts.begin();
+ }
+ period_xacts_list::iterator period_xacts_end() {
+ return period_xacts.end();
+ }
+
void add_xact_finalizer(xact_finalizer_t * finalizer) {
xact_finalize_hooks.add_hook(finalizer);
}
diff --git a/src/py_account.cc b/src/py_account.cc
index 7fa30d0a..3341c948 100644
--- a/src/py_account.cc
+++ b/src/py_account.cc
@@ -177,8 +177,6 @@ void export_account()
.def_readwrite("name", &account_t::name)
.def_readwrite("note", &account_t::note)
.def_readonly("depth", &account_t::depth)
- .def_readonly("accounts", &account_t::accounts)
- .def_readonly("posts", &account_t::posts)
.def(self_ns::str(self))
@@ -201,6 +199,13 @@ void export_account()
.def("__len__", accounts_len)
.def("__getitem__", accounts_getitem, return_internal_reference<1>())
+ .def("__iter__", range<return_internal_reference<> >
+ (&account_t::accounts_begin, &account_t::accounts_end))
+ .def("accounts", range<return_internal_reference<> >
+ (&account_t::accounts_begin, &account_t::accounts_end))
+ .def("posts", range<return_internal_reference<> >
+ (&account_t::posts_begin, &account_t::posts_end))
+
.def("has_xdata", &account_t::has_xdata)
.def("clear_xdata", &account_t::clear_xdata)
.def("xdata", py_xdata,
diff --git a/src/py_journal.cc b/src/py_journal.cc
index 873645d3..0f800077 100644
--- a/src/py_journal.cc
+++ b/src/py_journal.cc
@@ -192,7 +192,6 @@ void export_journal()
make_getter(&journal_t::basket,
return_internal_reference<1>()),
make_setter(&journal_t::basket))
- .add_property("sources", make_getter(&journal_t::sources))
.add_property("was_loaded", make_getter(&journal_t::was_loaded))
.add_property("commodity_pool",
make_getter(&journal_t::commodity_pool,
@@ -221,6 +220,17 @@ void export_journal()
.def("__len__", xacts_len)
.def("__getitem__", xacts_getitem, return_internal_reference<1>())
+ .def("__iter__", range<return_internal_reference<> >
+ (&journal_t::xacts_begin, &journal_t::xacts_end))
+ .def("xacts", range<return_internal_reference<> >
+ (&journal_t::xacts_begin, &journal_t::xacts_end))
+ .def("auto_xacts", range<return_internal_reference<> >
+ (&journal_t::auto_xacts_begin, &journal_t::auto_xacts_end))
+ .def("period_xacts", range<return_internal_reference<> >
+ (&journal_t::period_xacts_begin, &journal_t::period_xacts_end))
+ .def("sources", range<return_internal_reference<> >
+ (&journal_t::sources_begin, &journal_t::sources_end))
+
.def("valid", &journal_t::valid)
;
}
diff --git a/src/py_xact.cc b/src/py_xact.cc
index d98d226c..3755dcd1 100644
--- a/src/py_xact.cc
+++ b/src/py_xact.cc
@@ -88,9 +88,6 @@ void export_xact()
return_value_policy<reference_existing_object>()),
make_setter(&xact_base_t::journal,
with_custodian_and_ward<1, 2>()))
- .add_property("posts",
- make_getter(&xact_base_t::posts),
- make_setter(&xact_base_t::posts))
.def("__len__", posts_len)
.def("__getitem__", posts_getitem,
@@ -100,6 +97,12 @@ void export_xact()
.def("remove_post", &xact_base_t::add_post)
.def("finalize", &xact_base_t::finalize)
+
+ .def("__iter__", range<return_internal_reference<> >
+ (&xact_t::posts_begin, &xact_t::posts_end))
+ .def("posts", range<return_internal_reference<> >
+ (&xact_t::posts_begin, &xact_t::posts_end))
+
.def("valid", &xact_base_t::valid)
;
diff --git a/src/system.hh.in b/src/system.hh.in
index 4a7dc55f..96febb22 100644
--- a/src/system.hh.in
+++ b/src/system.hh.in
@@ -155,6 +155,7 @@ typedef std::ostream::pos_type ostream_pos_type;
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/write.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
+#include <boost/iterator/transform_iterator.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/operators.hpp>
#include <boost/optional.hpp>
diff --git a/src/xact.h b/src/xact.h
index 07fc68f5..337abce8 100644
--- a/src/xact.h
+++ b/src/xact.h
@@ -77,6 +77,13 @@ public:
virtual void add_post(post_t * post);
virtual bool remove_post(post_t * post);
+ posts_list::iterator posts_begin() {
+ return posts.begin();
+ }
+ posts_list::iterator posts_end() {
+ return posts.end();
+ }
+
virtual bool finalize();
virtual bool valid() const {
return true;