00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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