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.

service_registry.hpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // detail/impl/service_registry.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_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(key, Service::id);
  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(key, Service::id);
  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(key, Service::id);
  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(key, Service::id);
  46. return do_has_service(key);
  47. }
  48. #if !defined(ASIO_NO_TYPEID)
  49. template <typename Service>
  50. void service_registry::init_key(execution_context::service::key& key,
  51. const service_id<Service>& /*id*/)
  52. {
  53. key.type_info_ = &typeid(typeid_wrapper<Service>);
  54. key.id_ = 0;
  55. }
  56. #endif // !defined(ASIO_NO_TYPEID)
  57. template <typename Service, typename Owner>
  58. execution_context::service* service_registry::create(void* owner)
  59. {
  60. return new Service(*static_cast<Owner*>(owner));
  61. }
  62. } // namespace detail
  63. } // namespace asio
  64. #include "asio/detail/pop_options.hpp"
  65. #endif // ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP