Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:48

0001 //
0002 // detail/wrapped_handler.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP
0012 #define BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/bind_handler.hpp>
0019 #include <boost/asio/detail/handler_cont_helpers.hpp>
0020 
0021 #include <boost/asio/detail/push_options.hpp>
0022 
0023 namespace boost {
0024 namespace asio {
0025 namespace detail {
0026 
0027 struct is_continuation_delegated
0028 {
0029   template <typename Dispatcher, typename Handler>
0030   bool operator()(Dispatcher&, Handler& handler) const
0031   {
0032     return boost_asio_handler_cont_helpers::is_continuation(handler);
0033   }
0034 };
0035 
0036 struct is_continuation_if_running
0037 {
0038   template <typename Dispatcher, typename Handler>
0039   bool operator()(Dispatcher& dispatcher, Handler&) const
0040   {
0041     return dispatcher.running_in_this_thread();
0042   }
0043 };
0044 
0045 template <typename Dispatcher, typename Handler,
0046     typename IsContinuation = is_continuation_delegated>
0047 class wrapped_handler
0048 {
0049 public:
0050   typedef void result_type;
0051 
0052   wrapped_handler(Dispatcher dispatcher, Handler& handler)
0053     : dispatcher_(dispatcher),
0054       handler_(static_cast<Handler&&>(handler))
0055   {
0056   }
0057 
0058   wrapped_handler(const wrapped_handler& other)
0059     : dispatcher_(other.dispatcher_),
0060       handler_(other.handler_)
0061   {
0062   }
0063 
0064   wrapped_handler(wrapped_handler&& other)
0065     : dispatcher_(other.dispatcher_),
0066       handler_(static_cast<Handler&&>(other.handler_))
0067   {
0068   }
0069 
0070   void operator()()
0071   {
0072     dispatcher_.dispatch(static_cast<Handler&&>(handler_));
0073   }
0074 
0075   void operator()() const
0076   {
0077     dispatcher_.dispatch(handler_);
0078   }
0079 
0080   template <typename Arg1>
0081   void operator()(const Arg1& arg1)
0082   {
0083     dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
0084   }
0085 
0086   template <typename Arg1>
0087   void operator()(const Arg1& arg1) const
0088   {
0089     dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
0090   }
0091 
0092   template <typename Arg1, typename Arg2>
0093   void operator()(const Arg1& arg1, const Arg2& arg2)
0094   {
0095     dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
0096   }
0097 
0098   template <typename Arg1, typename Arg2>
0099   void operator()(const Arg1& arg1, const Arg2& arg2) const
0100   {
0101     dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
0102   }
0103 
0104   template <typename Arg1, typename Arg2, typename Arg3>
0105   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
0106   {
0107     dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
0108   }
0109 
0110   template <typename Arg1, typename Arg2, typename Arg3>
0111   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const
0112   {
0113     dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
0114   }
0115 
0116   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
0117   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0118       const Arg4& arg4)
0119   {
0120     dispatcher_.dispatch(
0121         detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
0122   }
0123 
0124   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
0125   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0126       const Arg4& arg4) const
0127   {
0128     dispatcher_.dispatch(
0129         detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
0130   }
0131 
0132   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
0133       typename Arg5>
0134   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0135       const Arg4& arg4, const Arg5& arg5)
0136   {
0137     dispatcher_.dispatch(
0138         detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
0139   }
0140 
0141   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
0142       typename Arg5>
0143   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0144       const Arg4& arg4, const Arg5& arg5) const
0145   {
0146     dispatcher_.dispatch(
0147         detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
0148   }
0149 
0150 //private:
0151   Dispatcher dispatcher_;
0152   Handler handler_;
0153 };
0154 
0155 template <typename Handler, typename Context>
0156 class rewrapped_handler
0157 {
0158 public:
0159   explicit rewrapped_handler(Handler& handler, const Context& context)
0160     : context_(context),
0161       handler_(static_cast<Handler&&>(handler))
0162   {
0163   }
0164 
0165   explicit rewrapped_handler(const Handler& handler, const Context& context)
0166     : context_(context),
0167       handler_(handler)
0168   {
0169   }
0170 
0171   rewrapped_handler(const rewrapped_handler& other)
0172     : context_(other.context_),
0173       handler_(other.handler_)
0174   {
0175   }
0176 
0177   rewrapped_handler(rewrapped_handler&& other)
0178     : context_(static_cast<Context&&>(other.context_)),
0179       handler_(static_cast<Handler&&>(other.handler_))
0180   {
0181   }
0182 
0183   void operator()()
0184   {
0185     handler_();
0186   }
0187 
0188   void operator()() const
0189   {
0190     handler_();
0191   }
0192 
0193 //private:
0194   Context context_;
0195   Handler handler_;
0196 };
0197 
0198 template <typename Dispatcher, typename Handler, typename IsContinuation>
0199 inline bool asio_handler_is_continuation(
0200     wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
0201 {
0202   return IsContinuation()(this_handler->dispatcher_, this_handler->handler_);
0203 }
0204 
0205 template <typename Dispatcher, typename Context>
0206 inline bool asio_handler_is_continuation(
0207     rewrapped_handler<Dispatcher, Context>* this_handler)
0208 {
0209   return boost_asio_handler_cont_helpers::is_continuation(
0210       this_handler->context_);
0211 }
0212 
0213 } // namespace detail
0214 } // namespace asio
0215 } // namespace boost
0216 
0217 #include <boost/asio/detail/pop_options.hpp>
0218 
0219 #endif // BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP