Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/asio/detail/impl/service_registry.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // | |
2 // detail/impl/service_registry.hpp | |
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
4 // | |
5 // Copyright (c) 2003-2013 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, typename Arg> | |
25 service_registry::service_registry( | |
26 boost::asio::io_service& o, Service*, Arg arg) | |
27 : owner_(o), | |
28 first_service_(new Service(o, arg)) | |
29 { | |
30 boost::asio::io_service::service::key key; | |
31 init_key(key, Service::id); | |
32 first_service_->key_ = key; | |
33 first_service_->next_ = 0; | |
34 } | |
35 | |
36 template <typename Service> | |
37 Service& service_registry::first_service() | |
38 { | |
39 return *static_cast<Service*>(first_service_); | |
40 } | |
41 | |
42 template <typename Service> | |
43 Service& service_registry::use_service() | |
44 { | |
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)); | |
49 } | |
50 | |
51 template <typename Service> | |
52 void service_registry::add_service(Service* new_service) | |
53 { | |
54 boost::asio::io_service::service::key key; | |
55 init_key(key, Service::id); | |
56 return do_add_service(key, new_service); | |
57 } | |
58 | |
59 template <typename Service> | |
60 bool service_registry::has_service() const | |
61 { | |
62 boost::asio::io_service::service::key key; | |
63 init_key(key, Service::id); | |
64 return do_has_service(key); | |
65 } | |
66 | |
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*/) | |
71 { | |
72 key.type_info_ = &typeid(typeid_wrapper<Service>); | |
73 key.id_ = 0; | |
74 } | |
75 #endif // !defined(BOOST_ASIO_NO_TYPEID) | |
76 | |
77 template <typename Service> | |
78 boost::asio::io_service::service* service_registry::create( | |
79 boost::asio::io_service& owner) | |
80 { | |
81 return new Service(owner); | |
82 } | |
83 | |
84 } // namespace detail | |
85 } // namespace asio | |
86 } // namespace boost | |
87 | |
88 #include <boost/asio/detail/pop_options.hpp> | |
89 | |
90 #endif // BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP |