Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:23:24

0001 //
0002 // detail/wrapped_handler.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 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 #include <boost/asio/detail/initiate_dispatch.hpp>
0021 
0022 #include <boost/asio/detail/push_options.hpp>
0023 
0024 namespace boost {
0025 namespace asio {
0026 namespace detail {
0027 
0028 struct is_continuation_delegated
0029 {
0030   template <typename Dispatcher, typename Handler>
0031   bool operator()(Dispatcher&, Handler& handler) const
0032   {
0033     return boost_asio_handler_cont_helpers::is_continuation(handler);
0034   }
0035 };
0036 
0037 struct is_continuation_if_running
0038 {
0039   template <typename Dispatcher, typename Handler>
0040   bool operator()(Dispatcher& dispatcher, Handler&) const
0041   {
0042     return dispatcher.running_in_this_thread();
0043   }
0044 };
0045 
0046 template <typename Dispatcher, typename = void>
0047 struct wrapped_executor
0048 {
0049   typedef Dispatcher executor_type;
0050 
0051   static const Dispatcher& get(const Dispatcher& dispatcher) noexcept
0052   {
0053     return dispatcher;
0054   }
0055 };
0056 
0057 template <typename Dispatcher>
0058 struct wrapped_executor<Dispatcher,
0059     void_type<typename Dispatcher::executor_type>>
0060 {
0061   typedef typename Dispatcher::executor_type executor_type;
0062 
0063   static executor_type get(const Dispatcher& dispatcher) noexcept
0064   {
0065     return dispatcher.get_executor();
0066   }
0067 };
0068 
0069 template <typename Dispatcher, typename Handler,
0070     typename IsContinuation = is_continuation_delegated>
0071 class wrapped_handler
0072 {
0073 public:
0074   typedef void result_type;
0075   typedef typename wrapped_executor<Dispatcher>::executor_type executor_type;
0076 
0077   wrapped_handler(Dispatcher dispatcher, Handler& handler)
0078     : dispatcher_(dispatcher),
0079       handler_(static_cast<Handler&&>(handler))
0080   {
0081   }
0082 
0083   wrapped_handler(const wrapped_handler& other)
0084     : dispatcher_(other.dispatcher_),
0085       handler_(other.handler_)
0086   {
0087   }
0088 
0089   wrapped_handler(wrapped_handler&& other)
0090     : dispatcher_(other.dispatcher_),
0091       handler_(static_cast<Handler&&>(other.handler_))
0092   {
0093   }
0094 
0095   executor_type get_executor() const noexcept
0096   {
0097     return wrapped_executor<Dispatcher>::get(dispatcher_);
0098   }
0099 
0100   void operator()()
0101   {
0102     detail::initiate_dispatch_with_executor<executor_type>(
0103         this->get_executor())(static_cast<Handler&&>(handler_));
0104   }
0105 
0106   void operator()() const
0107   {
0108     detail::initiate_dispatch_with_executor<executor_type>(
0109         this->get_executor())(handler_);
0110   }
0111 
0112   template <typename Arg1>
0113   void operator()(const Arg1& arg1)
0114   {
0115     detail::initiate_dispatch_with_executor<executor_type>(
0116         this->get_executor())(detail::bind_handler(handler_, arg1));
0117   }
0118 
0119   template <typename Arg1>
0120   void operator()(const Arg1& arg1) const
0121   {
0122     detail::initiate_dispatch_with_executor<executor_type>(
0123         this->get_executor())(detail::bind_handler(handler_, arg1));
0124   }
0125 
0126   template <typename Arg1, typename Arg2>
0127   void operator()(const Arg1& arg1, const Arg2& arg2)
0128   {
0129     detail::initiate_dispatch_with_executor<executor_type>(
0130         this->get_executor())(detail::bind_handler(handler_, arg1, arg2));
0131   }
0132 
0133   template <typename Arg1, typename Arg2>
0134   void operator()(const Arg1& arg1, const Arg2& arg2) const
0135   {
0136     detail::initiate_dispatch_with_executor<executor_type>(
0137         this->get_executor())(detail::bind_handler(handler_, arg1, arg2));
0138   }
0139 
0140   template <typename Arg1, typename Arg2, typename Arg3>
0141   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
0142   {
0143     detail::initiate_dispatch_with_executor<executor_type>(
0144         this->get_executor())(detail::bind_handler(handler_, arg1, arg2, arg3));
0145   }
0146 
0147   template <typename Arg1, typename Arg2, typename Arg3>
0148   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const
0149   {
0150     detail::initiate_dispatch_with_executor<executor_type>(
0151         this->get_executor())(detail::bind_handler(handler_, arg1, arg2, arg3));
0152   }
0153 
0154   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
0155   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0156       const Arg4& arg4)
0157   {
0158     detail::initiate_dispatch_with_executor<executor_type>(
0159         this->get_executor())(
0160           detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
0161   }
0162 
0163   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
0164   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0165       const Arg4& arg4) const
0166   {
0167     detail::initiate_dispatch_with_executor<executor_type>(
0168         this->get_executor())(
0169           detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
0170   }
0171 
0172   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
0173       typename Arg5>
0174   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0175       const Arg4& arg4, const Arg5& arg5)
0176   {
0177     detail::initiate_dispatch_with_executor<executor_type>(
0178         this->get_executor())(
0179           detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
0180   }
0181 
0182   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
0183       typename Arg5>
0184   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0185       const Arg4& arg4, const Arg5& arg5) const
0186   {
0187     detail::initiate_dispatch_with_executor<executor_type>(
0188         this->get_executor())(
0189           detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
0190   }
0191 
0192 //private:
0193   Dispatcher dispatcher_;
0194   Handler handler_;
0195 };
0196 
0197 template <typename Dispatcher, typename Handler, typename IsContinuation>
0198 inline bool asio_handler_is_continuation(
0199     wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
0200 {
0201   return IsContinuation()(this_handler->dispatcher_, this_handler->handler_);
0202 }
0203 
0204 } // namespace detail
0205 } // namespace asio
0206 } // namespace boost
0207 
0208 #include <boost/asio/detail/pop_options.hpp>
0209 
0210 #endif // BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP