Chris@16
|
1 //
|
Chris@16
|
2 // async_result.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@101
|
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_ASIO_ASYNC_RESULT_HPP
|
Chris@16
|
12 #define BOOST_ASIO_ASYNC_RESULT_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/asio/detail/config.hpp>
|
Chris@16
|
19 #include <boost/asio/handler_type.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 namespace boost {
|
Chris@16
|
24 namespace asio {
|
Chris@16
|
25
|
Chris@16
|
26 /// An interface for customising the behaviour of an initiating function.
|
Chris@16
|
27 /**
|
Chris@16
|
28 * This template may be specialised for user-defined handler types.
|
Chris@16
|
29 */
|
Chris@16
|
30 template <typename Handler>
|
Chris@16
|
31 class async_result
|
Chris@16
|
32 {
|
Chris@16
|
33 public:
|
Chris@16
|
34 /// The return type of the initiating function.
|
Chris@16
|
35 typedef void type;
|
Chris@16
|
36
|
Chris@16
|
37 /// Construct an async result from a given handler.
|
Chris@16
|
38 /**
|
Chris@16
|
39 * When using a specalised async_result, the constructor has an opportunity
|
Chris@16
|
40 * to initialise some state associated with the handler, which is then
|
Chris@16
|
41 * returned from the initiating function.
|
Chris@16
|
42 */
|
Chris@16
|
43 explicit async_result(Handler&)
|
Chris@16
|
44 {
|
Chris@16
|
45 }
|
Chris@16
|
46
|
Chris@16
|
47 /// Obtain the value to be returned from the initiating function.
|
Chris@16
|
48 type get()
|
Chris@16
|
49 {
|
Chris@16
|
50 }
|
Chris@16
|
51 };
|
Chris@16
|
52
|
Chris@16
|
53 namespace detail {
|
Chris@16
|
54
|
Chris@16
|
55 // Helper template to deduce the true type of a handler, capture a local copy
|
Chris@16
|
56 // of the handler, and then create an async_result for the handler.
|
Chris@16
|
57 template <typename Handler, typename Signature>
|
Chris@16
|
58 struct async_result_init
|
Chris@16
|
59 {
|
Chris@16
|
60 explicit async_result_init(BOOST_ASIO_MOVE_ARG(Handler) orig_handler)
|
Chris@16
|
61 : handler(BOOST_ASIO_MOVE_CAST(Handler)(orig_handler)),
|
Chris@16
|
62 result(handler)
|
Chris@16
|
63 {
|
Chris@16
|
64 }
|
Chris@16
|
65
|
Chris@16
|
66 typename handler_type<Handler, Signature>::type handler;
|
Chris@16
|
67 async_result<typename handler_type<Handler, Signature>::type> result;
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70 template <typename Handler, typename Signature>
|
Chris@16
|
71 struct async_result_type_helper
|
Chris@16
|
72 {
|
Chris@16
|
73 typedef typename async_result<
|
Chris@16
|
74 typename handler_type<Handler, Signature>::type
|
Chris@16
|
75 >::type type;
|
Chris@16
|
76 };
|
Chris@16
|
77
|
Chris@16
|
78 } // namespace detail
|
Chris@16
|
79 } // namespace asio
|
Chris@16
|
80 } // namespace boost
|
Chris@16
|
81
|
Chris@16
|
82 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
83
|
Chris@16
|
84 #if defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
85 # define BOOST_ASIO_INITFN_RESULT_TYPE(h, sig) \
|
Chris@16
|
86 void_or_deduced
|
Chris@16
|
87 #elif defined(_MSC_VER) && (_MSC_VER < 1500)
|
Chris@16
|
88 # define BOOST_ASIO_INITFN_RESULT_TYPE(h, sig) \
|
Chris@16
|
89 typename ::boost::asio::detail::async_result_type_helper<h, sig>::type
|
Chris@16
|
90 #else
|
Chris@16
|
91 # define BOOST_ASIO_INITFN_RESULT_TYPE(h, sig) \
|
Chris@16
|
92 typename ::boost::asio::async_result< \
|
Chris@16
|
93 typename ::boost::asio::handler_type<h, sig>::type>::type
|
Chris@16
|
94 #endif
|
Chris@16
|
95
|
Chris@16
|
96 #endif // BOOST_ASIO_ASYNC_RESULT_HPP
|