annotate DEPENDENCIES/generic/include/boost/asio/basic_io_object.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // basic_io_object.hpp
Chris@16 3 // ~~~~~~~~~~~~~~~~~~~
Chris@16 4 //
Chris@101 5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
Chris@16 6 //
Chris@16 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 //
Chris@16 10
Chris@16 11 #ifndef BOOST_ASIO_BASIC_IO_OBJECT_HPP
Chris@16 12 #define BOOST_ASIO_BASIC_IO_OBJECT_HPP
Chris@16 13
Chris@16 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 15 # pragma once
Chris@16 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 17
Chris@16 18 #include <boost/asio/detail/config.hpp>
Chris@16 19 #include <boost/asio/io_service.hpp>
Chris@16 20
Chris@16 21 #include <boost/asio/detail/push_options.hpp>
Chris@16 22
Chris@16 23 namespace boost {
Chris@16 24 namespace asio {
Chris@16 25
Chris@16 26 #if defined(BOOST_ASIO_HAS_MOVE)
Chris@16 27 namespace detail
Chris@16 28 {
Chris@16 29 // Type trait used to determine whether a service supports move.
Chris@16 30 template <typename IoObjectService>
Chris@16 31 class service_has_move
Chris@16 32 {
Chris@16 33 private:
Chris@16 34 typedef IoObjectService service_type;
Chris@16 35 typedef typename service_type::implementation_type implementation_type;
Chris@16 36
Chris@16 37 template <typename T, typename U>
Chris@16 38 static auto eval(T* t, U* u) -> decltype(t->move_construct(*u, *u), char());
Chris@16 39 static char (&eval(...))[2];
Chris@16 40
Chris@16 41 public:
Chris@16 42 static const bool value =
Chris@16 43 sizeof(service_has_move::eval(
Chris@16 44 static_cast<service_type*>(0),
Chris@16 45 static_cast<implementation_type*>(0))) == 1;
Chris@16 46 };
Chris@16 47 }
Chris@16 48 #endif // defined(BOOST_ASIO_HAS_MOVE)
Chris@16 49
Chris@16 50 /// Base class for all I/O objects.
Chris@16 51 /**
Chris@16 52 * @note All I/O objects are non-copyable. However, when using C++0x, certain
Chris@16 53 * I/O objects do support move construction and move assignment.
Chris@16 54 */
Chris@16 55 #if !defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
Chris@16 56 template <typename IoObjectService>
Chris@16 57 #else
Chris@16 58 template <typename IoObjectService,
Chris@16 59 bool Movable = detail::service_has_move<IoObjectService>::value>
Chris@16 60 #endif
Chris@16 61 class basic_io_object
Chris@16 62 {
Chris@16 63 public:
Chris@16 64 /// The type of the service that will be used to provide I/O operations.
Chris@16 65 typedef IoObjectService service_type;
Chris@16 66
Chris@16 67 /// The underlying implementation type of I/O object.
Chris@16 68 typedef typename service_type::implementation_type implementation_type;
Chris@16 69
Chris@16 70 /// Get the io_service associated with the object.
Chris@16 71 /**
Chris@16 72 * This function may be used to obtain the io_service object that the I/O
Chris@16 73 * object uses to dispatch handlers for asynchronous operations.
Chris@16 74 *
Chris@16 75 * @return A reference to the io_service object that the I/O object will use
Chris@16 76 * to dispatch handlers. Ownership is not transferred to the caller.
Chris@16 77 */
Chris@16 78 boost::asio::io_service& get_io_service()
Chris@16 79 {
Chris@16 80 return service.get_io_service();
Chris@16 81 }
Chris@16 82
Chris@16 83 protected:
Chris@16 84 /// Construct a basic_io_object.
Chris@16 85 /**
Chris@16 86 * Performs:
Chris@16 87 * @code get_service().construct(get_implementation()); @endcode
Chris@16 88 */
Chris@16 89 explicit basic_io_object(boost::asio::io_service& io_service)
Chris@16 90 : service(boost::asio::use_service<IoObjectService>(io_service))
Chris@16 91 {
Chris@16 92 service.construct(implementation);
Chris@16 93 }
Chris@16 94
Chris@16 95 #if defined(GENERATING_DOCUMENTATION)
Chris@16 96 /// Move-construct a basic_io_object.
Chris@16 97 /**
Chris@16 98 * Performs:
Chris@16 99 * @code get_service().move_construct(
Chris@16 100 * get_implementation(), other.get_implementation()); @endcode
Chris@16 101 *
Chris@16 102 * @note Available only for services that support movability,
Chris@16 103 */
Chris@16 104 basic_io_object(basic_io_object&& other);
Chris@16 105
Chris@16 106 /// Move-assign a basic_io_object.
Chris@16 107 /**
Chris@16 108 * Performs:
Chris@16 109 * @code get_service().move_assign(get_implementation(),
Chris@16 110 * other.get_service(), other.get_implementation()); @endcode
Chris@16 111 *
Chris@16 112 * @note Available only for services that support movability,
Chris@16 113 */
Chris@16 114 basic_io_object& operator=(basic_io_object&& other);
Chris@16 115 #endif // defined(GENERATING_DOCUMENTATION)
Chris@16 116
Chris@16 117 /// Protected destructor to prevent deletion through this type.
Chris@16 118 /**
Chris@16 119 * Performs:
Chris@16 120 * @code get_service().destroy(get_implementation()); @endcode
Chris@16 121 */
Chris@16 122 ~basic_io_object()
Chris@16 123 {
Chris@16 124 service.destroy(implementation);
Chris@16 125 }
Chris@16 126
Chris@16 127 /// Get the service associated with the I/O object.
Chris@16 128 service_type& get_service()
Chris@16 129 {
Chris@16 130 return service;
Chris@16 131 }
Chris@16 132
Chris@16 133 /// Get the service associated with the I/O object.
Chris@16 134 const service_type& get_service() const
Chris@16 135 {
Chris@16 136 return service;
Chris@16 137 }
Chris@16 138
Chris@16 139 /// (Deprecated: Use get_service().) The service associated with the I/O
Chris@16 140 /// object.
Chris@16 141 /**
Chris@16 142 * @note Available only for services that do not support movability.
Chris@16 143 */
Chris@16 144 service_type& service;
Chris@16 145
Chris@16 146 /// Get the underlying implementation of the I/O object.
Chris@16 147 implementation_type& get_implementation()
Chris@16 148 {
Chris@16 149 return implementation;
Chris@16 150 }
Chris@16 151
Chris@16 152 /// Get the underlying implementation of the I/O object.
Chris@16 153 const implementation_type& get_implementation() const
Chris@16 154 {
Chris@16 155 return implementation;
Chris@16 156 }
Chris@16 157
Chris@16 158 /// (Deprecated: Use get_implementation().) The underlying implementation of
Chris@16 159 /// the I/O object.
Chris@16 160 implementation_type implementation;
Chris@16 161
Chris@16 162 private:
Chris@16 163 basic_io_object(const basic_io_object&);
Chris@16 164 basic_io_object& operator=(const basic_io_object&);
Chris@16 165 };
Chris@16 166
Chris@16 167 #if defined(BOOST_ASIO_HAS_MOVE)
Chris@16 168 // Specialisation for movable objects.
Chris@16 169 template <typename IoObjectService>
Chris@16 170 class basic_io_object<IoObjectService, true>
Chris@16 171 {
Chris@16 172 public:
Chris@16 173 typedef IoObjectService service_type;
Chris@16 174 typedef typename service_type::implementation_type implementation_type;
Chris@16 175
Chris@16 176 boost::asio::io_service& get_io_service()
Chris@16 177 {
Chris@16 178 return service_->get_io_service();
Chris@16 179 }
Chris@16 180
Chris@16 181 protected:
Chris@16 182 explicit basic_io_object(boost::asio::io_service& io_service)
Chris@16 183 : service_(&boost::asio::use_service<IoObjectService>(io_service))
Chris@16 184 {
Chris@16 185 service_->construct(implementation);
Chris@16 186 }
Chris@16 187
Chris@16 188 basic_io_object(basic_io_object&& other)
Chris@16 189 : service_(&other.get_service())
Chris@16 190 {
Chris@16 191 service_->move_construct(implementation, other.implementation);
Chris@16 192 }
Chris@16 193
Chris@16 194 ~basic_io_object()
Chris@16 195 {
Chris@16 196 service_->destroy(implementation);
Chris@16 197 }
Chris@16 198
Chris@16 199 basic_io_object& operator=(basic_io_object&& other)
Chris@16 200 {
Chris@16 201 service_->move_assign(implementation,
Chris@16 202 *other.service_, other.implementation);
Chris@16 203 service_ = other.service_;
Chris@16 204 return *this;
Chris@16 205 }
Chris@16 206
Chris@16 207 service_type& get_service()
Chris@16 208 {
Chris@16 209 return *service_;
Chris@16 210 }
Chris@16 211
Chris@16 212 const service_type& get_service() const
Chris@16 213 {
Chris@16 214 return *service_;
Chris@16 215 }
Chris@16 216
Chris@16 217 implementation_type& get_implementation()
Chris@16 218 {
Chris@16 219 return implementation;
Chris@16 220 }
Chris@16 221
Chris@16 222 const implementation_type& get_implementation() const
Chris@16 223 {
Chris@16 224 return implementation;
Chris@16 225 }
Chris@16 226
Chris@16 227 implementation_type implementation;
Chris@16 228
Chris@16 229 private:
Chris@16 230 basic_io_object(const basic_io_object&);
Chris@16 231 void operator=(const basic_io_object&);
Chris@16 232
Chris@16 233 IoObjectService* service_;
Chris@16 234 };
Chris@16 235 #endif // defined(BOOST_ASIO_HAS_MOVE)
Chris@16 236
Chris@16 237 } // namespace asio
Chris@16 238 } // namespace boost
Chris@16 239
Chris@16 240 #include <boost/asio/detail/pop_options.hpp>
Chris@16 241
Chris@16 242 #endif // BOOST_ASIO_BASIC_IO_OBJECT_HPP