PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/asio/windows/random_access_handle_service.hpp

http://pythonocc.googlecode.com/
C++ Header | 182 lines | 123 code | 30 blank | 29 comment | 3 complexity | 89ec271349b6f2927ad519a6e85cd771 MD5 | raw file
  1//
  2// random_access_handle_service.hpp
  3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4//
  5// Copyright (c) 2003-2010 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_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP
 12#define BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_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/push_options.hpp>
 19
 20#include <boost/asio/detail/push_options.hpp>
 21#include <cstddef>
 22#include <boost/config.hpp>
 23#include <boost/cstdint.hpp>
 24#include <boost/asio/detail/pop_options.hpp>
 25
 26#include <boost/asio/error.hpp>
 27#include <boost/asio/io_service.hpp>
 28#include <boost/asio/detail/service_base.hpp>
 29#include <boost/asio/detail/win_iocp_handle_service.hpp>
 30
 31#if !defined(BOOST_ASIO_DISABLE_WINDOWS_RANDOM_ACCESS_HANDLE)
 32# if defined(BOOST_ASIO_HAS_IOCP)
 33#  define BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE 1
 34# endif // defined(BOOST_ASIO_HAS_IOCP)
 35#endif // !defined(BOOST_ASIO_DISABLE_WINDOWS_RANDOM_ACCESS_HANDLE)
 36
 37#if defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \
 38  || defined(GENERATING_DOCUMENTATION)
 39
 40namespace boost {
 41namespace asio {
 42namespace windows {
 43
 44/// Default service implementation for a random-access handle.
 45class random_access_handle_service
 46#if defined(GENERATING_DOCUMENTATION)
 47  : public boost::asio::io_service::service
 48#else
 49  : public boost::asio::detail::service_base<random_access_handle_service>
 50#endif
 51{
 52public:
 53#if defined(GENERATING_DOCUMENTATION)
 54  /// The unique service identifier.
 55  static boost::asio::io_service::id id;
 56#endif
 57
 58private:
 59  // The type of the platform-specific implementation.
 60  typedef detail::win_iocp_handle_service service_impl_type;
 61
 62public:
 63  /// The type of a random-access handle implementation.
 64#if defined(GENERATING_DOCUMENTATION)
 65  typedef implementation_defined implementation_type;
 66#else
 67  typedef service_impl_type::implementation_type implementation_type;
 68#endif
 69
 70  /// The native handle type.
 71#if defined(GENERATING_DOCUMENTATION)
 72  typedef implementation_defined native_type;
 73#else
 74  typedef service_impl_type::native_type native_type;
 75#endif
 76
 77  /// Construct a new random-access handle service for the specified io_service.
 78  explicit random_access_handle_service(boost::asio::io_service& io_service)
 79    : boost::asio::detail::service_base<
 80        random_access_handle_service>(io_service),
 81      service_impl_(io_service)
 82  {
 83  }
 84
 85  /// Destroy all user-defined handler objects owned by the service.
 86  void shutdown_service()
 87  {
 88    service_impl_.shutdown_service();
 89  }
 90
 91  /// Construct a new random-access handle implementation.
 92  void construct(implementation_type& impl)
 93  {
 94    service_impl_.construct(impl);
 95  }
 96
 97  /// Destroy a random-access handle implementation.
 98  void destroy(implementation_type& impl)
 99  {
100    service_impl_.destroy(impl);
101  }
102
103  /// Assign an existing native handle to a random-access handle.
104  boost::system::error_code assign(implementation_type& impl,
105      const native_type& native_handle, boost::system::error_code& ec)
106  {
107    return service_impl_.assign(impl, native_handle, ec);
108  }
109
110  /// Determine whether the handle is open.
111  bool is_open(const implementation_type& impl) const
112  {
113    return service_impl_.is_open(impl);
114  }
115
116  /// Close a random-access handle implementation.
117  boost::system::error_code close(implementation_type& impl,
118      boost::system::error_code& ec)
119  {
120    return service_impl_.close(impl, ec);
121  }
122
123  /// Get the native handle implementation.
124  native_type native(implementation_type& impl)
125  {
126    return service_impl_.native(impl);
127  }
128
129  /// Cancel all asynchronous operations associated with the handle.
130  boost::system::error_code cancel(implementation_type& impl,
131      boost::system::error_code& ec)
132  {
133    return service_impl_.cancel(impl, ec);
134  }
135
136  /// Write the given data at the specified offset.
137  template <typename ConstBufferSequence>
138  std::size_t write_some_at(implementation_type& impl, boost::uint64_t offset,
139      const ConstBufferSequence& buffers, boost::system::error_code& ec)
140  {
141    return service_impl_.write_some_at(impl, offset, buffers, ec);
142  }
143
144  /// Start an asynchronous write at the specified offset.
145  template <typename ConstBufferSequence, typename WriteHandler>
146  void async_write_some_at(implementation_type& impl, boost::uint64_t offset,
147      const ConstBufferSequence& buffers, WriteHandler handler)
148  {
149    service_impl_.async_write_some_at(impl, offset, buffers, handler);
150  }
151
152  /// Read some data from the specified offset.
153  template <typename MutableBufferSequence>
154  std::size_t read_some_at(implementation_type& impl, boost::uint64_t offset,
155      const MutableBufferSequence& buffers, boost::system::error_code& ec)
156  {
157    return service_impl_.read_some_at(impl, offset, buffers, ec);
158  }
159
160  /// Start an asynchronous read at the specified offset.
161  template <typename MutableBufferSequence, typename ReadHandler>
162  void async_read_some_at(implementation_type& impl, boost::uint64_t offset,
163      const MutableBufferSequence& buffers, ReadHandler handler)
164  {
165    service_impl_.async_read_some_at(impl, offset, buffers, handler);
166  }
167
168private:
169  // The platform-specific implementation.
170  service_impl_type service_impl_;
171};
172
173} // namespace windows
174} // namespace asio
175} // namespace boost
176
177#endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
178       //   || defined(GENERATING_DOCUMENTATION)
179
180#include <boost/asio/detail/pop_options.hpp>
181
182#endif // BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP