diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-05 21:18:37 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-05 21:20:09 -0400 |
commit | 408b819c6e087593ba61e82b91dda2369ef32f62 (patch) | |
tree | 68456c86187e00355d47c5794008b8226bd000e2 /src/chain.h | |
parent | 7b24e8f8e33049fe533cce2d2d473c6122460954 (diff) | |
download | fork-ledger-408b819c6e087593ba61e82b91dda2369ef32f62.tar.gz fork-ledger-408b819c6e087593ba61e82b91dda2369ef32f62.tar.bz2 fork-ledger-408b819c6e087593ba61e82b91dda2369ef32f62.zip |
Greatly simplified the way option and command handlers are defined.
Diffstat (limited to 'src/chain.h')
-rw-r--r-- | src/chain.h | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/chain.h b/src/chain.h index c9199f05..c6de088f 100644 --- a/src/chain.h +++ b/src/chain.h @@ -46,10 +46,49 @@ #ifndef _CHAIN_H #define _CHAIN_H -#include "report.h" +#include "xact.h" +#include "account.h" namespace ledger { +/** + * @brief Brief + * + * Long. + */ +template <typename T> +struct item_handler : public noncopyable +{ + shared_ptr<item_handler> handler; + +public: + item_handler() { + TRACE_CTOR(item_handler, ""); + } + item_handler(shared_ptr<item_handler> _handler) : handler(_handler) { + TRACE_CTOR(item_handler, "shared_ptr<item_handler>"); + } + virtual ~item_handler() { + TRACE_DTOR(item_handler); + } + + virtual void flush() { + if (handler.get()) + handler->flush(); + } + virtual void operator()(T& item) { + if (handler.get()) { + check_for_signal(); + (*handler.get())(item); + } + } +}; + +typedef shared_ptr<item_handler<xact_t> > xact_handler_ptr; +typedef shared_ptr<item_handler<account_t> > acct_handler_ptr; + +class report_t; + xact_handler_ptr chain_xact_handlers(report_t& report, xact_handler_ptr base_handler, |