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