File indexing completed on 2025-01-18 09:29:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_BASIC_IO_OBJECT_HPP
0012 #define BOOST_ASIO_BASIC_IO_OBJECT_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/io_context.hpp>
0020
0021 #include <boost/asio/detail/push_options.hpp>
0022
0023 namespace boost {
0024 namespace asio {
0025
0026 namespace detail
0027 {
0028
0029 template <typename IoObjectService>
0030 class service_has_move
0031 {
0032 private:
0033 typedef IoObjectService service_type;
0034 typedef typename service_type::implementation_type implementation_type;
0035
0036 template <typename T, typename U>
0037 static auto asio_service_has_move_eval(T* t, U* u)
0038 -> decltype(t->move_construct(*u, *u), char());
0039 static char (&asio_service_has_move_eval(...))[2];
0040
0041 public:
0042 static const bool value =
0043 sizeof(asio_service_has_move_eval(
0044 static_cast<service_type*>(0),
0045 static_cast<implementation_type*>(0))) == 1;
0046 };
0047 }
0048
0049
0050
0051
0052
0053
0054 #if defined(GENERATING_DOCUMENTATION)
0055 template <typename IoObjectService>
0056 #else
0057 template <typename IoObjectService,
0058 bool Movable = detail::service_has_move<IoObjectService>::value>
0059 #endif
0060 class basic_io_object
0061 {
0062 public:
0063
0064 typedef IoObjectService service_type;
0065
0066
0067 typedef typename service_type::implementation_type implementation_type;
0068
0069 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079 boost::asio::io_context& get_io_context()
0080 {
0081 return service_.get_io_context();
0082 }
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093 boost::asio::io_context& get_io_service()
0094 {
0095 return service_.get_io_context();
0096 }
0097 #endif
0098
0099
0100 typedef boost::asio::io_context::executor_type executor_type;
0101
0102
0103 executor_type get_executor() noexcept
0104 {
0105 return service_.get_io_context().get_executor();
0106 }
0107
0108 protected:
0109
0110
0111
0112
0113
0114 explicit basic_io_object(boost::asio::io_context& io_context)
0115 : service_(boost::asio::use_service<IoObjectService>(io_context))
0116 {
0117 service_.construct(implementation_);
0118 }
0119
0120 #if defined(GENERATING_DOCUMENTATION)
0121
0122
0123
0124
0125
0126
0127
0128
0129 basic_io_object(basic_io_object&& other);
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 basic_io_object& operator=(basic_io_object&& other);
0140
0141
0142 template <typename IoObjectService1>
0143 basic_io_object(IoObjectService1& other_service,
0144 typename IoObjectService1::implementation_type& other_implementation);
0145 #endif
0146
0147
0148
0149
0150
0151
0152 ~basic_io_object()
0153 {
0154 service_.destroy(implementation_);
0155 }
0156
0157
0158 service_type& get_service()
0159 {
0160 return service_;
0161 }
0162
0163
0164 const service_type& get_service() const
0165 {
0166 return service_;
0167 }
0168
0169
0170 implementation_type& get_implementation()
0171 {
0172 return implementation_;
0173 }
0174
0175
0176 const implementation_type& get_implementation() const
0177 {
0178 return implementation_;
0179 }
0180
0181 private:
0182 basic_io_object(const basic_io_object&);
0183 basic_io_object& operator=(const basic_io_object&);
0184
0185
0186 service_type& service_;
0187
0188
0189 implementation_type implementation_;
0190 };
0191
0192
0193 template <typename IoObjectService>
0194 class basic_io_object<IoObjectService, true>
0195 {
0196 public:
0197 typedef IoObjectService service_type;
0198 typedef typename service_type::implementation_type implementation_type;
0199
0200 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0201 boost::asio::io_context& get_io_context()
0202 {
0203 return service_->get_io_context();
0204 }
0205
0206 boost::asio::io_context& get_io_service()
0207 {
0208 return service_->get_io_context();
0209 }
0210 #endif
0211
0212 typedef boost::asio::io_context::executor_type executor_type;
0213
0214 executor_type get_executor() noexcept
0215 {
0216 return service_->get_io_context().get_executor();
0217 }
0218
0219 protected:
0220 explicit basic_io_object(boost::asio::io_context& io_context)
0221 : service_(&boost::asio::use_service<IoObjectService>(io_context))
0222 {
0223 service_->construct(implementation_);
0224 }
0225
0226 basic_io_object(basic_io_object&& other)
0227 : service_(&other.get_service())
0228 {
0229 service_->move_construct(implementation_, other.implementation_);
0230 }
0231
0232 template <typename IoObjectService1>
0233 basic_io_object(IoObjectService1& other_service,
0234 typename IoObjectService1::implementation_type& other_implementation)
0235 : service_(&boost::asio::use_service<IoObjectService>(
0236 other_service.get_io_context()))
0237 {
0238 service_->converting_move_construct(implementation_,
0239 other_service, other_implementation);
0240 }
0241
0242 ~basic_io_object()
0243 {
0244 service_->destroy(implementation_);
0245 }
0246
0247 basic_io_object& operator=(basic_io_object&& other)
0248 {
0249 service_->move_assign(implementation_,
0250 *other.service_, other.implementation_);
0251 service_ = other.service_;
0252 return *this;
0253 }
0254
0255 service_type& get_service()
0256 {
0257 return *service_;
0258 }
0259
0260 const service_type& get_service() const
0261 {
0262 return *service_;
0263 }
0264
0265 implementation_type& get_implementation()
0266 {
0267 return implementation_;
0268 }
0269
0270 const implementation_type& get_implementation() const
0271 {
0272 return implementation_;
0273 }
0274
0275 private:
0276 basic_io_object(const basic_io_object&);
0277 void operator=(const basic_io_object&);
0278
0279 IoObjectService* service_;
0280 implementation_type implementation_;
0281 };
0282
0283 }
0284 }
0285
0286 #include <boost/asio/detail/pop_options.hpp>
0287
0288 #endif