• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // handler_type.hpp
3 // ~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 //
10 
11 #ifndef ASIO_HANDLER_TYPE_HPP
12 #define ASIO_HANDLER_TYPE_HPP
13 
14 
15 #include "asio/detail/config.hpp"
16 
17 #include "asio/detail/push_options.hpp"
18 
19 namespace asio {
20 
21 /// Default handler type traits provided for all handlers.
22 /**
23  * The handler_type traits class is used for determining the concrete handler
24  * type to be used for an asynchronous operation. It allows the handler type to
25  * be determined at the point where the specific completion handler signature
26  * is known.
27  *
28  * This template may be specialised for user-defined handler types.
29  */
30 template <typename Handler, typename Signature>
31 struct handler_type
32 {
33   /// The handler type for the specific signature.
34   typedef Handler type;
35 };
36 
37 
38 template <typename Handler, typename Signature>
39 struct handler_type<const Handler, Signature>
40   : handler_type<Handler, Signature> {};
41 
42 template <typename Handler, typename Signature>
43 struct handler_type<volatile Handler, Signature>
44   : handler_type<Handler, Signature> {};
45 
46 template <typename Handler, typename Signature>
47 struct handler_type<const volatile Handler, Signature>
48   : handler_type<Handler, Signature> {};
49 
50 template <typename Handler, typename Signature>
51 struct handler_type<const Handler&, Signature>
52   : handler_type<Handler, Signature> {};
53 
54 template <typename Handler, typename Signature>
55 struct handler_type<volatile Handler&, Signature>
56   : handler_type<Handler, Signature> {};
57 
58 template <typename Handler, typename Signature>
59 struct handler_type<const volatile Handler&, Signature>
60   : handler_type<Handler, Signature> {};
61 
62 template <typename Handler, typename Signature>
63 struct handler_type<Handler&, Signature>
64   : handler_type<Handler, Signature> {};
65 
66 template <typename Handler, typename Signature>
67 struct handler_type<Handler&&, Signature>
68   : handler_type<Handler, Signature> {};
69 
70 template <typename ReturnType, typename Signature>
71 struct handler_type<ReturnType(), Signature>
72   : handler_type<ReturnType(*)(), Signature> {};
73 
74 template <typename ReturnType, typename Arg1, typename Signature>
75 struct handler_type<ReturnType(Arg1), Signature>
76   : handler_type<ReturnType(*)(Arg1), Signature> {};
77 
78 template <typename ReturnType, typename Arg1, typename Arg2, typename Signature>
79 struct handler_type<ReturnType(Arg1, Arg2), Signature>
80   : handler_type<ReturnType(*)(Arg1, Arg2), Signature> {};
81 
82 template <typename ReturnType, typename Arg1, typename Arg2, typename Arg3,
83     typename Signature>
84 struct handler_type<ReturnType(Arg1, Arg2, Arg3), Signature>
85   : handler_type<ReturnType(*)(Arg1, Arg2, Arg3), Signature> {};
86 
87 template <typename ReturnType, typename Arg1, typename Arg2, typename Arg3,
88     typename Arg4, typename Signature>
89 struct handler_type<ReturnType(Arg1, Arg2, Arg3, Arg4), Signature>
90   : handler_type<ReturnType(*)(Arg1, Arg2, Arg3, Arg4), Signature> {};
91 
92 template <typename ReturnType, typename Arg1, typename Arg2, typename Arg3,
93     typename Arg4, typename Arg5, typename Signature>
94 struct handler_type<ReturnType(Arg1, Arg2, Arg3, Arg4, Arg5), Signature>
95   : handler_type<ReturnType(*)(Arg1, Arg2, Arg3, Arg4, Arg5), Signature> {};
96 
97 
98 } // namespace asio
99 
100 #include "asio/detail/pop_options.hpp"
101 
102 #define ASIO_HANDLER_TYPE(h, sig)    typename handler_type<h, sig>::type
103 
104 #endif // ASIO_HANDLER_TYPE_HPP
105