basic_deadline_timer.hpp
Go to the documentation of this file.
00001 //
00002 // basic_deadline_timer.hpp
00003 // ~~~~~~~~~~~~~~~~~~~~~~~~
00004 //
00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
00006 //
00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00009 //
00010 
00011 #ifndef ASIO_BASIC_DEADLINE_TIMER_HPP
00012 #define ASIO_BASIC_DEADLINE_TIMER_HPP
00013 
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017 
00018 #include "asio/detail/push_options.hpp"
00019 
00020 #include "asio/detail/push_options.hpp"
00021 #include <cstddef>
00022 #include <boost/config.hpp>
00023 #include "asio/detail/pop_options.hpp"
00024 
00025 #include "asio/basic_io_object.hpp"
00026 #include "asio/deadline_timer_service.hpp"
00027 #include "asio/error.hpp"
00028 #include "asio/detail/throw_error.hpp"
00029 
00030 namespace asio {
00031 
00033 
00116 template <typename Time,
00117     typename TimeTraits = asio::time_traits<Time>,
00118     typename TimerService = deadline_timer_service<Time, TimeTraits> >
00119 class basic_deadline_timer
00120   : public basic_io_object<TimerService>
00121 {
00122 public:
00124   typedef TimeTraits traits_type;
00125 
00127   typedef typename traits_type::time_type time_type;
00128 
00130   typedef typename traits_type::duration_type duration_type;
00131 
00133 
00141   explicit basic_deadline_timer(asio::io_service& io_service)
00142     : basic_io_object<TimerService>(io_service)
00143   {
00144   }
00145 
00147 
00156   basic_deadline_timer(asio::io_service& io_service,
00157       const time_type& expiry_time)
00158     : basic_io_object<TimerService>(io_service)
00159   {
00160     asio::error_code ec;
00161     this->service.expires_at(this->implementation, expiry_time, ec);
00162     asio::detail::throw_error(ec);
00163   }
00164 
00166 
00175   basic_deadline_timer(asio::io_service& io_service,
00176       const duration_type& expiry_time)
00177     : basic_io_object<TimerService>(io_service)
00178   {
00179     asio::error_code ec;
00180     this->service.expires_from_now(this->implementation, expiry_time, ec);
00181     asio::detail::throw_error(ec);
00182   }
00183 
00185 
00196   std::size_t cancel()
00197   {
00198     asio::error_code ec;
00199     std::size_t s = this->service.cancel(this->implementation, ec);
00200     asio::detail::throw_error(ec);
00201     return s;
00202   }
00203 
00205 
00216   std::size_t cancel(asio::error_code& ec)
00217   {
00218     return this->service.cancel(this->implementation, ec);
00219   }
00220 
00222 
00226   time_type expires_at() const
00227   {
00228     return this->service.expires_at(this->implementation);
00229   }
00230 
00232 
00243   std::size_t expires_at(const time_type& expiry_time)
00244   {
00245     asio::error_code ec;
00246     std::size_t s = this->service.expires_at(
00247         this->implementation, expiry_time, ec);
00248     asio::detail::throw_error(ec);
00249     return s;
00250   }
00251 
00253 
00264   std::size_t expires_at(const time_type& expiry_time,
00265       asio::error_code& ec)
00266   {
00267     return this->service.expires_at(this->implementation, expiry_time, ec);
00268   }
00269 
00271 
00275   duration_type expires_from_now() const
00276   {
00277     return this->service.expires_from_now(this->implementation);
00278   }
00279 
00281 
00292   std::size_t expires_from_now(const duration_type& expiry_time)
00293   {
00294     asio::error_code ec;
00295     std::size_t s = this->service.expires_from_now(
00296         this->implementation, expiry_time, ec);
00297     asio::detail::throw_error(ec);
00298     return s;
00299   }
00300 
00302 
00313   std::size_t expires_from_now(const duration_type& expiry_time,
00314       asio::error_code& ec)
00315   {
00316     return this->service.expires_from_now(
00317         this->implementation, expiry_time, ec);
00318   }
00319 
00321 
00327   void wait()
00328   {
00329     asio::error_code ec;
00330     this->service.wait(this->implementation, ec);
00331     asio::detail::throw_error(ec);
00332   }
00333 
00335 
00341   void wait(asio::error_code& ec)
00342   {
00343     this->service.wait(this->implementation, ec);
00344   }
00345 
00347 
00370   template <typename WaitHandler>
00371   void async_wait(WaitHandler handler)
00372   {
00373     this->service.async_wait(this->implementation, handler);
00374   }
00375 };
00376 
00377 } // namespace asio
00378 
00379 #include "asio/detail/pop_options.hpp"
00380 
00381 #endif // ASIO_BASIC_DEADLINE_TIMER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


Castor
Author(s): Carpe Noctem
autogenerated on Fri Nov 8 2013 11:05:39