00001 #ifndef QPID_FRAMING_BODYHOLDER_H
00002 #define QPID_FRAMING_BODYHOLDER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "qpid/framing/AMQBody.h"
00026 #include "qpid/framing/Blob.h"
00027 #include "qpid/framing/MaxMethodBodySize.h"
00028 #include "qpid/framing/amqp_types.h"
00029 #include "qpid/RefCounted.h"
00030
00031
00032 namespace qpid {
00033 namespace framing {
00034
00035 class AMQMethodBody;
00036 class AMQBody;
00037 class Buffer;
00038
00042 class BodyHolder : public RefCounted
00043 {
00044 public:
00045
00046 BodyHolder() {}
00047 BodyHolder(const AMQBody& b) { setBody(b); }
00048 BodyHolder(ClassId c, MethodId m) { setMethod(c,m); }
00049
00051 template <class InPlace>
00052 BodyHolder(const InPlace& ip, typename EnableInPlace<InPlace>::type* =0)
00053 : blob(ip) {}
00054
00055 void setBody(const AMQBody& b);
00056
00058 template <class InPlace>
00059 typename EnableInPlace<InPlace,BodyHolder&>::type
00060 operator=(const InPlace& ip) { blob=ip; return *this; }
00061
00063 template <class T>
00064 typename DisableInPlace<T,BodyHolder&>::type operator=(const T& x)
00065 { blob=in_place<T>(x); return *this; }
00066
00068 void setMethod(ClassId c, MethodId m);
00069
00070 void encode(Buffer&) const;
00071 void decode(uint8_t frameType, Buffer&, uint32_t=0);
00072 uint32_t size() const;
00073
00075 AMQBody* get() { return blob.get(); }
00076 const AMQBody* get() const { return blob.get(); }
00077
00079 AMQMethodBody* getMethod() { return get()->getMethod(); }
00080 const AMQMethodBody* getMethod() const { return get()->getMethod(); }
00081
00082 private:
00083 Blob<MAX_METHOD_BODY_SIZE, AMQBody> blob;
00084 };
00085
00086 }}
00087
00088 #endif