Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compose.hpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // compose.hpp
  3. // ~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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 ASIO_COMPOSE_HPP
  11. #define ASIO_COMPOSE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/async_result.hpp"
  17. #include "asio/detail/push_options.hpp"
  18. namespace asio {
  19. #if defined(ASIO_HAS_VARIADIC_TEMPLATES) \
  20. || defined(GENERATING_DOCUMENTATION)
  21. /// Launch an asynchronous operation with a stateful implementation.
  22. /**
  23. * The async_compose function simplifies the implementation of composed
  24. * asynchronous operations automatically wrapping a stateful function object
  25. * with a conforming intermediate completion handler.
  26. *
  27. * @param implementation A function object that contains the implementation of
  28. * the composed asynchronous operation. The first argument to the function
  29. * object is a non-const reference to the enclosing intermediate completion
  30. * handler. The remaining arguments are any arguments that originate from the
  31. * completion handlers of any asynchronous operations performed by the
  32. * implementation.
  33. * @param token The completion token.
  34. *
  35. * @param io_objects_or_executors Zero or more I/O objects or I/O executors for
  36. * which outstanding work must be maintained.
  37. *
  38. * @par Example:
  39. *
  40. * @code struct async_echo_implementation
  41. * {
  42. * tcp::socket& socket_;
  43. * asio::mutable_buffer buffer_;
  44. * enum { starting, reading, writing } state_;
  45. *
  46. * template <typename Self>
  47. * void operator()(Self& self,
  48. * asio::error_code error = {},
  49. * std::size_t n = 0)
  50. * {
  51. * switch (state_)
  52. * {
  53. * case starting:
  54. * state_ = reading;
  55. * socket_.async_read_some(
  56. * buffer_, std::move(self));
  57. * break;
  58. * case reading:
  59. * if (error)
  60. * {
  61. * self.complete(error, 0);
  62. * }
  63. * else
  64. * {
  65. * state_ = writing;
  66. * asio::async_write(socket_, buffer_,
  67. * asio::transfer_exactly(n),
  68. * std::move(self));
  69. * }
  70. * break;
  71. * case writing:
  72. * self.complete(error, n);
  73. * break;
  74. * }
  75. * }
  76. * };
  77. *
  78. * template <typename CompletionToken>
  79. * auto async_echo(tcp::socket& socket,
  80. * asio::mutable_buffer buffer,
  81. * CompletionToken&& token) ->
  82. * typename asio::async_result<
  83. * typename std::decay<CompletionToken>::type,
  84. * void(asio::error_code, std::size_t)>::return_type
  85. * {
  86. * return asio::async_compose<CompletionToken,
  87. * void(asio::error_code, std::size_t)>(
  88. * async_echo_implementation{socket, buffer,
  89. * async_echo_implementation::starting},
  90. * token, socket);
  91. * } @endcode
  92. */
  93. template <typename CompletionToken, typename Signature,
  94. typename Implementation, typename... IoObjectsOrExecutors>
  95. ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)
  96. async_compose(ASIO_MOVE_ARG(Implementation) implementation,
  97. ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token,
  98. ASIO_MOVE_ARG(IoObjectsOrExecutors)... io_objects_or_executors);
  99. #else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
  100. // || defined(GENERATING_DOCUMENTATION)
  101. template <typename CompletionToken, typename Signature, typename Implementation>
  102. ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)
  103. async_compose(ASIO_MOVE_ARG(Implementation) implementation,
  104. ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token);
  105. #define ASIO_PRIVATE_ASYNC_COMPOSE_DEF(n) \
  106. template <typename CompletionToken, typename Signature, \
  107. typename Implementation, ASIO_VARIADIC_TPARAMS(n)> \
  108. ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature) \
  109. async_compose(ASIO_MOVE_ARG(Implementation) implementation, \
  110. ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \
  111. ASIO_VARIADIC_MOVE_PARAMS(n));
  112. /**/
  113. ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_ASYNC_COMPOSE_DEF)
  114. #undef ASIO_PRIVATE_ASYNC_COMPOSE_DEF
  115. #endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
  116. // || defined(GENERATING_DOCUMENTATION)
  117. } // namespace asio
  118. #include "asio/detail/pop_options.hpp"
  119. #include "asio/impl/compose.hpp"
  120. #endif // ASIO_COMPOSE_HPP