channel_handler.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // experimental/detail/channel_handler.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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. #ifndef BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_HANDLER_HPP
  11. #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_HANDLER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/associator.hpp>
  17. #include <boost/asio/experimental/detail/channel_payload.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace experimental {
  22. namespace detail {
  23. template <typename Payload, typename Handler>
  24. class channel_handler
  25. {
  26. public:
  27. channel_handler(Payload&& p, Handler& h)
  28. : payload_(static_cast<Payload&&>(p)),
  29. handler_(static_cast<Handler&&>(h))
  30. {
  31. }
  32. void operator()()
  33. {
  34. payload_.receive(handler_);
  35. }
  36. //private:
  37. Payload payload_;
  38. Handler handler_;
  39. };
  40. } // namespace detail
  41. } // namespace experimental
  42. template <template <typename, typename> class Associator,
  43. typename Payload, typename Handler, typename DefaultCandidate>
  44. struct associator<Associator,
  45. experimental::detail::channel_handler<Payload, Handler>,
  46. DefaultCandidate>
  47. : Associator<Handler, DefaultCandidate>
  48. {
  49. static typename Associator<Handler, DefaultCandidate>::type get(
  50. const experimental::detail::channel_handler<Payload, Handler>& h) noexcept
  51. {
  52. return Associator<Handler, DefaultCandidate>::get(h.handler_);
  53. }
  54. static auto get(
  55. const experimental::detail::channel_handler<Payload, Handler>& h,
  56. const DefaultCandidate& c) noexcept
  57. -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
  58. {
  59. return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
  60. }
  61. };
  62. } // namespace asio
  63. } // namespace boost
  64. #include <boost/asio/detail/pop_options.hpp>
  65. #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_HANDLER_HPP