/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/framing/Visitor.h

00001 #ifndef QPID_FRAMING_VISITOR_H
00002 #define QPID_FRAMING_VISITOR_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 
00024 #include <boost/mpl/vector.hpp>
00025 #include <boost/type_traits/remove_reference.hpp>
00026 #include <boost/preprocessor/seq/for_each.hpp>
00027 
00028 namespace qpid {
00029 namespace framing {
00030 
00038 template <class T, class R=void> struct Visit {
00039     typedef R ReturnType;
00040     typedef T VisitType;
00041     
00042     virtual ~Visit() {}
00043     virtual R visit(T&) = 0;
00044 };
00045 
00046 
00047 #define QPID_VISITOR_DECL(_1,_2,T) class T;
00048 
00049 #define QPID_VISITOR_BASE(_1,_2,T) , public ::qpid::framing::Visit<T>
00050 
00061 #define QPID_VISITOR(visitor,types) \
00062     BOOST_PP_SEQ_FOR_EACH(QPID_VISITOR_DECL, _, types) \
00063     class visitor : public ::qpid::framing::Visit<BOOST_PP_SEQ_HEAD(types)> \
00064     BOOST_PP_SEQ_FOR_EACH(QPID_VISITOR_BASE, _, BOOST_PP_SEQ_TAIL(types)) \
00065     {}
00066 
00070 template <class V, class R=void>
00071 struct VisitableRoot {
00072     typedef V VisitorType;
00073     typedef R ReturnType;
00074     virtual ~VisitableRoot() {}
00075     virtual R accept(V& v) = 0;
00076 };
00077 
00082 template <class T, class Base>
00083 struct Visitable : public Base {
00084     void accept(typename Base::VisitorType& v) {
00085         static_cast<Visit<T>& >(v).visit(static_cast<T&>(*this));
00086     }
00087 };
00088 
00089 }} // namespace qpid::framing
00090 
00091 #endif  

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7