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

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

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