2 // detail/impl/service_registry.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP
12 #define BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/push_options.hpp>
24 template <typename Service, typename Arg>
25 service_registry::service_registry(
26 boost::asio::io_service& o, Service*, Arg arg)
28 first_service_(new Service(o, arg))
30 boost::asio::io_service::service::key key;
31 init_key(key, Service::id);
32 first_service_->key_ = key;
33 first_service_->next_ = 0;
36 template <typename Service>
37 Service& service_registry::first_service()
39 return *static_cast<Service*>(first_service_);
42 template <typename Service>
43 Service& service_registry::use_service()
45 boost::asio::io_service::service::key key;
46 init_key(key, Service::id);
47 factory_type factory = &service_registry::create<Service>;
48 return *static_cast<Service*>(do_use_service(key, factory));
51 template <typename Service>
52 void service_registry::add_service(Service* new_service)
54 boost::asio::io_service::service::key key;
55 init_key(key, Service::id);
56 return do_add_service(key, new_service);
59 template <typename Service>
60 bool service_registry::has_service() const
62 boost::asio::io_service::service::key key;
63 init_key(key, Service::id);
64 return do_has_service(key);
67 #if !defined(BOOST_ASIO_NO_TYPEID)
68 template <typename Service>
69 void service_registry::init_key(boost::asio::io_service::service::key& key,
70 const boost::asio::detail::service_id<Service>& /*id*/)
72 key.type_info_ = &typeid(typeid_wrapper<Service>);
75 #endif // !defined(BOOST_ASIO_NO_TYPEID)
77 template <typename Service>
78 boost::asio::io_service::service* service_registry::create(
79 boost::asio::io_service& owner)
81 return new Service(owner);
88 #include <boost/asio/detail/pop_options.hpp>
90 #endif // BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP