7 #ifndef CPPWAMP_VISITOR_HPP
8 #define CPPWAMP_VISITOR_HPP
17 #include <type_traits>
28 template <
typename TResult =
void>
42 template <
typename TVisitor>
43 using ResultTypeOf =
typename std::remove_reference<TVisitor>::type::Result;
51 template <
typename V,
typename T>
61 template <
typename V,
typename L,
typename R>
73 template <
typename V,
typename T,
typename O>
85 template <
typename V,
typename T>
89 using I = decltype(variant.typeId());
90 switch (variant.typeId())
92 case I::null:
return forward<V>(visitor)(variant.template as<I::null>());
93 case I::boolean:
return forward<V>(visitor)(variant.template as<I::boolean>());
94 case I::integer:
return forward<V>(visitor)(variant.template as<I::integer>());
95 case I::uint:
return forward<V>(visitor)(variant.template as<I::uint>());
96 case I::real:
return forward<V>(visitor)(variant.template as<I::real>());
97 case I::string:
return forward<V>(visitor)(variant.template as<I::string>());
98 case I::blob:
return forward<V>(visitor)(variant.template as<I::blob>());
99 case I::array:
return forward<V>(visitor)(variant.template as<I::array>());
100 case I::object:
return forward<V>(visitor)(variant.template as<I::object>());
101 default: assert(
false);
105 return visitor(variant.template as<I::null>());
109 template <
typename V,
typename L,
typename R>
113 using I = decltype(l.typeId());
117 case I::null:
return applyWithOperand(forward<V>(v), forward<L>(l), r.template as<I::null>());
118 case I::boolean:
return applyWithOperand(forward<V>(v), forward<L>(l), r.template as<I::boolean>());
119 case I::integer:
return applyWithOperand(forward<V>(v), forward<L>(l), r.template as<I::integer>());
120 case I::uint:
return applyWithOperand(forward<V>(v), forward<L>(l), r.template as<I::uint>());
121 case I::real:
return applyWithOperand(forward<V>(v), forward<L>(l), r.template as<I::real>());
122 case I::string:
return applyWithOperand(forward<V>(v), forward<L>(l), r.template as<I::string>());
123 case I::blob:
return applyWithOperand(forward<V>(v), forward<L>(l), r.template as<I::blob>());
124 case I::array:
return applyWithOperand(forward<V>(v), forward<L>(l), r.template as<I::array>());
125 case I::object:
return applyWithOperand(forward<V>(v), forward<L>(l), r.template as<I::object>());
126 default: assert(
false);
130 return applyWithOperand(forward<V>(v), forward<L>(l),
131 r.template as<I::null>());
135 template <
typename V,
typename T,
typename O>
139 using I = decltype(l.typeId());
143 case I::null:
return forward<V>(v)(l.template as<I::null>(), forward<O>(o));
144 case I::boolean:
return forward<V>(v)(l.template as<I::boolean>(), forward<O>(o));
145 case I::integer:
return forward<V>(v)(l.template as<I::integer>(), forward<O>(o));
146 case I::uint:
return forward<V>(v)(l.template as<I::uint>(), forward<O>(o));
147 case I::real:
return forward<V>(v)(l.template as<I::real>(), forward<O>(o));
148 case I::string:
return forward<V>(v)(l.template as<I::string>(), forward<O>(o));
149 case I::blob:
return forward<V>(v)(l.template as<I::blob>(), forward<O>(o));
150 case I::array:
return forward<V>(v)(l.template as<I::array>(), forward<O>(o));
151 case I::object:
return forward<V>(v)(l.template as<I::object>(), forward<O>(o));
152 default: assert(
false);
156 return forward<V>(v)(l.template as<I::null>(), forward<O>(o));
161 #endif // CPPWAMP_VISITOR_HPP