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.

111 lines
3.2KB

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