execution_context.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef BOOST_ASIO_IMPL_EXECUTION_CONTEXT_HPP
  11. #define BOOST_ASIO_IMPL_EXECUTION_CONTEXT_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/handler_type_requirements.hpp>
  16. #include <boost/asio/detail/scoped_ptr.hpp>
  17. #include <boost/asio/detail/service_registry.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. #if !defined(GENERATING_DOCUMENTATION)
  22. template <typename Service>
  23. inline Service& use_service(execution_context& e)
  24. {
  25. // Check that Service meets the necessary type requirements.
  26. (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
  27. return e.service_registry_->template use_service<Service>();
  28. }
  29. template <typename Service, typename... Args>
  30. Service& make_service(execution_context& e, Args&&... args)
  31. {
  32. detail::scoped_ptr<Service> svc(
  33. new Service(e, static_cast<Args&&>(args)...));
  34. e.service_registry_->template add_service<Service>(svc.get());
  35. Service& result = *svc;
  36. svc.release();
  37. return result;
  38. }
  39. template <typename Service>
  40. inline void add_service(execution_context& e, Service* svc)
  41. {
  42. // Check that Service meets the necessary type requirements.
  43. (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
  44. e.service_registry_->template add_service<Service>(svc);
  45. }
  46. template <typename Service>
  47. inline bool has_service(execution_context& e)
  48. {
  49. // Check that Service meets the necessary type requirements.
  50. (void)static_cast<execution_context::service*>(static_cast<Service*>(0));
  51. return e.service_registry_->template has_service<Service>();
  52. }
  53. #endif // !defined(GENERATING_DOCUMENTATION)
  54. inline execution_context& execution_context::service::context()
  55. {
  56. return owner_;
  57. }
  58. } // namespace asio
  59. } // namespace boost
  60. #include <boost/asio/detail/pop_options.hpp>
  61. #endif // BOOST_ASIO_IMPL_EXECUTION_CONTEXT_HPP