Apache Qpid C++ API
Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation

qpid/framing/AMQHeaderBody.h

Go to the documentation of this file.
00001 #ifndef QPID_FRAMING_AMQHEADERBODY_H
00002 #define QPID_FRAMING_AMQHEADERBODY_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 #include "amqp_types.h"
00025 #include "AMQBody.h"
00026 #include "Buffer.h"
00027 #include "qpid/framing/DeliveryProperties.h"
00028 #include "qpid/framing/MessageProperties.h"
00029 #include <iostream>
00030 
00031 #include <boost/optional.hpp>
00032 
00033 
00034 namespace qpid {
00035 namespace framing {
00036 
00037 enum DeliveryMode { TRANSIENT = 1, PERSISTENT = 2};
00038 
00039 class AMQHeaderBody :  public AMQBody
00040 {
00041     template <class T> struct OptProps { boost::optional<T> props; };
00042     template <class Base, class T>
00043     struct PropSet : public Base, public OptProps<T> {
00044         uint32_t encodedSize() const {
00045             const boost::optional<T>& p=this->OptProps<T>::props;
00046             return (p ? p->encodedSize() : 0) + Base::encodedSize();
00047         }
00048         void encode(Buffer& buffer) const {
00049             const boost::optional<T>& p=this->OptProps<T>::props;
00050             if (p) p->encode(buffer);
00051             Base::encode(buffer);
00052         }
00053         bool decode(Buffer& buffer, uint32_t size, uint16_t type) {
00054             boost::optional<T>& p=this->OptProps<T>::props;
00055             if (type == T::TYPE) {
00056                 p=T();
00057                 p->decodeStructBody(buffer, size);
00058                 return true;
00059         }
00060             else
00061                 return Base::decode(buffer, size, type);
00062         }        
00063         void print(std::ostream& out) const {
00064             const boost::optional<T>& p=this->OptProps<T>::props;
00065             if (p) out << *p;
00066             Base::print(out);
00067         }
00068     };
00069 
00070     struct Empty {
00071         uint32_t encodedSize() const { return 0; }
00072         void encode(Buffer&) const {};
00073         bool decode(Buffer&, uint32_t, uint16_t) const { return false; };
00074         void print(std::ostream&) const {}
00075     };
00076 
00077     // Could use boost::mpl::fold to construct a larger set.
00078     typedef  PropSet<PropSet<Empty, DeliveryProperties>, MessageProperties> Properties;
00079 
00080     Properties properties;
00081     
00082 public:
00083 
00084     inline uint8_t type() const { return HEADER_BODY; }
00085 
00086     uint32_t encodedSize() const;
00087     void encode(Buffer& buffer) const;
00088     void decode(Buffer& buffer, uint32_t size);
00089     uint64_t getContentLength() const;
00090     void print(std::ostream& out) const;
00091     void accept(AMQBodyConstVisitor&) const;
00092 
00093     template <class T> T* get(bool create) {
00094         boost::optional<T>& p=properties.OptProps<T>::props;
00095         if (create && !p) p=T();
00096         return p.get_ptr();
00097     }
00098 
00099     template <class T> const T* get() const {
00100         return properties.OptProps<T>::props.get_ptr();
00101     }
00102 
00103     boost::intrusive_ptr<AMQBody> clone() const { return BodyFactory::copy(*this); }
00104 };
00105 
00106 }}
00107 
00108 
00109 
00110 #endif  

Qpid C++ API Reference
Generated on Tue Dec 8 15:39:48 2009 for Qpid C++ Client API by doxygen 1.4.7