From 408b819c6e087593ba61e82b91dda2369ef32f62 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 5 Feb 2009 21:18:37 -0400 Subject: Greatly simplified the way option and command handlers are defined. --- src/chain.h | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/chain.h') 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 +struct item_handler : public noncopyable +{ + shared_ptr handler; + +public: + item_handler() { + TRACE_CTOR(item_handler, ""); + } + item_handler(shared_ptr _handler) : handler(_handler) { + TRACE_CTOR(item_handler, "shared_ptr"); + } + 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 > xact_handler_ptr; +typedef shared_ptr > acct_handler_ptr; + +class report_t; + xact_handler_ptr chain_xact_handlers(report_t& report, xact_handler_ptr base_handler, -- cgit v1.2.3