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

qpid/framing/FrameSet.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 "qpid/InlineVector.h"
00023 #include "qpid/framing/amqp_framing.h"
00024 #include "qpid/framing/AMQFrame.h"
00025 #include "qpid/framing/SequenceNumber.h"
00026 
00027 #ifndef _FrameSet_
00028 #define _FrameSet_
00029 
00030 namespace qpid {
00031 namespace framing {
00032 
00036 class FrameSet
00037 {
00038     typedef InlineVector<AMQFrame, 4> Frames;
00039     const SequenceNumber id;
00040     Frames parts;
00041         mutable uint64_t contentSize;
00042         mutable bool recalculateSize;
00043 
00044 public:
00045     typedef boost::shared_ptr<FrameSet> shared_ptr;
00046 
00047     FrameSet(const SequenceNumber& id);
00048     void append(const AMQFrame& part);
00049     bool isComplete() const;
00050 
00051     uint64_t getContentSize() const;
00052 
00053     void getContent(std::string&) const;
00054     std::string getContent() const;
00055 
00056     bool isContentBearing() const;
00057 
00058     const AMQMethodBody* getMethod() const;
00059     const AMQHeaderBody* getHeaders() const;
00060     AMQHeaderBody* getHeaders();
00061      
00062     template <class T> bool isA() const {
00063         const AMQMethodBody* method = getMethod();
00064         return method && method->isA<T>();
00065     }
00066 
00067     template <class T> const T* as() const {
00068         const AMQMethodBody* method = getMethod();
00069         return (method && method->isA<T>()) ? dynamic_cast<const T*>(method) : 0;
00070     }    
00071 
00072     template <class T> const T* getHeaderProperties() const {
00073         const AMQHeaderBody* header = getHeaders();
00074         return header ? header->get<T>() : 0;
00075     }
00076 
00077     Frames::const_iterator begin() const { return parts.begin(); }
00078     Frames::const_iterator end() const { return parts.end(); }
00079     
00080     const SequenceNumber& getId() const { return id; }
00081 
00082     template <class P> void remove(P predicate) {
00083         parts.erase(std::remove_if(parts.begin(), parts.end(), predicate), parts.end());
00084     }
00085 
00086     template <class F> void map(F& functor) {
00087         std::for_each(parts.begin(), parts.end(), functor);
00088     }
00089 
00090     template <class F> void map(F& functor) const {
00091         std::for_each(parts.begin(), parts.end(), functor);
00092     }
00093 
00094     template <class F, class P> void map_if(F& functor, P predicate) {
00095         for(Frames::iterator i = parts.begin(); i != parts.end(); i++) {
00096             if (predicate(*i)) functor(*i);
00097         }
00098     }
00099 
00100     template <class F, class P> void map_if(F& functor, P predicate) const {
00101         for(Frames::const_iterator i = parts.begin(); i != parts.end(); i++) {
00102             if (predicate(*i)) functor(*i);
00103         }
00104     }
00105 };
00106 
00107 }
00108 }
00109 
00110 
00111 #endif

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