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.

95 lines
2.5KB

  1. //
  2. // detail/impl/service_registry.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_DETAIL_IMPL_SERVICE_REGISTRY_HPP
  11. #define ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/push_options.hpp"
  16. namespace asio {
  17. namespace detail {
  18. template <typename Service>
  19. Service& service_registry::use_service()
  20. {
  21. execution_context::service::key key;
  22. init_key<Service>(key, 0);
  23. factory_type factory = &service_registry::create<Service, execution_context>;
  24. return *static_cast<Service*>(do_use_service(key, factory, &owner_));
  25. }
  26. template <typename Service>
  27. Service& service_registry::use_service(io_context& owner)
  28. {
  29. execution_context::service::key key;
  30. init_key<Service>(key, 0);
  31. factory_type factory = &service_registry::create<Service, io_context>;
  32. return *static_cast<Service*>(do_use_service(key, factory, &owner));
  33. }
  34. template <typename Service>
  35. void service_registry::add_service(Service* new_service)
  36. {
  37. execution_context::service::key key;
  38. init_key<Service>(key, 0);
  39. return do_add_service(key, new_service);
  40. }
  41. template <typename Service>
  42. bool service_registry::has_service() const
  43. {
  44. execution_context::service::key key;
  45. init_key<Service>(key, 0);
  46. return do_has_service(key);
  47. }
  48. template <typename Service>
  49. inline void service_registry::init_key(
  50. execution_context::service::key& key, ...)
  51. {
  52. init_key_from_id(key, Service::id);
  53. }
  54. #if !defined(ASIO_NO_TYPEID)
  55. template <typename Service>
  56. void service_registry::init_key(execution_context::service::key& key,
  57. typename enable_if<
  58. is_base_of<typename Service::key_type, Service>::value>::type*)
  59. {
  60. key.type_info_ = &typeid(typeid_wrapper<Service>);
  61. key.id_ = 0;
  62. }
  63. template <typename Service>
  64. void service_registry::init_key_from_id(execution_context::service::key& key,
  65. const service_id<Service>& /*id*/)
  66. {
  67. key.type_info_ = &typeid(typeid_wrapper<Service>);
  68. key.id_ = 0;
  69. }
  70. #endif // !defined(ASIO_NO_TYPEID)
  71. template <typename Service, typename Owner>
  72. execution_context::service* service_registry::create(void* owner)
  73. {
  74. return new Service(*static_cast<Owner*>(owner));
  75. }
  76. } // namespace detail
  77. } // namespace asio
  78. #include "asio/detail/pop_options.hpp"
  79. #endif // ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP