Apache Qpid C++ API
Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation

qpid/framing/TemplateVisitor.h

Go to the documentation of this file.
00001 #ifndef QPID_FRAMING_TEMPLATEVISITOR_H
00002 #define QPID_FRAMING_TEMPLATEVISITOR_H
00003 
00004 /*
00005  * Licensed to the Apache Software Foundation (ASF) under one
00006  * or more contributor license agreements.  See the NOTICE file
00007  * distributed with this work for additional information
00008  * regarding copyright ownership.  The ASF licenses this file
00009  * to you under the Apache License, Version 2.0 (the
00010  * "License"); you may not use this file except in compliance
00011  * with the License.  You may obtain a copy of the License at
00012  *
00013  *   http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  * Unless required by applicable law or agreed to in writing,
00016  * software distributed under the License is distributed on an
00017  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00018  * KIND, either express or implied.  See the License for the
00019  * specific language governing permissions and limitations
00020  * under the License.
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 }} // namespace qpid::framing
00081 
00082 
00083 #endif  
00085 }} // namespace qpid::framing
00086 
00087 
00088 
00089 #endif  

Qpid C++ API Reference
Generated on Tue Dec 8 15:39:48 2009 for Qpid C++ Client API by doxygen 1.4.7