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

00001 #ifndef QPID_FRAMING_BODYHOLDER_H
00002 #define QPID_FRAMING_BODYHOLDER_H
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 
00025 #include "qpid/framing/AMQBody.h"
00026 #include "qpid/framing/Blob.h"
00027 #include "qpid/framing/MaxMethodBodySize.h" // Generated file.
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     // default copy, assign dtor ok.
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 }} // namespace qpid::framing
00087 
00088 #endif  

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