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