summaryrefslogtreecommitdiff
path: root/cpp/src/qpid
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid')
-rw-r--r--cpp/src/qpid/amqp_0_10/Holder.h50
-rw-r--r--cpp/src/qpid/amqp_0_10/Unit.h9
2 files changed, 42 insertions, 17 deletions
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 <class Invokable> struct InvokeVisitor {
+ typedef void result_type;
+ Invokable& target;
+ InvokeVisitor(Invokable& i) : target(i) {}
+
+ template <class Action>
+ void operator()(const Action& action) { action.invoke(target); }
+};
+
template <class DerivedHolder, class BaseHeld, size_t Size>
-struct Holder : public framing::Blob<Size, BaseHeld> {
+class Holder : public framing::Blob<Size, BaseHeld> {
typedef framing::Blob<Size, BaseHeld> Base;
-
- struct Assign : public ApplyFunctor<void> {
- Holder& holder;
- Assign(Holder& x) : holder(x) {}
- template <class T> void operator()(const T& rhs) { holder=rhs; }
- };
+ public:
+
Holder() {}
- Holder(const BaseHeld& x) { *this=x; }
- template <class T> Holder(const T& value) : Base(value) {}
+ template <class T> 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 <class Invokable> void invoke(Invokable& i) const {
+ InvokeVisitor<Invokable> v(i);
+ apply(v, *this->get());
+ }
template <class S> void encode(S& s) const {
s(getClassCode())(getCode());
@@ -65,8 +72,23 @@ struct Holder : public framing::Blob<Size, BaseHeld> {
s.split(*this);
apply(s, *this->get());
}
+
+ private:
+ struct Assign : public ApplyFunctor<void> {
+ Holder& holder;
+ Assign(Holder& x) : holder(x) {}
+ template <class T> void operator()(const T& rhs) { holder=rhs; }
+ };
};
+template <class D, class B, size_t S>
+Holder<D,B,S>& Holder<D,B,S>::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<ControlHolder, CommandHolder, Header, Body> Variant;
-
explicit Unit(const FrameHeader& h=FrameHeader()) : header(h) { updateVariant(); }
/**
@@ -57,12 +54,18 @@ class Unit {
template<class T> const T* get() const { return boost::get<T>(&variant); }
template<class T> T* get() { return boost::get<T>(&variant); }
template<class T> Unit& operator=(const T& t) { variant=t; return *this; }
+
+ template <class V> typename V::result_type applyVisitor(V& v) const {
+ variant.apply_visitor(v);
+ }
template <class S> void serialize(S& s) { variant.apply_visitor(s); s.split(*this); }
template <class S> void encode(S&) const {}
template <class S> void decode(S&) { updateHeader(header.getFlags()); }
private:
+ typedef boost::variant<ControlHolder, CommandHolder, Header, Body> Variant;
+
void updateHeader(uint8_t flags);
void updateVariant();