Realistic 3D camera system
3D camera system components
service_registry.hpp
Go to the documentation of this file.
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 
11 #ifndef ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP
12 #define 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 
19 
20 namespace asio {
21 namespace detail {
22 
23 template <typename Service, typename Arg>
25  asio::io_service& o, Service*, Arg arg)
26  : owner_(o),
27  first_service_(new Service(o, arg))
28 {
29  asio::io_service::service::key key;
30  init_key(key, Service::id);
31  first_service_->key_ = key;
32  first_service_->next_ = 0;
33 }
34 
35 template <typename Service>
37 {
38  return *static_cast<Service*>(first_service_);
39 }
40 
41 template <typename Service>
43 {
44  asio::io_service::service::key key;
45  init_key(key, Service::id);
46  factory_type factory = &service_registry::create<Service>;
47  return *static_cast<Service*>(do_use_service(key, factory));
48 }
49 
50 template <typename Service>
51 void service_registry::add_service(Service* new_service)
52 {
53  asio::io_service::service::key key;
54  init_key(key, Service::id);
55  return do_add_service(key, new_service);
56 }
57 
58 template <typename Service>
60 {
61  asio::io_service::service::key key;
62  init_key(key, Service::id);
63  return do_has_service(key);
64 }
65 
66 #if !defined(ASIO_NO_TYPEID)
67 template <typename Service>
68 void service_registry::init_key(asio::io_service::service::key& key,
70 {
71  key.type_info_ = &typeid(typeid_wrapper<Service>);
72  key.id_ = 0;
73 }
74 #endif // !defined(ASIO_NO_TYPEID)
75 
76 template <typename Service>
77 asio::io_service::service* service_registry::create(
78  asio::io_service& owner)
79 {
80  return new Service(owner);
81 }
82 
83 } // namespace detail
84 } // namespace asio
85 
87 
88 #endif // ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP
service_registry(asio::io_service &o, Service *initial_service, Arg arg)
Provides core I/O functionality.
Definition: io_service.hpp:184
void add_service(Service *new_service)
Base class for all io_service services.
Definition: io_service.hpp:674