Realistic 3D camera system
3D camera system components
wrapped_handler.hpp
Go to the documentation of this file.
1 //
2 // detail/wrapped_handler.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_DETAIL_WRAPPED_HANDLER_HPP
12 #define ASIO_DETAIL_WRAPPED_HANDLER_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
22 
24 
25 namespace asio {
26 namespace detail {
27 
29 {
30  template <typename Dispatcher, typename Handler>
31  bool operator()(Dispatcher&, Handler& handler) const
32  {
34  }
35 };
36 
38 {
39  template <typename Dispatcher, typename Handler>
40  bool operator()(Dispatcher& dispatcher, Handler&) const
41  {
42  return dispatcher.running_in_this_thread();
43  }
44 };
45 
46 template <typename Dispatcher, typename Handler,
47  typename IsContinuation = is_continuation_delegated>
49 {
50 public:
51  typedef void result_type;
52 
53  wrapped_handler(Dispatcher dispatcher, Handler& handler)
54  : dispatcher_(dispatcher),
55  handler_(ASIO_MOVE_CAST(Handler)(handler))
56  {
57  }
58 
59 #if defined(ASIO_HAS_MOVE)
60  wrapped_handler(const wrapped_handler& other)
61  : dispatcher_(other.dispatcher_),
62  handler_(other.handler_)
63  {
64  }
65 
67  : dispatcher_(other.dispatcher_),
68  handler_(ASIO_MOVE_CAST(Handler)(other.handler_))
69  {
70  }
71 #endif // defined(ASIO_HAS_MOVE)
72 
73  void operator()()
74  {
75  dispatcher_.dispatch(ASIO_MOVE_CAST(Handler)(handler_));
76  }
77 
78  void operator()() const
79  {
80  dispatcher_.dispatch(handler_);
81  }
82 
83  template <typename Arg1>
84  void operator()(const Arg1& arg1)
85  {
86  dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
87  }
88 
89  template <typename Arg1>
90  void operator()(const Arg1& arg1) const
91  {
92  dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
93  }
94 
95  template <typename Arg1, typename Arg2>
96  void operator()(const Arg1& arg1, const Arg2& arg2)
97  {
98  dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
99  }
100 
101  template <typename Arg1, typename Arg2>
102  void operator()(const Arg1& arg1, const Arg2& arg2) const
103  {
104  dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
105  }
106 
107  template <typename Arg1, typename Arg2, typename Arg3>
108  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
109  {
110  dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
111  }
112 
113  template <typename Arg1, typename Arg2, typename Arg3>
114  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const
115  {
116  dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
117  }
118 
119  template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
120  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
121  const Arg4& arg4)
122  {
123  dispatcher_.dispatch(
124  detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
125  }
126 
127  template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
128  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
129  const Arg4& arg4) const
130  {
131  dispatcher_.dispatch(
132  detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
133  }
134 
135  template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
136  typename Arg5>
137  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
138  const Arg4& arg4, const Arg5& arg5)
139  {
140  dispatcher_.dispatch(
141  detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
142  }
143 
144  template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
145  typename Arg5>
146  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
147  const Arg4& arg4, const Arg5& arg5) const
148  {
149  dispatcher_.dispatch(
150  detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
151  }
152 
153 //private:
154  Dispatcher dispatcher_;
155  Handler handler_;
156 };
157 
158 template <typename Handler, typename Context>
160 {
161 public:
162  explicit rewrapped_handler(Handler& handler, const Context& context)
163  : context_(context),
164  handler_(ASIO_MOVE_CAST(Handler)(handler))
165  {
166  }
167 
168  explicit rewrapped_handler(const Handler& handler, const Context& context)
169  : context_(context),
170  handler_(handler)
171  {
172  }
173 
174 #if defined(ASIO_HAS_MOVE)
176  : context_(other.context_),
177  handler_(other.handler_)
178  {
179  }
180 
182  : context_(ASIO_MOVE_CAST(Context)(other.context_)),
183  handler_(ASIO_MOVE_CAST(Handler)(other.handler_))
184  {
185  }
186 #endif // defined(ASIO_HAS_MOVE)
187 
188  void operator()()
189  {
190  handler_();
191  }
192 
193  void operator()() const
194  {
195  handler_();
196  }
197 
198 //private:
199  Context context_;
200  Handler handler_;
201 };
202 
203 template <typename Dispatcher, typename Handler, typename IsContinuation>
204 inline void* asio_handler_allocate(std::size_t size,
206 {
208  size, this_handler->handler_);
209 }
210 
211 template <typename Dispatcher, typename Handler, typename IsContinuation>
212 inline void asio_handler_deallocate(void* pointer, std::size_t size,
214 {
216  pointer, size, this_handler->handler_);
217 }
218 
219 template <typename Dispatcher, typename Handler, typename IsContinuation>
222 {
223  return IsContinuation()(this_handler->dispatcher_, this_handler->handler_);
224 }
225 
226 template <typename Function, typename Dispatcher,
227  typename Handler, typename IsContinuation>
228 inline void asio_handler_invoke(Function& function,
230 {
231  this_handler->dispatcher_.dispatch(
233  function, this_handler->handler_));
234 }
235 
236 template <typename Function, typename Dispatcher,
237  typename Handler, typename IsContinuation>
238 inline void asio_handler_invoke(const Function& function,
240 {
241  this_handler->dispatcher_.dispatch(
243  function, this_handler->handler_));
244 }
245 
246 template <typename Handler, typename Context>
247 inline void* asio_handler_allocate(std::size_t size,
249 {
251  size, this_handler->context_);
252 }
253 
254 template <typename Handler, typename Context>
255 inline void asio_handler_deallocate(void* pointer, std::size_t size,
257 {
259  pointer, size, this_handler->context_);
260 }
261 
262 template <typename Dispatcher, typename Context>
265 {
267  this_handler->context_);
268 }
269 
270 template <typename Function, typename Handler, typename Context>
271 inline void asio_handler_invoke(Function& function,
273 {
275  function, this_handler->context_);
276 }
277 
278 template <typename Function, typename Handler, typename Context>
279 inline void asio_handler_invoke(const Function& function,
281 {
283  function, this_handler->context_);
284 }
285 
286 } // namespace detail
287 } // namespace asio
288 
290 
291 #endif // ASIO_DETAIL_WRAPPED_HANDLER_HPP
void asio_handler_deallocate(void *pointer, std::size_t size, binder1< Handler, Arg1 > *this_handler)
void operator()(const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) const
void operator()(const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
rewrapped_handler(const Handler &handler, const Context &context)
void * asio_handler_allocate(std::size_t size, binder1< Handler, Arg1 > *this_handler)
wrapped_handler(Dispatcher dispatcher, Handler &handler)
void operator()(const Arg1 &arg1, const Arg2 &arg2)
void operator()(const Arg1 &arg1) const
void invoke(Function &function, Context &context)
void operator()(const Arg1 &arg1)
void operator()(const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) const
void operator()(const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
void asio_handler_invoke(Function &function, binder1< Handler, Arg1 > *this_handler)
rewrapped_handler(Handler &handler, const Context &context)
bool is_continuation(Context &context)
void operator()(const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) const
void operator()(const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
void deallocate(void *p, std::size_t s, Handler &h)
void * allocate(std::size_t s, Handler &h)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
binder1< Handler, Arg1 > bind_handler(Handler handler, const Arg1 &arg1)
void operator()(const Arg1 &arg1, const Arg2 &arg2) const
bool operator()(Dispatcher &dispatcher, Handler &) const
bool asio_handler_is_continuation(binder1< Handler, Arg1 > *this_handler)
bool operator()(Dispatcher &, Handler &handler) const