fix doc example typo
[boost.git] / boost / asio / detail / bind_handler.hpp
blob3a9ad0191ce89fa2cdb7117d7e30e611d921fdc1
1 //
2 // bind_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_BIND_HANDLER_HPP
12 #define BOOST_ASIO_DETAIL_BIND_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/handler_alloc_helpers.hpp>
21 #include <boost/asio/detail/handler_invoke_helpers.hpp>
23 namespace boost {
24 namespace asio {
25 namespace detail {
27 template <typename Handler, typename Arg1>
28 class binder1
30 public:
31 binder1(const Handler& handler, const Arg1& arg1)
32 : handler_(handler),
33 arg1_(arg1)
37 void operator()()
39 handler_(arg1_);
42 void operator()() const
44 handler_(arg1_);
47 //private:
48 Handler handler_;
49 Arg1 arg1_;
52 template <typename Handler, typename Arg1>
53 inline void* asio_handler_allocate(std::size_t size,
54 binder1<Handler, Arg1>* this_handler)
56 return boost_asio_handler_alloc_helpers::allocate(
57 size, &this_handler->handler_);
60 template <typename Handler, typename Arg1>
61 inline void asio_handler_deallocate(void* pointer, std::size_t size,
62 binder1<Handler, Arg1>* this_handler)
64 boost_asio_handler_alloc_helpers::deallocate(
65 pointer, size, &this_handler->handler_);
68 template <typename Function, typename Handler, typename Arg1>
69 inline void asio_handler_invoke(const Function& function,
70 binder1<Handler, Arg1>* this_handler)
72 boost_asio_handler_invoke_helpers::invoke(
73 function, &this_handler->handler_);
76 template <typename Handler, typename Arg1>
77 inline binder1<Handler, Arg1> bind_handler(const Handler& handler,
78 const Arg1& arg1)
80 return binder1<Handler, Arg1>(handler, arg1);
83 template <typename Handler, typename Arg1, typename Arg2>
84 class binder2
86 public:
87 binder2(const Handler& handler, const Arg1& arg1, const Arg2& arg2)
88 : handler_(handler),
89 arg1_(arg1),
90 arg2_(arg2)
94 void operator()()
96 handler_(arg1_, arg2_);
99 void operator()() const
101 handler_(arg1_, arg2_);
104 //private:
105 Handler handler_;
106 Arg1 arg1_;
107 Arg2 arg2_;
110 template <typename Handler, typename Arg1, typename Arg2>
111 inline void* asio_handler_allocate(std::size_t size,
112 binder2<Handler, Arg1, Arg2>* this_handler)
114 return boost_asio_handler_alloc_helpers::allocate(
115 size, &this_handler->handler_);
118 template <typename Handler, typename Arg1, typename Arg2>
119 inline void asio_handler_deallocate(void* pointer, std::size_t size,
120 binder2<Handler, Arg1, Arg2>* this_handler)
122 boost_asio_handler_alloc_helpers::deallocate(
123 pointer, size, &this_handler->handler_);
126 template <typename Function, typename Handler, typename Arg1, typename Arg2>
127 inline void asio_handler_invoke(const Function& function,
128 binder2<Handler, Arg1, Arg2>* this_handler)
130 boost_asio_handler_invoke_helpers::invoke(
131 function, &this_handler->handler_);
134 template <typename Handler, typename Arg1, typename Arg2>
135 inline binder2<Handler, Arg1, Arg2> bind_handler(const Handler& handler,
136 const Arg1& arg1, const Arg2& arg2)
138 return binder2<Handler, Arg1, Arg2>(handler, arg1, arg2);
141 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
142 class binder3
144 public:
145 binder3(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
146 const Arg3& arg3)
147 : handler_(handler),
148 arg1_(arg1),
149 arg2_(arg2),
150 arg3_(arg3)
154 void operator()()
156 handler_(arg1_, arg2_, arg3_);
159 void operator()() const
161 handler_(arg1_, arg2_, arg3_);
164 //private:
165 Handler handler_;
166 Arg1 arg1_;
167 Arg2 arg2_;
168 Arg3 arg3_;
171 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
172 inline void* asio_handler_allocate(std::size_t size,
173 binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
175 return boost_asio_handler_alloc_helpers::allocate(
176 size, &this_handler->handler_);
179 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
180 inline void asio_handler_deallocate(void* pointer, std::size_t size,
181 binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
183 boost_asio_handler_alloc_helpers::deallocate(
184 pointer, size, &this_handler->handler_);
187 template <typename Function, typename Handler, typename Arg1, typename Arg2,
188 typename Arg3>
189 inline void asio_handler_invoke(const Function& function,
190 binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
192 boost_asio_handler_invoke_helpers::invoke(
193 function, &this_handler->handler_);
196 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
197 inline binder3<Handler, Arg1, Arg2, Arg3> bind_handler(const Handler& handler,
198 const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
200 return binder3<Handler, Arg1, Arg2, Arg3>(handler, arg1, arg2, arg3);
203 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
204 typename Arg4>
205 class binder4
207 public:
208 binder4(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
209 const Arg3& arg3, const Arg4& arg4)
210 : handler_(handler),
211 arg1_(arg1),
212 arg2_(arg2),
213 arg3_(arg3),
214 arg4_(arg4)
218 void operator()()
220 handler_(arg1_, arg2_, arg3_, arg4_);
223 void operator()() const
225 handler_(arg1_, arg2_, arg3_, arg4_);
228 //private:
229 Handler handler_;
230 Arg1 arg1_;
231 Arg2 arg2_;
232 Arg3 arg3_;
233 Arg4 arg4_;
236 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
237 typename Arg4>
238 inline void* asio_handler_allocate(std::size_t size,
239 binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
241 return boost_asio_handler_alloc_helpers::allocate(
242 size, &this_handler->handler_);
245 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
246 typename Arg4>
247 inline void asio_handler_deallocate(void* pointer, std::size_t size,
248 binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
250 boost_asio_handler_alloc_helpers::deallocate(
251 pointer, size, &this_handler->handler_);
254 template <typename Function, typename Handler, typename Arg1, typename Arg2,
255 typename Arg3, typename Arg4>
256 inline void asio_handler_invoke(const Function& function,
257 binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
259 boost_asio_handler_invoke_helpers::invoke(
260 function, &this_handler->handler_);
263 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
264 typename Arg4>
265 inline binder4<Handler, Arg1, Arg2, Arg3, Arg4> bind_handler(
266 const Handler& handler, const Arg1& arg1, const Arg2& arg2,
267 const Arg3& arg3, const Arg4& arg4)
269 return binder4<Handler, Arg1, Arg2, Arg3, Arg4>(handler, arg1, arg2, arg3,
270 arg4);
273 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
274 typename Arg4, typename Arg5>
275 class binder5
277 public:
278 binder5(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
279 const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
280 : handler_(handler),
281 arg1_(arg1),
282 arg2_(arg2),
283 arg3_(arg3),
284 arg4_(arg4),
285 arg5_(arg5)
289 void operator()()
291 handler_(arg1_, arg2_, arg3_, arg4_, arg5_);
294 void operator()() const
296 handler_(arg1_, arg2_, arg3_, arg4_, arg5_);
299 //private:
300 Handler handler_;
301 Arg1 arg1_;
302 Arg2 arg2_;
303 Arg3 arg3_;
304 Arg4 arg4_;
305 Arg5 arg5_;
308 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
309 typename Arg4, typename Arg5>
310 inline void* asio_handler_allocate(std::size_t size,
311 binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
313 return boost_asio_handler_alloc_helpers::allocate(
314 size, &this_handler->handler_);
317 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
318 typename Arg4, typename Arg5>
319 inline void asio_handler_deallocate(void* pointer, std::size_t size,
320 binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
322 boost_asio_handler_alloc_helpers::deallocate(
323 pointer, size, &this_handler->handler_);
326 template <typename Function, typename Handler, typename Arg1, typename Arg2,
327 typename Arg3, typename Arg4, typename Arg5>
328 inline void asio_handler_invoke(const Function& function,
329 binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
331 boost_asio_handler_invoke_helpers::invoke(
332 function, &this_handler->handler_);
335 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
336 typename Arg4, typename Arg5>
337 inline binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5> bind_handler(
338 const Handler& handler, const Arg1& arg1, const Arg2& arg2,
339 const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
341 return binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>(handler, arg1, arg2,
342 arg3, arg4, arg5);
345 } // namespace detail
346 } // namespace asio
347 } // namespace boost
349 #include <boost/asio/detail/pop_options.hpp>
351 #endif // BOOST_ASIO_DETAIL_BIND_HANDLER_HPP