From 599ff4a59af78af75639a05a3e87a29f81a29e2b Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 10 Apr 2008 12:36:58 +0000 Subject: Invocation handlers, see src/tests/amqp_0_10/handlers.cpp for example. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@646778 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/amqp_0_10/Holder.h | 50 +++++++++++++++++++++++++++++------------ cpp/src/qpid/amqp_0_10/Unit.h | 9 +++++--- 2 files changed, 42 insertions(+), 17 deletions(-) (limited to 'cpp/src/qpid') diff --git a/cpp/src/qpid/amqp_0_10/Holder.h b/cpp/src/qpid/amqp_0_10/Holder.h index 4c1fccd44f..1664afcc8f 100644 --- a/cpp/src/qpid/amqp_0_10/Holder.h +++ b/cpp/src/qpid/amqp_0_10/Holder.h @@ -27,29 +27,36 @@ namespace qpid { namespace amqp_0_10 { +using framing::in_place; + +template struct InvokeVisitor { + typedef void result_type; + Invokable& target; + InvokeVisitor(Invokable& i) : target(i) {} + + template + void operator()(const Action& action) { action.invoke(target); } +}; + template -struct Holder : public framing::Blob { +class Holder : public framing::Blob { typedef framing::Blob Base; - - struct Assign : public ApplyFunctor { - Holder& holder; - Assign(Holder& x) : holder(x) {} - template void operator()(const T& rhs) { holder=rhs; } - }; + public: + Holder() {} - Holder(const BaseHeld& x) { *this=x; } - template Holder(const T& value) : Base(value) {} + template explicit Holder(const T& value) : Base(value) {} using Base::operator=; - Holder& operator=(const BaseHeld& rhs) { - Assign assign(*this); - apply(assign, rhs); - return *this; - } + Holder& operator=(const BaseHeld& rhs); uint8_t getCode() const { return this->get()->getCode(); } uint8_t getClassCode() const { return this->get()->getClassCode(); } + + template void invoke(Invokable& i) const { + InvokeVisitor v(i); + apply(v, *this->get()); + } template void encode(S& s) const { s(getClassCode())(getCode()); @@ -65,8 +72,23 @@ struct Holder : public framing::Blob { s.split(*this); apply(s, *this->get()); } + + private: + struct Assign : public ApplyFunctor { + Holder& holder; + Assign(Holder& x) : holder(x) {} + template void operator()(const T& rhs) { holder=rhs; } + }; }; +template +Holder& Holder::operator=(const B& rhs) { + Assign assign(*this); + apply(assign, rhs); + return *this; +} + + }} // namespace qpid::amqp_0_10 diff --git a/cpp/src/qpid/amqp_0_10/Unit.h b/cpp/src/qpid/amqp_0_10/Unit.h index bcba36e35a..0229e07419 100644 --- a/cpp/src/qpid/amqp_0_10/Unit.h +++ b/cpp/src/qpid/amqp_0_10/Unit.h @@ -34,15 +34,12 @@ namespace qpid { namespace amqp_0_10 { - /** * A Unit contains a frame header and associated value. * For all types except BODY the frame header is for a complete segment. */ class Unit { public: - typedef boost::variant Variant; - explicit Unit(const FrameHeader& h=FrameHeader()) : header(h) { updateVariant(); } /** @@ -57,12 +54,18 @@ class Unit { template const T* get() const { return boost::get(&variant); } template T* get() { return boost::get(&variant); } template Unit& operator=(const T& t) { variant=t; return *this; } + + template typename V::result_type applyVisitor(V& v) const { + variant.apply_visitor(v); + } template void serialize(S& s) { variant.apply_visitor(s); s.split(*this); } template void encode(S&) const {} template void decode(S&) { updateHeader(header.getFlags()); } private: + typedef boost::variant Variant; + void updateHeader(uint8_t flags); void updateVariant(); -- cgit v1.2.1