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.

110 lines
3.0KB

  1. //
  2. // impl/execution_context.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_IMPL_EXECUTION_CONTEXT_HPP
  11. #define ASIO_IMPL_EXECUTION_CONTEXT_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/handler_type_requirements.hpp"
  16. #include "asio/detail/scoped_ptr.hpp"
  17. #include "asio/detail/service_registry.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. #if !defined(GENERATING_DOCUMENTATION)
  21. template <typename Service>
  22. inline Service& use_service(execution_context& e)
  23. {
  24. // Check that Service meets the necessary type requirements.
  25. (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
  26. return e.service_registry_->template use_service<Service>();
  27. }
  28. #if defined(ASIO_HAS_VARIADIC_TEMPLATES)
  29. template <typename Service, typename... Args>
  30. Service& make_service(execution_context& e, ASIO_MOVE_ARG(Args)... args)
  31. {
  32. detail::scoped_ptr<Service> svc(
  33. new Service(e, ASIO_MOVE_CAST(Args)(args)...));
  34. e.service_registry_->template add_service<Service>(svc.get());
  35. Service& result = *svc;
  36. svc.release();
  37. return result;
  38. }
  39. #else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
  40. template <typename Service>
  41. Service& make_service(execution_context& e)
  42. {
  43. detail::scoped_ptr<Service> svc(new Service(e));
  44. e.service_registry_->template add_service<Service>(svc.get());
  45. Service& result = *svc;
  46. svc.release();
  47. return result;
  48. }
  49. #define ASIO_PRIVATE_MAKE_SERVICE_DEF(n) \
  50. template <typename Service, ASIO_VARIADIC_TPARAMS(n)> \
  51. Service& make_service(execution_context& e, \
  52. ASIO_VARIADIC_MOVE_PARAMS(n)) \
  53. { \
  54. detail::scoped_ptr<Service> svc( \
  55. new Service(e, ASIO_VARIADIC_MOVE_ARGS(n))); \
  56. e.service_registry_->template add_service<Service>(svc.get()); \
  57. Service& result = *svc; \
  58. svc.release(); \
  59. return result; \
  60. } \
  61. /**/
  62. ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_MAKE_SERVICE_DEF)
  63. #undef ASIO_PRIVATE_MAKE_SERVICE_DEF
  64. #endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
  65. template <typename Service>
  66. inline void add_service(execution_context& e, Service* svc)
  67. {
  68. // Check that Service meets the necessary type requirements.
  69. (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
  70. e.service_registry_->template add_service<Service>(svc);
  71. }
  72. template <typename Service>
  73. inline bool has_service(execution_context& e)
  74. {
  75. // Check that Service meets the necessary type requirements.
  76. (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
  77. return e.service_registry_->template has_service<Service>();
  78. }
  79. #endif // !defined(GENERATING_DOCUMENTATION)
  80. inline execution_context& execution_context::service::context()
  81. {
  82. return owner_;
  83. }
  84. } // namespace asio
  85. #include "asio/detail/pop_options.hpp"
  86. #endif // ASIO_IMPL_EXECUTION_CONTEXT_HPP