summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-10 04:38:38 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-10 04:38:38 -0400
commit6261da4660a6602345c19d5a948124991bda86dc (patch)
treea3913dfa8dd403f8c32c27734b7a1cc73107afaf
parent359b3ba3266d440a99fc506212a2a03bd5be4de7 (diff)
downloadfork-ledger-6261da4660a6602345c19d5a948124991bda86dc.tar.gz
fork-ledger-6261da4660a6602345c19d5a948124991bda86dc.tar.bz2
fork-ledger-6261da4660a6602345c19d5a948124991bda86dc.zip
slight changed semantics of item_handler<T>, to play better with Boost.Python
-rw-r--r--main.cc67
-rw-r--r--main.py4
-rw-r--r--walk.cc36
-rw-r--r--walk.h2
4 files changed, 66 insertions, 43 deletions
diff --git a/main.cc b/main.cc
index ab26d0d7..b2a9e7b8 100644
--- a/main.cc
+++ b/main.cc
@@ -141,47 +141,50 @@ void parse_ledger_data(journal_t * journal,
item_handler<transaction_t> *
chain_formatters(const std::string& command,
- item_handler<transaction_t> * base_formatter)
+ item_handler<transaction_t> * base_formatter,
+ std::list<item_handler<transaction_t> *>& ptrs)
{
- std::auto_ptr<item_handler<transaction_t> > formatter;
+ item_handler<transaction_t> * formatter = NULL;
// format_transactions write each transaction received to the
// output stream.
if (command == "b" || command == "E") {
- formatter.reset(base_formatter);
+ ptrs.push_back(formatter = base_formatter);
} else {
- formatter.reset(base_formatter);
+ ptrs.push_back(formatter = base_formatter);
// filter_transactions will only pass through transactions
// matching the `display_predicate'.
if (! config.display_predicate.empty())
- formatter.reset(new filter_transactions(formatter.release(),
- config.display_predicate));
+ ptrs.push_back(formatter =
+ new filter_transactions(formatter,
+ config.display_predicate));
// calc_transactions computes the running total. When this
// appears will determine, for example, whether filtered
// transactions are included or excluded from the running total.
- formatter.reset(new calc_transactions(formatter.release(),
- config.show_inverted));
+ ptrs.push_back(formatter =
+ new calc_transactions(formatter, config.show_inverted));
// sort_transactions will sort all the transactions it sees, based
// on the `sort_order' value expression.
if (config.sort_order.get())
- formatter.reset(new sort_transactions(formatter.release(),
- config.sort_order.get()));
+ ptrs.push_back(formatter =
+ new sort_transactions(formatter, config.sort_order.get()));
// changed_value_transactions adds virtual transactions to the
// list to account for changes in market value of commodities,
// which otherwise would affect the running total unpredictably.
if (config.show_revalued)
- formatter.reset(new changed_value_transactions(formatter.release(),
- config.show_revalued_only));
+ ptrs.push_back(formatter =
+ new changed_value_transactions(formatter,
+ config.show_revalued_only));
// collapse_transactions causes entries with multiple transactions
// to appear as entries with a subtotaled transaction for each
// commodity used.
if (config.show_collapsed)
- formatter.reset(new collapse_transactions(formatter.release()));
+ ptrs.push_back(formatter = new collapse_transactions(formatter));
// subtotal_transactions combines all the transactions it receives
// into one subtotal entry, which has one transaction for each
@@ -195,13 +198,14 @@ chain_formatters(const std::string& command,
// reports all the transactions that fall on each subsequent day
// of the week.
if (config.show_subtotal)
- formatter.reset(new subtotal_transactions(formatter.release()));
+ ptrs.push_back(formatter = new subtotal_transactions(formatter));
else if (config.report_interval)
- formatter.reset(new interval_transactions(formatter.release(),
- config.report_interval,
- config.interval_begin));
+ ptrs.push_back(formatter =
+ new interval_transactions(formatter,
+ config.report_interval,
+ config.interval_begin));
else if (config.days_of_the_week)
- formatter.reset(new dow_transactions(formatter.release()));
+ ptrs.push_back(formatter = new dow_transactions(formatter));
}
// related_transactions will pass along all transactions related
@@ -210,16 +214,17 @@ chain_formatters(const std::string& command,
// one transaction of an entry is to be printed, all the
// transaction for that entry will be printed.
if (config.show_related)
- formatter.reset(new related_transactions(formatter.release(),
- config.show_all_related));
+ ptrs.push_back(formatter =
+ new related_transactions(formatter,
+ config.show_all_related));
// This filter_transactions will only pass through transactions
// matching the `predicate'.
if (! config.predicate.empty())
- formatter.reset(new filter_transactions(formatter.release(),
- config.predicate));
+ ptrs.push_back(formatter = new filter_transactions(formatter,
+ config.predicate));
- return formatter.release();
+ return formatter;
}
int parse_and_report(int argc, char * argv[], char * envp[])
@@ -306,15 +311,17 @@ int parse_and_report(int argc, char * argv[], char * envp[])
TIMER_START(report_gen);
- std::auto_ptr<item_handler<transaction_t> > formatter;
+ item_handler<transaction_t> * formatter;
+ std::list<item_handler<transaction_t> *> formatter_ptrs;
if (command == "b" || command == "E") {
- formatter.reset(chain_formatters(command, new set_account_value));
+ formatter = new set_account_value;
+ formatter = chain_formatters(command, formatter, formatter_ptrs);
} else {
std::ostream& out(config.output_stream.get() ?
*config.output_stream : std::cout);
- formatter.reset(chain_formatters(command,
- new format_transactions(out, config.format, config.nformat)));
+ formatter = new format_transactions(out, config.format, config.nformat);
+ formatter = chain_formatters(command, formatter, formatter_ptrs);
}
if (command == "e")
@@ -354,6 +361,12 @@ int parse_and_report(int argc, char * argv[], char * envp[])
}
#if DEBUG_LEVEL >= BETA
+ for (std::list<item_handler<transaction_t> *>::iterator i
+ = formatter_ptrs.begin();
+ i != formatter_ptrs.end();
+ i++)
+ delete *i;
+
// Cleanup the data handlers that might be present on some objects.
clear_transaction_data xact_cleanup;
diff --git a/main.py b/main.py
index 0a0919ca..b39193d3 100644
--- a/main.py
+++ b/main.py
@@ -24,8 +24,8 @@ class OutputTransaction (TransactionHandler):
print xact.entry.payee
handler = OutputTransaction()
-chain = FilterTransactions (handler, "/Checking/")
+handler = FilterTransactions (handler, "/Checking/")
for entry in journal:
for xact in entry:
- chain (xact)
+ handler (xact)
diff --git a/walk.cc b/walk.cc
index 0e0fd0ab..b80dfbc0 100644
--- a/walk.cc
+++ b/walk.cc
@@ -312,18 +312,19 @@ template <typename T>
struct item_handler_wrap : public item_handler<T>
{
PyObject* self;
+
item_handler_wrap(PyObject * self_) : self(self_) {}
item_handler_wrap(PyObject * self_, const item_handler<T>& handler)
: item_handler<T>(const_cast<item_handler<T> *>(&handler)), self(self_) {}
- void flush() {
+ virtual void flush() {
call_method<void>(self, "flush");
}
void default_flush() {
item_handler<T>::flush();
}
- void operator()(T& item) {
+ virtual void operator()(T& item) {
call_method<void>(self, "__call__", item);
}
void default_call(T& item) {
@@ -357,65 +358,76 @@ void export_walk()
;
class_< set_account_value >
- ("SetAccountValue", init<item_handler<transaction_t> *>())
+ ("SetAccountValue", init<item_handler<transaction_t> *>()
+ [with_custodian_and_ward<1, 2>()])
.def("flush", &item_handler<transaction_t>::flush)
.def("__call__", &set_account_value::operator());
;
#if 0
class_< sort_transactions >
- ("SortTransactions", init<item_handler<transaction_t> *>())
+ ("SortTransactions", init<item_handler<transaction_t> *>()
+ [with_custodian_and_ward<1, 2>()])
.def("flush", &sort_transactions::flush)
.def("__call__", &sort_transactions::operator());
;
#endif
class_< filter_transactions >
- ("FilterTransactions", init<item_handler<transaction_t> *, std::string>())
+ ("FilterTransactions", init<item_handler<transaction_t> *, std::string>()
+ [with_custodian_and_ward<1, 2>()])
.def("flush", &item_handler<transaction_t>::flush)
.def("__call__", &filter_transactions::operator());
;
class_< calc_transactions >
- ("CalcTransactions", init<item_handler<transaction_t> *, optional<bool> >())
+ ("CalcTransactions", init<item_handler<transaction_t> *, optional<bool> >()
+ [with_custodian_and_ward<1, 2>()])
.def("flush", &item_handler<transaction_t>::flush)
.def("__call__", &calc_transactions::operator());
;
class_< collapse_transactions >
- ("CollapseTransactions", init<item_handler<transaction_t> *>())
+ ("CollapseTransactions", init<item_handler<transaction_t> *>()
+ [with_custodian_and_ward<1, 2>()])
.def("flush", &collapse_transactions::flush)
.def("__call__", &collapse_transactions::operator());
;
class_< changed_value_transactions >
- ("ChangeValueTransactions", init<item_handler<transaction_t> *, bool>())
+ ("ChangeValueTransactions", init<item_handler<transaction_t> *, bool>()
+ [with_custodian_and_ward<1, 2>()])
.def("flush", &changed_value_transactions::flush)
.def("__call__", &changed_value_transactions::operator());
;
class_< subtotal_transactions >
- ("SubtotalTransactions", init<item_handler<transaction_t> *>())
+ ("SubtotalTransactions", init<item_handler<transaction_t> *>()
+ [with_custodian_and_ward<1, 2>()])
.def("flush", subtotal_transactions_flush)
.def("__call__", &subtotal_transactions::operator());
;
#if 0
class_< interval_transactions >
- ("IntervalTransactions", init<item_handler<transaction_t> *>())
+ ("IntervalTransactions", init<item_handler<transaction_t> *>()
+ [with_custodian_and_ward<1, 2>()])
.def("flush", &item_handler<transaction_t>::flush)
.def("__call__", &interval_transactions::operator());
;
#endif
class_< dow_transactions >
- ("DowTransactions", init<item_handler<transaction_t> *>())
+ ("DowTransactions", init<item_handler<transaction_t> *>()
+ [with_custodian_and_ward<1, 2>()])
.def("flush", &dow_transactions::flush)
.def("__call__", &dow_transactions::operator());
;
class_< related_transactions >
- ("RelatedTransactions", init<item_handler<transaction_t> *, optional<bool> >())
+ ("RelatedTransactions",
+ init<item_handler<transaction_t> *, optional<bool> >()
+ [with_custodian_and_ward<1, 2>()])
.def("flush", &item_handler<transaction_t>::flush)
.def("__call__", &related_transactions::operator());
;
diff --git a/walk.h b/walk.h
index d9946ed9..102ed10c 100644
--- a/walk.h
+++ b/walk.h
@@ -25,8 +25,6 @@ struct item_handler {
virtual ~item_handler() {
DEBUG_PRINT("ledger.memory.dtors", "dtor item_handler<T>");
- if (handler)
- delete handler;
}
virtual void flush() {
if (handler)