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.

associated_executor.hpp 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // associated_executor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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_ASSOCIATED_EXECUTOR_HPP
  11. #define ASIO_ASSOCIATED_EXECUTOR_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/detail/type_traits.hpp"
  17. #include "asio/is_executor.hpp"
  18. #include "asio/system_executor.hpp"
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. namespace detail {
  22. template <typename>
  23. struct associated_executor_check
  24. {
  25. typedef void type;
  26. };
  27. template <typename T, typename E, typename = void>
  28. struct associated_executor_impl
  29. {
  30. typedef E type;
  31. static type get(const T&, const E& e) ASIO_NOEXCEPT
  32. {
  33. return e;
  34. }
  35. };
  36. template <typename T, typename E>
  37. struct associated_executor_impl<T, E,
  38. typename associated_executor_check<typename T::executor_type>::type>
  39. {
  40. typedef typename T::executor_type type;
  41. static type get(const T& t, const E&) ASIO_NOEXCEPT
  42. {
  43. return t.get_executor();
  44. }
  45. };
  46. } // namespace detail
  47. /// Traits type used to obtain the executor associated with an object.
  48. /**
  49. * A program may specialise this traits type if the @c T template parameter in
  50. * the specialisation is a user-defined type. The template parameter @c
  51. * Executor shall be a type meeting the Executor requirements.
  52. *
  53. * Specialisations shall meet the following requirements, where @c t is a const
  54. * reference to an object of type @c T, and @c e is an object of type @c
  55. * Executor.
  56. *
  57. * @li Provide a nested typedef @c type that identifies a type meeting the
  58. * Executor requirements.
  59. *
  60. * @li Provide a noexcept static member function named @c get, callable as @c
  61. * get(t) and with return type @c type.
  62. *
  63. * @li Provide a noexcept static member function named @c get, callable as @c
  64. * get(t,e) and with return type @c type.
  65. */
  66. template <typename T, typename Executor = system_executor>
  67. struct associated_executor
  68. {
  69. /// If @c T has a nested type @c executor_type, <tt>T::executor_type</tt>.
  70. /// Otherwise @c Executor.
  71. #if defined(GENERATING_DOCUMENTATION)
  72. typedef see_below type;
  73. #else // defined(GENERATING_DOCUMENTATION)
  74. typedef typename detail::associated_executor_impl<T, Executor>::type type;
  75. #endif // defined(GENERATING_DOCUMENTATION)
  76. /// If @c T has a nested type @c executor_type, returns
  77. /// <tt>t.get_executor()</tt>. Otherwise returns @c ex.
  78. static type get(const T& t,
  79. const Executor& ex = Executor()) ASIO_NOEXCEPT
  80. {
  81. return detail::associated_executor_impl<T, Executor>::get(t, ex);
  82. }
  83. };
  84. /// Helper function to obtain an object's associated executor.
  85. /**
  86. * @returns <tt>associated_executor<T>::get(t)</tt>
  87. */
  88. template <typename T>
  89. inline typename associated_executor<T>::type
  90. get_associated_executor(const T& t) ASIO_NOEXCEPT
  91. {
  92. return associated_executor<T>::get(t);
  93. }
  94. /// Helper function to obtain an object's associated executor.
  95. /**
  96. * @returns <tt>associated_executor<T, Executor>::get(t, ex)</tt>
  97. */
  98. template <typename T, typename Executor>
  99. inline typename associated_executor<T, Executor>::type
  100. get_associated_executor(const T& t, const Executor& ex,
  101. typename enable_if<is_executor<
  102. Executor>::value>::type* = 0) ASIO_NOEXCEPT
  103. {
  104. return associated_executor<T, Executor>::get(t, ex);
  105. }
  106. /// Helper function to obtain an object's associated executor.
  107. /**
  108. * @returns <tt>associated_executor<T, typename
  109. * ExecutionContext::executor_type>::get(t, ctx.get_executor())</tt>
  110. */
  111. template <typename T, typename ExecutionContext>
  112. inline typename associated_executor<T,
  113. typename ExecutionContext::executor_type>::type
  114. get_associated_executor(const T& t, ExecutionContext& ctx,
  115. typename enable_if<is_convertible<ExecutionContext&,
  116. execution_context&>::value>::type* = 0) ASIO_NOEXCEPT
  117. {
  118. return associated_executor<T,
  119. typename ExecutionContext::executor_type>::get(t, ctx.get_executor());
  120. }
  121. } // namespace asio
  122. #include "asio/detail/pop_options.hpp"
  123. #endif // ASIO_ASSOCIATED_EXECUTOR_HPP