fix doc example typo
[boost.git] / boost / asio / detail / wrapped_handler.hpp
blob64fc729566e6b1959ac413e27e97d9e9519e576f
1 //
2 // wrapped_handler.hpp
3 // ~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
11 #ifndef BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP
12 #define BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
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>
28 namespace boost {
29 namespace asio {
30 namespace detail {
32 template <typename Dispatcher, typename Handler>
33 class wrapped_handler
35 public:
36 typedef void result_type;
38 wrapped_handler(
39 typename boost::add_reference<Dispatcher>::type dispatcher,
40 Handler handler)
41 : dispatcher_(dispatcher),
42 handler_(handler)
46 void operator()()
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,
94 const Arg4& arg4)
96 dispatcher_.dispatch(
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,
109 typename Arg5>
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,
118 typename Arg5>
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));
126 //private:
127 Dispatcher dispatcher_;
128 Handler handler_;
131 template <typename Handler, typename Context>
132 class rewrapped_handler
134 public:
135 explicit rewrapped_handler(const Handler& handler, const Context& context)
136 : handler_(handler),
137 context_(context)
141 void operator()()
143 handler_();
146 void operator()() const
148 handler_();
151 //private:
152 Handler handler_;
153 Context context_;
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
206 } // namespace asio
207 } // namespace boost
209 #include <boost/asio/detail/pop_options.hpp>
211 #endif // BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP