1//
2// impl/execution_context.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2024 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_IMPL_EXECUTION_CONTEXT_HPP
12#define BOOST_ASIO_IMPL_EXECUTION_CONTEXT_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/handler_type_requirements.hpp>
19#include <boost/asio/detail/scoped_ptr.hpp>
20#include <boost/asio/detail/service_registry.hpp>
21
22#include <boost/asio/detail/push_options.hpp>
23
24namespace boost {
25namespace asio {
26
27#if !defined(GENERATING_DOCUMENTATION)
28
29template <typename Service>
30inline Service& use_service(execution_context& e)
31{
32 // Check that Service meets the necessary type requirements.
33 (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
34
35 return e.service_registry_->template use_service<Service>();
36}
37
38template <typename Service, typename... Args>
39Service& make_service(execution_context& e, Args&&... args)
40{
41 detail::scoped_ptr<Service> svc(
42 new Service(e, static_cast<Args&&>(args)...));
43 e.service_registry_->template add_service<Service>(svc.get());
44 Service& result = *svc;
45 svc.release();
46 return result;
47}
48
49template <typename Service>
50inline void add_service(execution_context& e, Service* svc)
51{
52 // Check that Service meets the necessary type requirements.
53 (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
54
55 e.service_registry_->template add_service<Service>(svc);
56}
57
58template <typename Service>
59inline bool has_service(execution_context& e)
60{
61 // Check that Service meets the necessary type requirements.
62 (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
63
64 return e.service_registry_->template has_service<Service>();
65}
66
67#endif // !defined(GENERATING_DOCUMENTATION)
68
69inline execution_context& execution_context::service::context()
70{
71 return owner_;
72}
73
74} // namespace asio
75} // namespace boost
76
77#include <boost/asio/detail/pop_options.hpp>
78
79#endif // BOOST_ASIO_IMPL_EXECUTION_CONTEXT_HPP
80

source code of boost/libs/asio/include/boost/asio/impl/execution_context.hpp