summaryrefslogtreecommitdiff
path: root/journal.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-24 04:10:39 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-24 04:10:39 -0400
commit4f56735dfa83b4415be52793bcc99fa4623b69a5 (patch)
tree3ae80552ae3a909f8c7f207a65873b8bd7f54e3b /journal.cc
parentc715528f2f778a58b610d1e11cee2a5909b43d1f (diff)
downloadfork-ledger-4f56735dfa83b4415be52793bcc99fa4623b69a5.tar.gz
fork-ledger-4f56735dfa83b4415be52793bcc99fa4623b69a5.tar.bz2
fork-ledger-4f56735dfa83b4415be52793bcc99fa4623b69a5.zip
changed entry_finalizer scheme to use objects, not just function pointers
Diffstat (limited to 'journal.cc')
-rw-r--r--journal.cc44
1 files changed, 29 insertions, 15 deletions
diff --git a/journal.cc b/journal.cc
index af3f4832..4166d45e 100644
--- a/journal.cc
+++ b/journal.cc
@@ -360,6 +360,7 @@ journal_t::~journal_t()
{
DEBUG_PRINT("ledger.memory.dtors", "dtor journal_t");
+ delete default_finalizer;
delete master;
// Don't bother unhooking each entry's transactions from the
@@ -574,27 +575,42 @@ account_t * py_find_account_2(journal_t& journal, const std::string& name,
return journal.find_account(name, auto_create);
}
-#if 0
+struct py_entry_finalizer_t : public entry_finalizer_t {
+ object pyobj;
+ py_entry_finalizer_t() {}
+ py_entry_finalizer_t(object obj) : pyobj(obj) {}
+ py_entry_finalizer_t(const py_entry_finalizer_t& other)
+ : pyobj(other.pyobj) {}
+ virtual bool operator()(entry_t& entry) {
+ return call<bool>(pyobj.ptr(), entry);
+ }
+};
+
+std::list<py_entry_finalizer_t> py_finalizers;
-void py_add_entry_finalize_hook(journal_t& journal, object x)
+void py_add_entry_finalizer(journal_t& journal, object x)
{
- add_hook(journal.entry_finalize_hooks,
- extract<journal_t::entry_finalize_hook_t>(x));
+ py_finalizers.push_back(py_entry_finalizer_t(x));
+ add_hook<entry_finalizer_t *>(journal.entry_finalize_hooks,
+ &py_finalizers.back());
}
-void py_remove_entry_finalize_hook(journal_t& journal, object x)
+void py_remove_entry_finalizer(journal_t& journal, object x)
{
- remove_hook(journal.entry_finalize_hooks,
- extract<journal_t::entry_finalize_hook_t>(x));
+ for (std::list<py_entry_finalizer_t>::iterator i = py_finalizers.begin();
+ i != py_finalizers.end();
+ i++)
+ if ((*i).pyobj == x) {
+ remove_hook<entry_finalizer_t *>(journal.entry_finalize_hooks, &(*i));
+ return;
+ }
}
-void py_run_entry_finalize_hooks(journal_t& journal, entry_t& entry)
+void py_run_entry_finalizers(journal_t& journal, entry_t& entry)
{
run_hooks(journal.entry_finalize_hooks, entry);
}
-#endif
-
#define EXC_TRANSLATOR(type) \
void exc_translate_ ## type(const type& err) { \
PyErr_SetString(PyExc_RuntimeError, err.what()); \
@@ -682,11 +698,9 @@ void export_journal()
.def("add_entry", &journal_t::add_entry)
.def("remove_entry", &journal_t::remove_entry)
-#if 0
- .def("add_entry_finalize_hook", py_add_entry_finalize_hook)
- .def("remove_entry_finalize_hook", py_remove_entry_finalize_hook)
- .def("run_entry_finalize_hooks", py_run_entry_finalize_hooks)
-#endif
+ .def("add_entry_finalizer", py_add_entry_finalizer)
+ .def("remove_entry_finalizer", py_remove_entry_finalizer)
+ .def("run_entry_finalizers", py_run_entry_finalizers)
.def("valid", &journal_t::valid)
;