]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | /* |
2 | * async_handler.hpp | |
3 | * | |
4 | * Created on: 12.06.2016 | |
5 | * Author: Klemens | |
6 | */ | |
7 | ||
8 | #ifndef BOOST_PROCESS_DETAIL_ASYNC_HANDLER_HPP_ | |
9 | #define BOOST_PROCESS_DETAIL_ASYNC_HANDLER_HPP_ | |
10 | ||
11 | #include <type_traits> | |
12 | ||
13 | #if defined(BOOST_POSIX_API) | |
14 | #include <boost/process/posix.hpp> | |
15 | #include <boost/process/detail/posix/async_handler.hpp> | |
16 | #include <boost/process/detail/posix/asio_fwd.hpp> | |
17 | #else | |
18 | #include <boost/process/detail/windows/async_handler.hpp> | |
19 | #include <boost/process/detail/windows/asio_fwd.hpp> | |
20 | #endif | |
21 | ||
22 | namespace boost { | |
23 | ||
24 | namespace process { | |
25 | ||
26 | namespace detail { | |
27 | ||
28 | #if defined(BOOST_POSIX_API) | |
29 | using ::boost::process::detail::posix::is_async_handler; | |
30 | using ::boost::process::detail::posix::does_require_io_context; | |
31 | #else | |
32 | using ::boost::process::detail::windows::is_async_handler; | |
33 | using ::boost::process::detail::windows::does_require_io_context; | |
34 | #endif | |
35 | ||
36 | template<typename ...Args> | |
37 | struct has_io_context; | |
38 | ||
39 | template<typename T, typename ...Args> | |
40 | struct has_io_context<T, Args...> | |
41 | { | |
42 | typedef typename has_io_context<Args...>::type next; | |
43 | typedef typename std::is_same< | |
44 | typename std::remove_reference<T>::type, | |
45 | boost::asio::io_context>::type is_ios; | |
46 | typedef typename std::conditional<is_ios::value, | |
47 | std::true_type, | |
48 | next>::type type; | |
49 | }; | |
50 | ||
51 | template<typename T> | |
52 | struct has_io_context<T> | |
53 | { | |
54 | typedef typename std::is_same< | |
55 | typename std::remove_reference<T>::type, | |
56 | boost::asio::io_context>::type type; | |
57 | }; | |
58 | ||
59 | template<typename ...Args> | |
60 | using has_io_context_t = typename has_io_context<Args...>::type; | |
61 | ||
62 | template<typename ...Args> | |
63 | struct has_async_handler; | |
64 | ||
65 | template<typename T, typename ...Args> | |
66 | struct has_async_handler<T, Args...> | |
67 | { | |
68 | typedef typename has_async_handler<Args...>::type next; | |
69 | typedef typename is_async_handler<T>::type is_ios; | |
70 | typedef typename std::conditional<is_ios::value, | |
71 | std::true_type, | |
72 | next>::type type; | |
73 | }; | |
74 | ||
75 | template<typename T> | |
76 | struct has_async_handler<T> | |
77 | { | |
78 | typedef typename is_async_handler<T>::type type; | |
79 | }; | |
80 | ||
81 | template<typename ...Args> | |
82 | struct needs_io_context; | |
83 | ||
84 | template<typename T, typename ...Args> | |
85 | struct needs_io_context<T, Args...> | |
86 | { | |
87 | typedef typename needs_io_context<Args...>::type next; | |
88 | typedef typename does_require_io_context<T>::type is_ios; | |
89 | typedef typename std::conditional<is_ios::value, | |
90 | std::true_type, | |
91 | next>::type type; | |
92 | }; | |
93 | ||
94 | template<typename T> | |
95 | struct needs_io_context<T> | |
96 | { | |
97 | typedef typename does_require_io_context<T>::type type; | |
98 | }; | |
99 | ||
100 | template<typename ...Args> | |
101 | boost::asio::io_context &get_io_context_var(boost::asio::io_context & f, Args&...) | |
102 | { | |
103 | return f; | |
104 | } | |
105 | ||
106 | template<typename First, typename ...Args> | |
107 | boost::asio::io_context &get_io_context_var(First&, Args&...args) | |
108 | { | |
109 | return get_io_context_var(args...); | |
110 | } | |
111 | ||
112 | } | |
113 | } | |
114 | } | |
115 | ||
116 | ||
117 | #endif /* BOOST_PROCESS_DETAIL_ASYNC_HANDLER_HPP_ */ |