Realistic 3D camera system
3D camera system components
basic_handle.hpp
Go to the documentation of this file.
1 //
2 // windows/basic_handle.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 ASIO_WINDOWS_BASIC_HANDLE_HPP
12 #define ASIO_WINDOWS_BASIC_HANDLE_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 
20 #if defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \
21  || defined(ASIO_HAS_WINDOWS_STREAM_HANDLE) \
22  || defined(ASIO_HAS_WINDOWS_OBJECT_HANDLE) \
23  || defined(GENERATING_DOCUMENTATION)
24 
25 #include "asio/basic_io_object.hpp"
27 #include "asio/error.hpp"
28 
30 
31 namespace asio {
32 namespace windows {
33 
35 
43 template <typename HandleService>
44 class basic_handle
45  : public basic_io_object<HandleService>
46 {
47 public:
50  typedef typename HandleService::native_handle_type native_type;
51 
53  typedef typename HandleService::native_handle_type native_handle_type;
54 
56  typedef basic_handle<HandleService> lowest_layer_type;
57 
59 
65  explicit basic_handle(asio::io_service& io_service)
66  : basic_io_object<HandleService>(io_service)
67  {
68  }
69 
71 
81  basic_handle(asio::io_service& io_service,
82  const native_handle_type& handle)
83  : basic_io_object<HandleService>(io_service)
84  {
86  this->get_service().assign(this->get_implementation(), handle, ec);
87  asio::detail::throw_error(ec, "assign");
88  }
89 
90 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
91 
100  basic_handle(basic_handle&& other)
101  : basic_io_object<HandleService>(
102  ASIO_MOVE_CAST(basic_handle)(other))
103  {
104  }
105 
107 
115  basic_handle& operator=(basic_handle&& other)
116  {
117  basic_io_object<HandleService>::operator=(
118  ASIO_MOVE_CAST(basic_handle)(other));
119  return *this;
120  }
121 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
122 
124 
132  lowest_layer_type& lowest_layer()
133  {
134  return *this;
135  }
136 
138 
146  const lowest_layer_type& lowest_layer() const
147  {
148  return *this;
149  }
150 
152  /*
153  * This function opens the handle to hold an existing native handle.
154  *
155  * @param handle A native handle.
156  *
157  * @throws asio::system_error Thrown on failure.
158  */
159  void assign(const native_handle_type& handle)
160  {
161  asio::error_code ec;
162  this->get_service().assign(this->get_implementation(), handle, ec);
163  asio::detail::throw_error(ec, "assign");
164  }
165 
167  /*
168  * This function opens the handle to hold an existing native handle.
169  *
170  * @param handle A native handle.
171  *
172  * @param ec Set to indicate what error occurred, if any.
173  */
174  asio::error_code assign(const native_handle_type& handle,
175  asio::error_code& ec)
176  {
177  return this->get_service().assign(this->get_implementation(), handle, ec);
178  }
179 
181  bool is_open() const
182  {
183  return this->get_service().is_open(this->get_implementation());
184  }
185 
187 
194  void close()
195  {
196  asio::error_code ec;
197  this->get_service().close(this->get_implementation(), ec);
198  asio::detail::throw_error(ec, "close");
199  }
200 
202 
210  {
211  return this->get_service().close(this->get_implementation(), ec);
212  }
213 
215 
220  native_type native()
221  {
222  return this->get_service().native_handle(this->get_implementation());
223  }
224 
226 
231  native_handle_type native_handle()
232  {
233  return this->get_service().native_handle(this->get_implementation());
234  }
235 
237 
244  void cancel()
245  {
246  asio::error_code ec;
247  this->get_service().cancel(this->get_implementation(), ec);
248  asio::detail::throw_error(ec, "cancel");
249  }
250 
252 
260  {
261  return this->get_service().cancel(this->get_implementation(), ec);
262  }
263 
264 protected:
266  ~basic_handle()
267  {
268  }
269 };
270 
271 } // namespace windows
272 } // namespace asio
273 
275 
276 #endif // defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
277  // || defined(ASIO_HAS_WINDOWS_STREAM_HANDLE)
278  // || defined(ASIO_HAS_WINDOWS_OBJECT_HANDLE)
279  // || defined(GENERATING_DOCUMENTATION)
280 
281 #endif // ASIO_WINDOWS_BASIC_HANDLE_HPP
void throw_error(const asio::error_code &err)
Definition: throw_error.hpp:31
Provides core I/O functionality.
Definition: io_service.hpp:184
Class to represent an error code value.
Definition: error_code.hpp:80
ASIO_DECL int close(int d, state_type &state, asio::error_code &ec)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138