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

qpid/framing/frame_functors.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
00019  *
00020  */
00021 #include <string>
00022 #include <ostream>
00023 #include <iostream>
00024 #include "qpid/framing/amqp_framing.h"
00025 #include "qpid/framing/AMQFrame.h"
00026 #include "qpid/framing/Buffer.h"
00027 
00028 #ifndef _frame_functors_
00029 #define _frame_functors_
00030 
00031 namespace qpid {
00032 namespace framing {
00033 
00034 class SumFrameSize
00035 {
00036     uint64_t size;
00037 public:
00038     SumFrameSize() : size(0) {}
00039     void operator()(const AMQFrame& f) { size += f.encodedSize(); }
00040     uint64_t getSize() { return size; }
00041 };
00042 
00043 class SumBodySize
00044 {
00045     uint64_t size;
00046 public:
00047     SumBodySize() : size(0) {}
00048     void operator()(const AMQFrame& f) { size += f.getBody()->encodedSize(); }
00049     uint64_t getSize() { return size; }
00050 };
00051 
00052 class Count
00053 {
00054     uint count;
00055 public:
00056     Count() : count(0) {}
00057     void operator()(const AMQFrame&) { count++; }
00058     uint getCount() { return count; }
00059 };
00060 
00061 class EncodeFrame
00062 {
00063     Buffer& buffer;
00064 public:
00065     EncodeFrame(Buffer& b) : buffer(b) {}
00066     void operator()(const AMQFrame& f) { f.encode(buffer); }
00067 };
00068 
00069 class EncodeBody
00070 {
00071     Buffer& buffer;
00072 public:
00073     EncodeBody(Buffer& b) : buffer(b) {}
00074     void operator()(const AMQFrame& f) { f.getBody()->encode(buffer); }
00075 };
00076 
00080 class Relay
00081 {
00082     FrameHandler& handler;
00083 
00084 public:
00085     Relay(FrameHandler& h) : handler(h) {}
00086 
00087     void operator()(const AMQFrame& f)
00088     {
00089         AMQFrame copy(f);
00090         handler.handle(copy);
00091     }
00092 };
00093 
00094 class Print
00095 {
00096     std::ostream& out;
00097 public:
00098     Print(std::ostream& o) : out(o) {}
00099 
00100     void operator()(const AMQFrame& f)
00101     {
00102         out << f << std::endl;
00103     }
00104 };
00105 
00106 class MarkLastSegment
00107 {
00108 public:
00109     void operator()(AMQFrame& f) const { f.setEof(true); }
00110 };
00111 
00112 }
00113 }
00114 
00115 
00116 #endif

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