File indexing completed on 2025-01-18 09:28:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP
0012 #define BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/push_options.hpp>
0019
0020 namespace boost {
0021 namespace asio {
0022 namespace detail {
0023
0024 template <typename Service>
0025 Service& service_registry::use_service()
0026 {
0027 execution_context::service::key key;
0028 init_key<Service>(key, 0);
0029 factory_type factory = &service_registry::create<Service, execution_context>;
0030 return *static_cast<Service*>(do_use_service(key, factory, &owner_));
0031 }
0032
0033 template <typename Service>
0034 Service& service_registry::use_service(io_context& owner)
0035 {
0036 execution_context::service::key key;
0037 init_key<Service>(key, 0);
0038 factory_type factory = &service_registry::create<Service, io_context>;
0039 return *static_cast<Service*>(do_use_service(key, factory, &owner));
0040 }
0041
0042 template <typename Service>
0043 void service_registry::add_service(Service* new_service)
0044 {
0045 execution_context::service::key key;
0046 init_key<Service>(key, 0);
0047 return do_add_service(key, new_service);
0048 }
0049
0050 template <typename Service>
0051 bool service_registry::has_service() const
0052 {
0053 execution_context::service::key key;
0054 init_key<Service>(key, 0);
0055 return do_has_service(key);
0056 }
0057
0058 template <typename Service>
0059 inline void service_registry::init_key(
0060 execution_context::service::key& key, ...)
0061 {
0062 init_key_from_id(key, Service::id);
0063 }
0064
0065 #if !defined(BOOST_ASIO_NO_TYPEID)
0066 template <typename Service>
0067 void service_registry::init_key(execution_context::service::key& key,
0068 enable_if_t<is_base_of<typename Service::key_type, Service>::value>*)
0069 {
0070 key.type_info_ = &typeid(typeid_wrapper<Service>);
0071 key.id_ = 0;
0072 }
0073
0074 template <typename Service>
0075 void service_registry::init_key_from_id(execution_context::service::key& key,
0076 const service_id<Service>& )
0077 {
0078 key.type_info_ = &typeid(typeid_wrapper<Service>);
0079 key.id_ = 0;
0080 }
0081 #endif
0082
0083 template <typename Service, typename Owner>
0084 execution_context::service* service_registry::create(void* owner)
0085 {
0086 return new Service(*static_cast<Owner*>(owner));
0087 }
0088
0089 }
0090 }
0091 }
0092
0093 #include <boost/asio/detail/pop_options.hpp>
0094
0095 #endif