00001 #ifndef QPID_FRAMING_VARIANT_H
00002 #define QPID_FRAMING_VARIANT_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00027 #include <boost/variant.hpp>
00028
00029 namespace qpid {
00030 namespace framing {
00031 class Buffer;
00032
00037 template <class R=void>
00038 struct NoBlankVisitor : public boost::static_visitor<R> {
00039 R foundBlank() const {
00040 assert(0);
00041 throw Exception(QPID_MSG("Invalid variant value."));
00042 }
00043 R operator()(const boost::blank&) const { return foundBlank(); }
00044 R operator()(boost::blank&) const { return foundBlank(); }
00045 };
00046
00047
00048 }}
00049
00050
00054 #define QPID_USING_NOBLANK(R) using ::qpid::framing::NoBlankVisitor<R>::operator()
00055
00056 namespace qpid {
00057 namespace framing {
00058
00060 template <class R> struct ConvertVisitor : public NoBlankVisitor<R> {
00061 QPID_USING_NOBLANK(R);
00062 template <class T> R operator()(T& t) const { return t; }
00063 };
00064
00066 template <class R> struct AddressVisitor : public NoBlankVisitor<R> {
00067 QPID_USING_NOBLANK(R);
00068 template <class T> R operator()(T& t) const { return &t; }
00069 };
00070
00072 template<class V>
00073 struct ApplyVisitor : public NoBlankVisitor<typename V::result_type> {
00074 QPID_USING_NOBLANK(typename V::result_type);
00075 const V& visitor;
00076 ApplyVisitor(const V& v) : visitor(v) {}
00077 template <class T> typename V::result_type operator()(T& t) const {
00078 return boost::apply_visitor(visitor, t);
00079 }
00080 };
00081
00083 template <class Visitor, class Visitable>
00084 typename Visitor::result_type applyApplyVisitor(const Visitor& visitor, Visitable& visitable) {
00085 return boost::apply_visitor(ApplyVisitor<Visitor>(visitor), visitable);
00086 }
00087
00088 }}
00089
00090
00091 #endif