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 "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