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

qpid/framing/Handler.h

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

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