Realistic 3D camera system
3D camera system components
basic_waitable_timer.hpp
Go to the documentation of this file.
1 //
2 // basic_waitable_timer.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_WAITABLE_TIMER_HPP
12 #define ASIO_BASIC_WAITABLE_TIMER_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 <cstddef>
20 #include "asio/basic_io_object.hpp"
23 #include "asio/error.hpp"
24 #include "asio/wait_traits.hpp"
26 
28 
29 namespace asio {
30 
32 
123 template <typename Clock,
124  typename WaitTraits = asio::wait_traits<Clock>,
125  typename WaitableTimerService = waitable_timer_service<Clock, WaitTraits> >
127  : public basic_io_object<WaitableTimerService>
128 {
129 public:
131  typedef Clock clock_type;
132 
134  typedef typename clock_type::duration duration;
135 
137  typedef typename clock_type::time_point time_point;
138 
140  typedef WaitTraits traits_type;
141 
143 
152  : basic_io_object<WaitableTimerService>(io_service)
153  {
154  }
155 
157 
167  const time_point& expiry_time)
168  : basic_io_object<WaitableTimerService>(io_service)
169  {
170  asio::error_code ec;
171  this->service.expires_at(this->implementation, expiry_time, ec);
172  asio::detail::throw_error(ec, "expires_at");
173  }
174 
176 
186  const duration& expiry_time)
187  : basic_io_object<WaitableTimerService>(io_service)
188  {
189  asio::error_code ec;
190  this->service.expires_from_now(this->implementation, expiry_time, ec);
191  asio::detail::throw_error(ec, "expires_from_now");
192  }
193 
195 
216  std::size_t cancel()
217  {
218  asio::error_code ec;
219  std::size_t s = this->service.cancel(this->implementation, ec);
220  asio::detail::throw_error(ec, "cancel");
221  return s;
222  }
223 
225 
246  std::size_t cancel(asio::error_code& ec)
247  {
248  return this->service.cancel(this->implementation, ec);
249  }
250 
252 
275  std::size_t cancel_one()
276  {
277  asio::error_code ec;
278  std::size_t s = this->service.cancel_one(this->implementation, ec);
279  asio::detail::throw_error(ec, "cancel_one");
280  return s;
281  }
282 
284 
307  std::size_t cancel_one(asio::error_code& ec)
308  {
309  return this->service.cancel_one(this->implementation, ec);
310  }
311 
313 
317  time_point expires_at() const
318  {
319  return this->service.expires_at(this->implementation);
320  }
321 
323 
344  std::size_t expires_at(const time_point& expiry_time)
345  {
346  asio::error_code ec;
347  std::size_t s = this->service.expires_at(
348  this->implementation, expiry_time, ec);
349  asio::detail::throw_error(ec, "expires_at");
350  return s;
351  }
352 
354 
375  std::size_t expires_at(const time_point& expiry_time,
376  asio::error_code& ec)
377  {
378  return this->service.expires_at(this->implementation, expiry_time, ec);
379  }
380 
382 
386  duration expires_from_now() const
387  {
388  return this->service.expires_from_now(this->implementation);
389  }
390 
392 
413  std::size_t expires_from_now(const duration& expiry_time)
414  {
415  asio::error_code ec;
416  std::size_t s = this->service.expires_from_now(
417  this->implementation, expiry_time, ec);
418  asio::detail::throw_error(ec, "expires_from_now");
419  return s;
420  }
421 
423 
444  std::size_t expires_from_now(const duration& expiry_time,
445  asio::error_code& ec)
446  {
447  return this->service.expires_from_now(
448  this->implementation, expiry_time, ec);
449  }
450 
452 
458  void wait()
459  {
460  asio::error_code ec;
461  this->service.wait(this->implementation, ec);
462  asio::detail::throw_error(ec, "wait");
463  }
464 
466 
473  {
474  this->service.wait(this->implementation, ec);
475  }
476 
478 
501  template <typename WaitHandler>
503  void (asio::error_code))
504  async_wait(ASIO_MOVE_ARG(WaitHandler) handler)
505  {
506  // If you get an error on the following line it means that your handler does
507  // not meet the documented type requirements for a WaitHandler.
508  ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
509 
510  return this->service.async_wait(this->implementation,
511  ASIO_MOVE_CAST(WaitHandler)(handler));
512  }
513 };
514 
515 } // namespace asio
516 
518 
519 #endif // ASIO_BASIC_WAITABLE_TIMER_HPP
void throw_error(const asio::error_code &err)
Definition: throw_error.hpp:31
Provides core I/O functionality.
Definition: io_service.hpp:184
SocketService & s
Definition: connect.hpp:521
void wait()
Perform a blocking wait on the timer.
Base class for all I/O objects.
std::size_t expires_from_now(const duration &expiry_time, asio::error_code &ec)
Set the timer&#39;s expiry time relative to now.
std::size_t expires_from_now(const duration &expiry_time)
Set the timer&#39;s expiry time relative to now.
#define ASIO_WAIT_HANDLER_CHECK(handler_type, handler)
Clock clock_type
The clock type.
time_point expires_at() const
Get the timer&#39;s expiry time as an absolute time.
asio::basic_streambuf< Allocator > CompletionCondition ASIO_MOVE_ARG(ReadHandler) handler)
Definition: read.hpp:704
WaitTraits traits_type
The wait traits type.
Wait traits suitable for use with the basic_waitable_timer class template.
Definition: wait_traits.hpp:24
Class to represent an error code value.
Definition: error_code.hpp:80
basic_waitable_timer(asio::io_service &io_service)
Constructor.
ASIO_INITFN_RESULT_TYPE(WaitHandler, void(asio::error_code)) async_wait(ASIO_MOVE_ARG(WaitHandler) handler)
Start an asynchronous wait on the timer.
std::size_t expires_at(const time_point &expiry_time, asio::error_code &ec)
Set the timer&#39;s expiry time as an absolute time.
std::size_t cancel_one(asio::error_code &ec)
Cancels one asynchronous operation that is waiting on the timer.
basic_waitable_timer(asio::io_service &io_service, const duration &expiry_time)
Constructor to set a particular expiry time relative to now.
std::size_t cancel_one()
Cancels one asynchronous operation that is waiting on the timer.
Provides waitable timer functionality.
std::size_t cancel()
Cancel any asynchronous operations that are waiting on the timer.
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
std::size_t expires_at(const time_point &expiry_time)
Set the timer&#39;s expiry time as an absolute time.
clock_type::time_point time_point
The time point type of the clock.
duration expires_from_now() const
Get the timer&#39;s expiry time relative to now.
clock_type::duration duration
The duration type of the clock.
basic_waitable_timer(asio::io_service &io_service, const time_point &expiry_time)
Constructor to set a particular expiry time as an absolute time.
std::size_t cancel(asio::error_code &ec)
Cancel any asynchronous operations that are waiting on the timer.
void wait(asio::error_code &ec)
Perform a blocking wait on the timer.