2 // impl/execution_context.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2020 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 #if !defined(GENERATING_DOCUMENTATION)
29 template <typename Service>
30 inline Service& use_service(execution_context& e)
32 // Check that Service meets the necessary type requirements.
33 (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
35 return e.service_registry_->template use_service<Service>();
38 #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
40 template <typename Service, typename... Args>
41 Service& make_service(execution_context& e, BOOST_ASIO_MOVE_ARG(Args)... args)
43 detail::scoped_ptr<Service> svc(
44 new Service(e, BOOST_ASIO_MOVE_CAST(Args)(args)...));
45 e.service_registry_->template add_service<Service>(svc.get());
46 Service& result = *svc;
51 #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
53 template <typename Service>
54 Service& make_service(execution_context& e)
56 detail::scoped_ptr<Service> svc(new Service(e));
57 e.service_registry_->template add_service<Service>(svc.get());
58 Service& result = *svc;
63 #define BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF(n) \
64 template <typename Service, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
65 Service& make_service(execution_context& e, \
66 BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
68 detail::scoped_ptr<Service> svc( \
69 new Service(e, BOOST_ASIO_VARIADIC_MOVE_ARGS(n))); \
70 e.service_registry_->template add_service<Service>(svc.get()); \
71 Service& result = *svc; \
76 BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF)
77 #undef BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF
79 #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
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 #endif // !defined(GENERATING_DOCUMENTATION)
101 inline execution_context& execution_context::service::context()
109 #include <boost/asio/detail/pop_options.hpp>
111 #endif // BOOST_ASIO_IMPL_EXECUTION_CONTEXT_HPP