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

00001 #ifndef QPID_AMQP_0_10_HOLDER_H
00002 #define QPID_AMQP_0_10_HOLDER_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 "qpid/framing/Blob.h"
00025 #include "apply.h"
00026 
00027 namespace qpid {
00028 namespace amqp_0_10 {
00029 
00030 using framing::in_place;
00031 
00032 template <class Invokable> struct InvokeVisitor {
00033     typedef void result_type;
00034     Invokable& target;     
00035     InvokeVisitor(Invokable& i) : target(i) {}
00036 
00037     template <class Action>
00038     void operator()(const Action& action) { action.invoke(target); }
00039 };
00040 
00041 template <class DerivedHolder, class BaseHeld, size_t Size>
00042 class Holder : public framing::Blob<Size, BaseHeld> {
00043     typedef framing::Blob<Size, BaseHeld> Base;
00044 
00045   public:
00046     
00047     Holder() {}
00048     template <class T> explicit Holder(const T& value) : Base(value) {}
00049 
00050     using Base::operator=;
00051     Holder& operator=(const BaseHeld& rhs);
00052     
00053     uint8_t getCode() const { return this->get()->getCode(); }
00054     uint8_t getClassCode() const { return this->get()->getClassCode(); }
00055 
00056     template <class Invokable> void invoke(Invokable& i) const {
00057         InvokeVisitor<Invokable> v(i);
00058         apply(v, *this->get());
00059     }
00060     
00061     template <class S> void encode(S& s) const {
00062         s(getClassCode())(getCode());
00063     }
00064 
00065     template <class S> void decode(S& s) {
00066         uint8_t code, classCode;
00067         s(classCode)(code);
00068         static_cast<DerivedHolder*>(this)->set(classCode, code);
00069     }
00070 
00071     template <class S> void serialize(S& s) {
00072         s.split(*this);
00073         apply(s, *this->get());
00074     }
00075 
00076   private:
00077     struct Assign : public ApplyFunctor<void> {
00078         Holder& holder;
00079         Assign(Holder& x) : holder(x) {}
00080         template <class T> void operator()(const T& rhs) { holder=rhs; }
00081     };
00082 };
00083 
00084 template <class D, class B, size_t S>
00085 Holder<D,B,S>& Holder<D,B,S>::operator=(const B& rhs) {
00086     Assign assign(*this);
00087     apply(assign, rhs);
00088     return *this;
00089 }
00090 
00091 
00092 
00093 }} // namespace qpid::amqp_0_10
00094 
00095 #endif  

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