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

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

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