00001 #ifndef QPID_FRAMING_TEMPLATEVISITOR_H
00002 #define QPID_FRAMING_TEMPLATEVISITOR_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <boost/mpl/fold.hpp>
00024 #include <boost/utility/value_init.hpp>
00025
00026 namespace qpid {
00027 namespace framing {
00028
00038 template <class VisitTemplate, class TypeList, class F>
00039 class TemplateVisitor
00040 {
00041 struct Base : public VisitorBase {
00042 F action;
00043 Base(F f) : action(f) {}
00044 using VisitorBase::visit;
00045 };
00046
00047 template <class B, class T> struct Visit : public B {
00048 Visit(F action) : B(action) {}
00049 using B::visit;
00050 void visit(const T& body) { action(body); }
00051 };
00052
00053 typedef typename boost::mpl::fold<
00054 TypeList, Base, Visit<boost::mpl::placeholders::_1,
00055 boost::mpl::placeholders::_2>
00056 >::type type;
00057 };
00058
00064 template <class VisitorBase, class TypeList, class F>
00065 TemplateVisitor<VisitorBase,TypeList,F>::type make_visitor(F action) {
00066 return TemplateVisitor<VisitorBase,TypeList,F>::type(action);
00067 };
00068
00073 template <class TypeList, class Target>
00074 bool invoke(const AMQBody& body, Target& target) {
00075 typename InvokeVisitor<TypeList, Target>::type v(target);
00076 body.accept(v);
00077 return v.target;
00078 }
00079
00080 }}
00081
00082
00083 #endif
00085 }} // namespace qpid::framing
00086
00087
00088
00089 #endif