Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:39

0001 //
0002 // io_object_impl.hpp
0003 // ~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_IO_OBJECT_IMPL_HPP
0012 #define BOOST_ASIO_DETAIL_IO_OBJECT_IMPL_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <new>
0019 #include <boost/asio/detail/config.hpp>
0020 #include <boost/asio/detail/type_traits.hpp>
0021 #include <boost/asio/execution/executor.hpp>
0022 #include <boost/asio/execution/context.hpp>
0023 #include <boost/asio/io_context.hpp>
0024 #include <boost/asio/query.hpp>
0025 
0026 #include <boost/asio/detail/push_options.hpp>
0027 
0028 namespace boost {
0029 namespace asio {
0030 namespace detail {
0031 
0032 template <typename IoObjectService,
0033     typename Executor = io_context::executor_type>
0034 class io_object_impl
0035 {
0036 public:
0037   // The type of the service that will be used to provide I/O operations.
0038   typedef IoObjectService service_type;
0039 
0040   // The underlying implementation type of I/O object.
0041   typedef typename service_type::implementation_type implementation_type;
0042 
0043   // The type of the executor associated with the object.
0044   typedef Executor executor_type;
0045 
0046   // Construct an I/O object using an executor.
0047   explicit io_object_impl(int, const executor_type& ex)
0048     : service_(&boost::asio::use_service<IoObjectService>(
0049           io_object_impl::get_context(ex))),
0050       executor_(ex)
0051   {
0052     service_->construct(implementation_);
0053   }
0054 
0055   // Construct an I/O object using an execution context.
0056   template <typename ExecutionContext>
0057   explicit io_object_impl(int, int, ExecutionContext& context)
0058     : service_(&boost::asio::use_service<IoObjectService>(context)),
0059       executor_(context.get_executor())
0060   {
0061     service_->construct(implementation_);
0062   }
0063 
0064   // Move-construct an I/O object.
0065   io_object_impl(io_object_impl&& other)
0066     : service_(&other.get_service()),
0067       executor_(other.get_executor())
0068   {
0069     service_->move_construct(implementation_, other.implementation_);
0070   }
0071 
0072   // Perform converting move-construction of an I/O object on the same service.
0073   template <typename Executor1>
0074   io_object_impl(io_object_impl<IoObjectService, Executor1>&& other)
0075     : service_(&other.get_service()),
0076       executor_(other.get_executor())
0077   {
0078     service_->move_construct(implementation_, other.get_implementation());
0079   }
0080 
0081   // Perform converting move-construction of an I/O object on another service.
0082   template <typename IoObjectService1, typename Executor1>
0083   io_object_impl(io_object_impl<IoObjectService1, Executor1>&& other)
0084     : service_(&boost::asio::use_service<IoObjectService>(
0085             io_object_impl::get_context(other.get_executor()))),
0086       executor_(other.get_executor())
0087   {
0088     service_->converting_move_construct(implementation_,
0089         other.get_service(), other.get_implementation());
0090   }
0091 
0092   // Destructor.
0093   ~io_object_impl()
0094   {
0095     service_->destroy(implementation_);
0096   }
0097 
0098   // Move-assign an I/O object.
0099   io_object_impl& operator=(io_object_impl&& other)
0100   {
0101     if (this != &other)
0102     {
0103       service_->move_assign(implementation_,
0104           *other.service_, other.implementation_);
0105       executor_.~executor_type();
0106       new (&executor_) executor_type(other.executor_);
0107       service_ = other.service_;
0108     }
0109     return *this;
0110   }
0111 
0112   // Get the executor associated with the object.
0113   const executor_type& get_executor() noexcept
0114   {
0115     return executor_;
0116   }
0117 
0118   // Get the service associated with the I/O object.
0119   service_type& get_service()
0120   {
0121     return *service_;
0122   }
0123 
0124   // Get the service associated with the I/O object.
0125   const service_type& get_service() const
0126   {
0127     return *service_;
0128   }
0129 
0130   // Get the underlying implementation of the I/O object.
0131   implementation_type& get_implementation()
0132   {
0133     return implementation_;
0134   }
0135 
0136   // Get the underlying implementation of the I/O object.
0137   const implementation_type& get_implementation() const
0138   {
0139     return implementation_;
0140   }
0141 
0142 private:
0143   // Helper function to get an executor's context.
0144   template <typename T>
0145   static execution_context& get_context(const T& t,
0146       enable_if_t<execution::is_executor<T>::value>* = 0)
0147   {
0148     return boost::asio::query(t, execution::context);
0149   }
0150 
0151   // Helper function to get an executor's context.
0152   template <typename T>
0153   static execution_context& get_context(const T& t,
0154       enable_if_t<!execution::is_executor<T>::value>* = 0)
0155   {
0156     return t.context();
0157   }
0158 
0159   // Disallow copying and copy assignment.
0160   io_object_impl(const io_object_impl&);
0161   io_object_impl& operator=(const io_object_impl&);
0162 
0163   // The service associated with the I/O object.
0164   service_type* service_;
0165 
0166   // The underlying implementation of the I/O object.
0167   implementation_type implementation_;
0168 
0169   // The associated executor.
0170   executor_type executor_;
0171 };
0172 
0173 } // namespace detail
0174 } // namespace asio
0175 } // namespace boost
0176 
0177 #include <boost/asio/detail/pop_options.hpp>
0178 
0179 #endif // BOOST_ASIO_DETAIL_IO_OBJECT_IMPL_HPP