00001 #ifndef QPID_FRAMING_HANDLER_H
00002 #define QPID_FRAMING_HANDLER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "qpid/shared_ptr.h"
00025 #include <boost/type_traits/remove_reference.hpp>
00026 #include <assert.h>
00027
00028 namespace qpid {
00029 namespace framing {
00030
00031 template <class T>
00032 struct Handler {
00033 typedef T HandledType;
00034 typedef void handleFptr(T);
00035 typedef void result_type;
00036
00037 Handler(Handler<T>* next_=0) : next(next_) {}
00038 virtual ~Handler() {}
00039 virtual void handle(T) = 0;
00040
00042 void operator()(T t) { handle(t); }
00043
00044
00046 Handler<T>* next;
00047
00052 template <class F> class Functor : public Handler<T> {
00053 public:
00054 Functor(F f, Handler<T>* next=0) : Handler<T>(next), functor(f) {}
00055 void handle(T t) { functor(t); }
00056 private:
00057 F functor;
00058 };
00059
00063 template <class X, void (X::*F)(T)>
00064 class MemFunRef : public Handler<T> {
00065 public:
00066 MemFunRef(X& x, Handler<T>* next=0) : Handler(next), target(&x) {}
00067 void handle(T t) { (target->*F)(t); }
00068
00070 MemFunRef* operator->() { return this; }
00071
00072 private:
00073 X* target;
00074 };
00075
00080 class InOutHandlerInterface {
00081 public:
00082 virtual ~InOutHandlerInterface() {}
00083 virtual void handleIn(T) = 0;
00084 virtual void handleOut(T) = 0;
00085 };
00086
00090 struct InOutHandler : protected InOutHandlerInterface {
00091 InOutHandler(Handler<T>* nextIn=0, Handler<T>* nextOut=0) : in(*this, nextIn), out(*this, nextOut) {}
00092 MemFunRef<InOutHandlerInterface, &InOutHandlerInterface::handleIn> in;
00093 MemFunRef<InOutHandlerInterface, &InOutHandlerInterface::handleOut> out;
00094 };
00095 };
00096
00097
00098
00099 }}
00100 #endif
00101 //