5 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP
12 #define BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/push_options.hpp>
20 #include <boost/asio/detail/push_options.hpp>
21 #include <boost/type_traits.hpp>
22 #include <boost/asio/detail/pop_options.hpp>
24 #include <boost/asio/detail/bind_handler.hpp>
25 #include <boost/asio/detail/handler_alloc_helpers.hpp>
26 #include <boost/asio/detail/handler_invoke_helpers.hpp>
32 template <typename Dispatcher
, typename Handler
>
36 typedef void result_type
;
39 typename
boost::add_reference
<Dispatcher
>::type dispatcher
,
41 : dispatcher_(dispatcher
),
48 dispatcher_
.dispatch(handler_
);
51 void operator()() const
53 dispatcher_
.dispatch(handler_
);
56 template <typename Arg1
>
57 void operator()(const Arg1
& arg1
)
59 dispatcher_
.dispatch(detail::bind_handler(handler_
, arg1
));
62 template <typename Arg1
>
63 void operator()(const Arg1
& arg1
) const
65 dispatcher_
.dispatch(detail::bind_handler(handler_
, arg1
));
68 template <typename Arg1
, typename Arg2
>
69 void operator()(const Arg1
& arg1
, const Arg2
& arg2
)
71 dispatcher_
.dispatch(detail::bind_handler(handler_
, arg1
, arg2
));
74 template <typename Arg1
, typename Arg2
>
75 void operator()(const Arg1
& arg1
, const Arg2
& arg2
) const
77 dispatcher_
.dispatch(detail::bind_handler(handler_
, arg1
, arg2
));
80 template <typename Arg1
, typename Arg2
, typename Arg3
>
81 void operator()(const Arg1
& arg1
, const Arg2
& arg2
, const Arg3
& arg3
)
83 dispatcher_
.dispatch(detail::bind_handler(handler_
, arg1
, arg2
, arg3
));
86 template <typename Arg1
, typename Arg2
, typename Arg3
>
87 void operator()(const Arg1
& arg1
, const Arg2
& arg2
, const Arg3
& arg3
) const
89 dispatcher_
.dispatch(detail::bind_handler(handler_
, arg1
, arg2
, arg3
));
92 template <typename Arg1
, typename Arg2
, typename Arg3
, typename Arg4
>
93 void operator()(const Arg1
& arg1
, const Arg2
& arg2
, const Arg3
& arg3
,
97 detail::bind_handler(handler_
, arg1
, arg2
, arg3
, arg4
));
100 template <typename Arg1
, typename Arg2
, typename Arg3
, typename Arg4
>
101 void operator()(const Arg1
& arg1
, const Arg2
& arg2
, const Arg3
& arg3
,
102 const Arg4
& arg4
) const
104 dispatcher_
.dispatch(
105 detail::bind_handler(handler_
, arg1
, arg2
, arg3
, arg4
));
108 template <typename Arg1
, typename Arg2
, typename Arg3
, typename Arg4
,
110 void operator()(const Arg1
& arg1
, const Arg2
& arg2
, const Arg3
& arg3
,
111 const Arg4
& arg4
, const Arg5
& arg5
)
113 dispatcher_
.dispatch(
114 detail::bind_handler(handler_
, arg1
, arg2
, arg3
, arg4
, arg5
));
117 template <typename Arg1
, typename Arg2
, typename Arg3
, typename Arg4
,
119 void operator()(const Arg1
& arg1
, const Arg2
& arg2
, const Arg3
& arg3
,
120 const Arg4
& arg4
, const Arg5
& arg5
) const
122 dispatcher_
.dispatch(
123 detail::bind_handler(handler_
, arg1
, arg2
, arg3
, arg4
, arg5
));
127 Dispatcher dispatcher_
;
131 template <typename Handler
, typename Context
>
132 class rewrapped_handler
135 explicit rewrapped_handler(const Handler
& handler
, const Context
& context
)
146 void operator()() const
156 template <typename Dispatcher
, typename Handler
>
157 inline void* asio_handler_allocate(std::size_t size
,
158 wrapped_handler
<Dispatcher
, Handler
>* this_handler
)
160 return boost_asio_handler_alloc_helpers::allocate(
161 size
, &this_handler
->handler_
);
164 template <typename Dispatcher
, typename Handler
>
165 inline void asio_handler_deallocate(void* pointer
, std::size_t size
,
166 wrapped_handler
<Dispatcher
, Handler
>* this_handler
)
168 boost_asio_handler_alloc_helpers::deallocate(
169 pointer
, size
, &this_handler
->handler_
);
172 template <typename Function
, typename Dispatcher
, typename Handler
>
173 inline void asio_handler_invoke(const Function
& function
,
174 wrapped_handler
<Dispatcher
, Handler
>* this_handler
)
176 this_handler
->dispatcher_
.dispatch(
177 rewrapped_handler
<Function
, Handler
>(
178 function
, this_handler
->handler_
));
181 template <typename Handler
, typename Context
>
182 inline void* asio_handler_allocate(std::size_t size
,
183 rewrapped_handler
<Handler
, Context
>* this_handler
)
185 return boost_asio_handler_alloc_helpers::allocate(
186 size
, &this_handler
->context_
);
189 template <typename Handler
, typename Context
>
190 inline void asio_handler_deallocate(void* pointer
, std::size_t size
,
191 rewrapped_handler
<Handler
, Context
>* this_handler
)
193 boost_asio_handler_alloc_helpers::deallocate(
194 pointer
, size
, &this_handler
->context_
);
197 template <typename Function
, typename Handler
, typename Context
>
198 inline void asio_handler_invoke(const Function
& function
,
199 rewrapped_handler
<Handler
, Context
>* this_handler
)
201 boost_asio_handler_invoke_helpers::invoke(
202 function
, &this_handler
->context_
);
205 } // namespace detail
209 #include <boost/asio/detail/pop_options.hpp>
211 #endif // BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP