File indexing completed on 2025-09-18 08:35:32
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
0020 #if !defined(BOOST_ASIO_NO_DEPRECATED) \
0021 || defined(GENERATING_DOCUMENTATION)
0022
0023 #include <boost/asio/io_context.hpp>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029
0030 namespace detail
0031 {
0032
0033 template <typename IoObjectService>
0034 class service_has_move
0035 {
0036 private:
0037 typedef IoObjectService service_type;
0038 typedef typename service_type::implementation_type implementation_type;
0039
0040 template <typename T, typename U>
0041 static auto asio_service_has_move_eval(T* t, U* u)
0042 -> decltype(t->move_construct(*u, *u), char());
0043 static char (&asio_service_has_move_eval(...))[2];
0044
0045 public:
0046 static const bool value =
0047 sizeof(asio_service_has_move_eval(
0048 static_cast<service_type*>(0),
0049 static_cast<implementation_type*>(0))) == 1;
0050 };
0051 }
0052
0053
0054
0055
0056
0057
0058 #if defined(GENERATING_DOCUMENTATION)
0059 template <typename IoObjectService>
0060 #else
0061 template <typename IoObjectService,
0062 bool Movable = detail::service_has_move<IoObjectService>::value>
0063 #endif
0064 class basic_io_object
0065 {
0066 public:
0067
0068 typedef IoObjectService service_type;
0069
0070
0071 typedef typename service_type::implementation_type implementation_type;
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 boost::asio::io_context& get_io_context()
0082 {
0083 return service_.get_io_context();
0084 }
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 boost::asio::io_context& get_io_service()
0095 {
0096 return service_.get_io_context();
0097 }
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 boost::asio::io_context& get_io_context()
0201 {
0202 return service_->get_io_context();
0203 }
0204
0205 boost::asio::io_context& get_io_service()
0206 {
0207 return service_->get_io_context();
0208 }
0209
0210 typedef boost::asio::io_context::executor_type executor_type;
0211
0212 executor_type get_executor() noexcept
0213 {
0214 return service_->get_io_context().get_executor();
0215 }
0216
0217 protected:
0218 explicit basic_io_object(boost::asio::io_context& io_context)
0219 : service_(&boost::asio::use_service<IoObjectService>(io_context))
0220 {
0221 service_->construct(implementation_);
0222 }
0223
0224 basic_io_object(basic_io_object&& other)
0225 : service_(&other.get_service())
0226 {
0227 service_->move_construct(implementation_, other.implementation_);
0228 }
0229
0230 template <typename IoObjectService1>
0231 basic_io_object(IoObjectService1& other_service,
0232 typename IoObjectService1::implementation_type& other_implementation)
0233 : service_(&boost::asio::use_service<IoObjectService>(
0234 other_service.get_io_context()))
0235 {
0236 service_->converting_move_construct(implementation_,
0237 other_service, other_implementation);
0238 }
0239
0240 ~basic_io_object()
0241 {
0242 service_->destroy(implementation_);
0243 }
0244
0245 basic_io_object& operator=(basic_io_object&& other)
0246 {
0247 service_->move_assign(implementation_,
0248 *other.service_, other.implementation_);
0249 service_ = other.service_;
0250 return *this;
0251 }
0252
0253 service_type& get_service()
0254 {
0255 return *service_;
0256 }
0257
0258 const service_type& get_service() const
0259 {
0260 return *service_;
0261 }
0262
0263 implementation_type& get_implementation()
0264 {
0265 return implementation_;
0266 }
0267
0268 const implementation_type& get_implementation() const
0269 {
0270 return implementation_;
0271 }
0272
0273 private:
0274 basic_io_object(const basic_io_object&);
0275 void operator=(const basic_io_object&);
0276
0277 IoObjectService* service_;
0278 implementation_type implementation_;
0279 };
0280
0281 }
0282 }
0283
0284 #include <boost/asio/detail/pop_options.hpp>
0285
0286 #endif
0287
0288
0289 #endif