2
// detail/wrapped_handler.hpp
3
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
5
// Copyright (c) 2003-2012 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/bind_handler.hpp>
19
#include <boost/asio/detail/handler_alloc_helpers.hpp>
20
#include <boost/asio/detail/handler_invoke_helpers.hpp>
22
#include <boost/asio/detail/push_options.hpp>
28
template <typename Dispatcher, typename Handler>
32
typedef void result_type;
34
wrapped_handler(Dispatcher dispatcher, Handler& handler)
35
: dispatcher_(dispatcher),
36
handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
40
#if defined(BOOST_ASIO_HAS_MOVE)
41
wrapped_handler(const wrapped_handler& other)
42
: dispatcher_(other.dispatcher_),
43
handler_(other.handler_)
47
wrapped_handler(wrapped_handler&& other)
48
: dispatcher_(other.dispatcher_),
49
handler_(BOOST_ASIO_MOVE_CAST(Handler)(other.handler_))
52
#endif // defined(BOOST_ASIO_HAS_MOVE)
56
dispatcher_.dispatch(handler_);
59
void operator()() const
61
dispatcher_.dispatch(handler_);
64
template <typename Arg1>
65
void operator()(const Arg1& arg1)
67
dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
70
template <typename Arg1>
71
void operator()(const Arg1& arg1) const
73
dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
76
template <typename Arg1, typename Arg2>
77
void operator()(const Arg1& arg1, const Arg2& arg2)
79
dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
82
template <typename Arg1, typename Arg2>
83
void operator()(const Arg1& arg1, const Arg2& arg2) const
85
dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
88
template <typename Arg1, typename Arg2, typename Arg3>
89
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
91
dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
94
template <typename Arg1, typename Arg2, typename Arg3>
95
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const
97
dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
100
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
101
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
104
dispatcher_.dispatch(
105
detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
108
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
109
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
110
const Arg4& arg4) const
112
dispatcher_.dispatch(
113
detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
116
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
118
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
119
const Arg4& arg4, const Arg5& arg5)
121
dispatcher_.dispatch(
122
detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
125
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
127
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
128
const Arg4& arg4, const Arg5& arg5) const
130
dispatcher_.dispatch(
131
detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
135
Dispatcher dispatcher_;
139
template <typename Handler, typename Context>
140
class rewrapped_handler
143
explicit rewrapped_handler(Handler& handler, const Context& context)
145
handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
149
explicit rewrapped_handler(const Handler& handler, const Context& context)
155
#if defined(BOOST_ASIO_HAS_MOVE)
156
rewrapped_handler(const rewrapped_handler& other)
157
: context_(other.context_),
158
handler_(other.handler_)
162
rewrapped_handler(rewrapped_handler&& other)
163
: context_(BOOST_ASIO_MOVE_CAST(Context)(other.context_)),
164
handler_(BOOST_ASIO_MOVE_CAST(Handler)(other.handler_))
167
#endif // defined(BOOST_ASIO_HAS_MOVE)
174
void operator()() const
184
template <typename Dispatcher, typename Handler>
185
inline void* asio_handler_allocate(std::size_t size,
186
wrapped_handler<Dispatcher, Handler>* this_handler)
188
return boost_asio_handler_alloc_helpers::allocate(
189
size, this_handler->handler_);
192
template <typename Dispatcher, typename Handler>
193
inline void asio_handler_deallocate(void* pointer, std::size_t size,
194
wrapped_handler<Dispatcher, Handler>* this_handler)
196
boost_asio_handler_alloc_helpers::deallocate(
197
pointer, size, this_handler->handler_);
200
template <typename Function, typename Dispatcher, typename Handler>
201
inline void asio_handler_invoke(Function& function,
202
wrapped_handler<Dispatcher, Handler>* this_handler)
204
this_handler->dispatcher_.dispatch(
205
rewrapped_handler<Function, Handler>(
206
function, this_handler->handler_));
209
template <typename Function, typename Dispatcher, typename Handler>
210
inline void asio_handler_invoke(const Function& function,
211
wrapped_handler<Dispatcher, Handler>* this_handler)
213
this_handler->dispatcher_.dispatch(
214
rewrapped_handler<Function, Handler>(
215
function, this_handler->handler_));
218
template <typename Handler, typename Context>
219
inline void* asio_handler_allocate(std::size_t size,
220
rewrapped_handler<Handler, Context>* this_handler)
222
return boost_asio_handler_alloc_helpers::allocate(
223
size, this_handler->context_);
226
template <typename Handler, typename Context>
227
inline void asio_handler_deallocate(void* pointer, std::size_t size,
228
rewrapped_handler<Handler, Context>* this_handler)
230
boost_asio_handler_alloc_helpers::deallocate(
231
pointer, size, this_handler->context_);
234
template <typename Function, typename Handler, typename Context>
235
inline void asio_handler_invoke(Function& function,
236
rewrapped_handler<Handler, Context>* this_handler)
238
boost_asio_handler_invoke_helpers::invoke(
239
function, this_handler->context_);
242
template <typename Function, typename Handler, typename Context>
243
inline void asio_handler_invoke(const Function& function,
244
rewrapped_handler<Handler, Context>* this_handler)
246
boost_asio_handler_invoke_helpers::invoke(
247
function, this_handler->context_);
250
} // namespace detail
254
#include <boost/asio/detail/pop_options.hpp>
256
#endif // BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP