/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/amqp_0_10/Unit.h

00001 #ifndef QPID_AMQP_0_10_UNIT_H
00002 #define QPID_AMQP_0_10_UNIT_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/amqp_0_10/ControlHolder.h"
00026 #include "qpid/amqp_0_10/CommandHolder.h"
00027 #include "qpid/amqp_0_10/Header.h"
00028 #include "qpid/amqp_0_10/Body.h"
00029 #include "qpid/amqp_0_10/FrameHeader.h"
00030 
00031 #include <boost/variant.hpp>
00032 #include <ostream>
00033 
00034 namespace qpid {
00035 namespace amqp_0_10 {
00036 
00041 class Unit {
00042   public:
00043     explicit Unit(const FrameHeader& h=FrameHeader()) : header(h) { updateVariant(); }
00044 
00048     template <class T>
00049     explicit Unit(const T& t, uint8_t flags=0) : variant(t) { updateHeader(flags); }
00050 
00051     void setHeader(FrameHeader& h) { header = h; updateVariant(); }
00052     const FrameHeader& getHeader() const { return header; }
00053 
00054     template<class T> const T* get() const { return boost::get<T>(&variant); }
00055     template<class T> T* get() { return boost::get<T>(&variant); }
00056     template<class T> Unit& operator=(const T& t) { variant=t; return *this; }
00057 
00058     template <class V> typename V::result_type applyVisitor(V& v) const {
00059         variant.apply_visitor(v); 
00060     }
00061     
00062     template <class S> void serialize(S& s) { variant.apply_visitor(s); s.split(*this); }
00063     template <class S> void encode(S&) const {} 
00064     template <class S> void decode(S&) { updateHeader(header.getFlags()); }
00065 
00066   private:
00067     typedef boost::variant<ControlHolder, CommandHolder, Header, Body> Variant;
00068 
00069     void updateHeader(uint8_t flags);
00070     void updateVariant();
00071     
00072     Variant variant;
00073     FrameHeader header;
00074 
00075   friend std::ostream& operator<<(std::ostream& o, const Unit& u);
00076 };
00077 
00078 std::ostream& operator<<(std::ostream& o, const Unit& u);
00079     
00080 }} // namespace qpid::amqp_0_10
00081 
00082 #endif  

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