]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/impl/service_registry.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / detail / impl / service_registry.hpp
1 //
2 // detail/impl/service_registry.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 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
11 #ifndef BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP
12 #define BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/push_options.hpp>
19
20 namespace boost {
21 namespace asio {
22 namespace detail {
23
24 template <typename Service>
25 Service& service_registry::use_service()
26 {
27 execution_context::service::key key;
28 init_key<Service>(key, 0);
29 factory_type factory = &service_registry::create<Service, execution_context>;
30 return *static_cast<Service*>(do_use_service(key, factory, &owner_));
31 }
32
33 template <typename Service>
34 Service& service_registry::use_service(io_context& owner)
35 {
36 execution_context::service::key key;
37 init_key<Service>(key, 0);
38 factory_type factory = &service_registry::create<Service, io_context>;
39 return *static_cast<Service*>(do_use_service(key, factory, &owner));
40 }
41
42 template <typename Service>
43 void service_registry::add_service(Service* new_service)
44 {
45 execution_context::service::key key;
46 init_key<Service>(key, 0);
47 return do_add_service(key, new_service);
48 }
49
50 template <typename Service>
51 bool service_registry::has_service() const
52 {
53 execution_context::service::key key;
54 init_key<Service>(key, 0);
55 return do_has_service(key);
56 }
57
58 template <typename Service>
59 inline void service_registry::init_key(
60 execution_context::service::key& key, ...)
61 {
62 init_key_from_id(key, Service::id);
63 }
64
65 #if !defined(BOOST_ASIO_NO_TYPEID)
66 template <typename Service>
67 void service_registry::init_key(execution_context::service::key& key,
68 typename enable_if<
69 is_base_of<typename Service::key_type, Service>::value>::type*)
70 {
71 key.type_info_ = &typeid(typeid_wrapper<Service>);
72 key.id_ = 0;
73 }
74
75 template <typename Service>
76 void service_registry::init_key_from_id(execution_context::service::key& key,
77 const service_id<Service>& /*id*/)
78 {
79 key.type_info_ = &typeid(typeid_wrapper<Service>);
80 key.id_ = 0;
81 }
82 #endif // !defined(BOOST_ASIO_NO_TYPEID)
83
84 template <typename Service, typename Owner>
85 execution_context::service* service_registry::create(void* owner)
86 {
87 return new Service(*static_cast<Owner*>(owner));
88 }
89
90 } // namespace detail
91 } // namespace asio
92 } // namespace boost
93
94 #include <boost/asio/detail/pop_options.hpp>
95
96 #endif // BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP