Realistic 3D camera system
3D camera system components
basic_io_object.hpp
Go to the documentation of this file.
1 //
2 // basic_io_object.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_BASIC_IO_OBJECT_HPP
12 #define 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 "asio/detail/config.hpp"
19 #include "asio/io_service.hpp"
20 
22 
23 namespace asio {
24 
25 #if defined(ASIO_HAS_MOVE)
26 namespace detail
27 {
28  // Type trait used to determine whether a service supports move.
29  template <typename IoObjectService>
30  class service_has_move
31  {
32  private:
33  typedef IoObjectService service_type;
34  typedef typename service_type::implementation_type implementation_type;
35 
36  template <typename T, typename U>
37  static auto eval(T* t, U* u) -> decltype(t->move_construct(*u, *u), char());
38  static char (&eval(...))[2];
39 
40  public:
41  static const bool value =
42  sizeof(service_has_move::eval(
43  static_cast<service_type*>(0),
44  static_cast<implementation_type*>(0))) == 1;
45  };
46 }
47 #endif // defined(ASIO_HAS_MOVE)
48 
50 
54 #if !defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
55 template <typename IoObjectService>
56 #else
57 template <typename IoObjectService,
58  bool Movable = detail::service_has_move<IoObjectService>::value>
59 #endif
61 {
62 public:
64  typedef IoObjectService service_type;
65 
67  typedef typename service_type::implementation_type implementation_type;
68 
70 
78  {
79  return service.get_io_service();
80  }
81 
82 protected:
84 
89  : service(asio::use_service<IoObjectService>(io_service))
90  {
91  service.construct(implementation);
92  }
93 
94 #if defined(GENERATING_DOCUMENTATION)
95 
104 
106 
113  basic_io_object& operator=(basic_io_object&& other);
114 #endif // defined(GENERATING_DOCUMENTATION)
115 
117 
122  {
123  service.destroy(implementation);
124  }
125 
127  service_type& get_service()
128  {
129  return service;
130  }
131 
133  const service_type& get_service() const
134  {
135  return service;
136  }
137 
140 
143  service_type& service;
144 
146  implementation_type& get_implementation()
147  {
148  return implementation;
149  }
150 
152  const implementation_type& get_implementation() const
153  {
154  return implementation;
155  }
156 
159  implementation_type implementation;
160 
161 private:
163  basic_io_object& operator=(const basic_io_object&);
164 };
165 
166 #if defined(ASIO_HAS_MOVE)
167 // Specialisation for movable objects.
168 template <typename IoObjectService>
169 class basic_io_object<IoObjectService, true>
170 {
171 public:
172  typedef IoObjectService service_type;
173  typedef typename service_type::implementation_type implementation_type;
174 
175  asio::io_service& get_io_service()
176  {
177  return service_->get_io_service();
178  }
179 
180 protected:
182  : service_(&asio::use_service<IoObjectService>(io_service))
183  {
184  service_->construct(implementation);
185  }
186 
188  : service_(&other.get_service())
189  {
190  service_->move_construct(implementation, other.implementation);
191  }
192 
193  ~basic_io_object()
194  {
195  service_->destroy(implementation);
196  }
197 
198  basic_io_object& operator=(basic_io_object&& other)
199  {
200  service_->move_assign(implementation,
201  *other.service_, other.implementation);
202  service_ = other.service_;
203  return *this;
204  }
205 
206  service_type& get_service()
207  {
208  return *service_;
209  }
210 
211  const service_type& get_service() const
212  {
213  return *service_;
214  }
215 
216  implementation_type& get_implementation()
217  {
218  return implementation;
219  }
220 
221  const implementation_type& get_implementation() const
222  {
223  return implementation;
224  }
225 
226  implementation_type implementation;
227 
228 private:
230  void operator=(const basic_io_object&);
231 
232  IoObjectService* service_;
233 };
234 #endif // defined(ASIO_HAS_MOVE)
235 
236 } // namespace asio
237 
239 
240 #endif // ASIO_BASIC_IO_OBJECT_HPP
basic_io_object(asio::io_service &io_service)
Construct a basic_io_object.
Provides core I/O functionality.
Definition: io_service.hpp:184
service_type & get_service()
Get the service associated with the I/O object.
~basic_io_object()
Protected destructor to prevent deletion through this type.
Base class for all I/O objects.
IoObjectService service_type
The type of the service that will be used to provide I/O operations.
Service & use_service(io_service &ios)
Definition: io_service.hpp:26
const implementation_type & get_implementation() const
Get the underlying implementation of the I/O object.
implementation_type & get_implementation()
Get the underlying implementation of the I/O object.
service_type::implementation_type implementation_type
The underlying implementation type of I/O object.
implementation_type implementation
asio::io_service & get_io_service()
Get the io_service associated with the object.
const service_type & get_service() const
Get the service associated with the I/O object.