Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-13 08:42:06

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         empty_work_function());
0105   }
0106 
0107   void operator()() const
0108   {
0109     detail::initiate_dispatch_with_executor<executor_type>(
0110         this->get_executor())(handler_, empty_work_function());
0111   }
0112 
0113   template <typename Arg1>
0114   void operator()(const Arg1& arg1)
0115   {
0116     detail::initiate_dispatch_with_executor<executor_type>(
0117         this->get_executor())(detail::bind_handler(handler_, arg1),
0118         empty_work_function());
0119   }
0120 
0121   template <typename Arg1>
0122   void operator()(const Arg1& arg1) const
0123   {
0124     detail::initiate_dispatch_with_executor<executor_type>(
0125         this->get_executor())(detail::bind_handler(handler_, arg1),
0126         empty_work_function());
0127   }
0128 
0129   template <typename Arg1, typename Arg2>
0130   void operator()(const Arg1& arg1, const Arg2& arg2)
0131   {
0132     detail::initiate_dispatch_with_executor<executor_type>(
0133         this->get_executor())(detail::bind_handler(handler_, arg1, arg2),
0134         empty_work_function());
0135   }
0136 
0137   template <typename Arg1, typename Arg2>
0138   void operator()(const Arg1& arg1, const Arg2& arg2) const
0139   {
0140     detail::initiate_dispatch_with_executor<executor_type>(
0141         this->get_executor())(detail::bind_handler(handler_, arg1, arg2),
0142         empty_work_function());
0143   }
0144 
0145   template <typename Arg1, typename Arg2, typename Arg3>
0146   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
0147   {
0148     detail::initiate_dispatch_with_executor<executor_type>(
0149         this->get_executor())(detail::bind_handler(handler_, arg1, arg2, arg3),
0150         empty_work_function());
0151   }
0152 
0153   template <typename Arg1, typename Arg2, typename Arg3>
0154   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const
0155   {
0156     detail::initiate_dispatch_with_executor<executor_type>(
0157         this->get_executor())(detail::bind_handler(handler_, arg1, arg2, arg3),
0158         empty_work_function());
0159   }
0160 
0161   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
0162   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0163       const Arg4& arg4)
0164   {
0165     detail::initiate_dispatch_with_executor<executor_type>(
0166         this->get_executor())(
0167           detail::bind_handler(handler_, arg1, arg2, arg3, arg4),
0168           empty_work_function());
0169   }
0170 
0171   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
0172   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0173       const Arg4& arg4) const
0174   {
0175     detail::initiate_dispatch_with_executor<executor_type>(
0176         this->get_executor())(
0177           detail::bind_handler(handler_, arg1, arg2, arg3, arg4),
0178           empty_work_function());
0179   }
0180 
0181   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
0182       typename Arg5>
0183   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0184       const Arg4& arg4, const Arg5& arg5)
0185   {
0186     detail::initiate_dispatch_with_executor<executor_type>(
0187         this->get_executor())(
0188           detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5),
0189           empty_work_function());
0190   }
0191 
0192   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
0193       typename Arg5>
0194   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0195       const Arg4& arg4, const Arg5& arg5) const
0196   {
0197     detail::initiate_dispatch_with_executor<executor_type>(
0198         this->get_executor())(
0199           detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5),
0200           empty_work_function());
0201   }
0202 
0203 //private:
0204   Dispatcher dispatcher_;
0205   Handler handler_;
0206 };
0207 
0208 template <typename Dispatcher, typename Handler, typename IsContinuation>
0209 inline bool asio_handler_is_continuation(
0210     wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
0211 {
0212   return IsContinuation()(this_handler->dispatcher_, this_handler->handler_);
0213 }
0214 
0215 } // namespace detail
0216 } // namespace asio
0217 } // namespace boost
0218 
0219 #include <boost/asio/detail/pop_options.hpp>
0220 
0221 #endif // BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP