2 // impl/execution_context.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_IMPL_EXECUTION_CONTEXT_HPP
12 #define BOOST_ASIO_IMPL_EXECUTION_CONTEXT_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/handler_type_requirements.hpp>
19 #include <boost/asio/detail/scoped_ptr.hpp>
20 #include <boost/asio/detail/service_registry.hpp>
22 #include <boost/asio/detail/push_options.hpp>
27 template <typename Service>
28 inline Service& use_service(execution_context& e)
30 // Check that Service meets the necessary type requirements.
31 (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
33 return e.service_registry_->template use_service<Service>();
36 #if !defined(GENERATING_DOCUMENTATION)
37 # if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
39 template <typename Service, typename... Args>
40 Service& make_service(execution_context& e, BOOST_ASIO_MOVE_ARG(Args)... args)
42 detail::scoped_ptr<Service> svc(
43 new Service(e, BOOST_ASIO_MOVE_CAST(Args)(args)...));
44 e.service_registry_->template add_service<Service>(svc.get());
45 Service& result = *svc;
50 # else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
52 template <typename Service>
53 Service& make_service(execution_context& e)
55 detail::scoped_ptr<Service> svc(new Service(e));
56 e.service_registry_->template add_service<Service>(svc.get());
57 Service& result = *svc;
62 #define BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF(n) \
63 template <typename Service, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
64 Service& make_service(execution_context& e, \
65 BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
67 detail::scoped_ptr<Service> svc( \
68 new Service(e, BOOST_ASIO_VARIADIC_MOVE_ARGS(n))); \
69 e.service_registry_->template add_service<Service>(svc.get()); \
70 Service& result = *svc; \
75 BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF)
76 #undef BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF
78 # endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
79 #endif // !defined(GENERATING_DOCUMENTATION)
81 template <typename Service>
82 inline void add_service(execution_context& e, Service* svc)
84 // Check that Service meets the necessary type requirements.
85 (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
87 e.service_registry_->template add_service<Service>(svc);
90 template <typename Service>
91 inline bool has_service(execution_context& e)
93 // Check that Service meets the necessary type requirements.
94 (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
96 return e.service_registry_->template has_service<Service>();
99 inline execution_context& execution_context::service::context()
107 #include <boost/asio/detail/pop_options.hpp>
109 #endif // BOOST_ASIO_IMPL_EXECUTION_CONTEXT_HPP