Realistic 3D camera system
3D camera system components
buffered_read_stream.hpp
Go to the documentation of this file.
1 //
2 // buffered_read_stream.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_BUFFERED_READ_STREAM_HPP
12 #define ASIO_BUFFERED_READ_STREAM_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/async_result.hpp"
22 #include "asio/buffer.hpp"
28 #include "asio/error.hpp"
29 #include "asio/io_service.hpp"
30 
32 
33 namespace asio {
34 
36 
47 template <typename Stream>
49  : private noncopyable
50 {
51 public:
53  typedef typename remove_reference<Stream>::type next_layer_type;
54 
56  typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
57 
58 #if defined(GENERATING_DOCUMENTATION)
59  static const std::size_t default_buffer_size = implementation_defined;
61 #else
62  ASIO_STATIC_CONSTANT(std::size_t, default_buffer_size = 1024);
63 #endif
64 
66  template <typename Arg>
67  explicit buffered_read_stream(Arg& a)
68  : next_layer_(a),
69  storage_(default_buffer_size)
70  {
71  }
72 
74  template <typename Arg>
75  buffered_read_stream(Arg& a, std::size_t buffer_size)
76  : next_layer_(a),
77  storage_(buffer_size)
78  {
79  }
80 
82  next_layer_type& next_layer()
83  {
84  return next_layer_;
85  }
86 
88  lowest_layer_type& lowest_layer()
89  {
90  return next_layer_.lowest_layer();
91  }
92 
94  const lowest_layer_type& lowest_layer() const
95  {
96  return next_layer_.lowest_layer();
97  }
98 
101  {
102  return next_layer_.get_io_service();
103  }
104 
106  void close()
107  {
108  next_layer_.close();
109  }
110 
113  {
114  return next_layer_.close(ec);
115  }
116 
119  template <typename ConstBufferSequence>
120  std::size_t write_some(const ConstBufferSequence& buffers)
121  {
122  return next_layer_.write_some(buffers);
123  }
124 
127  template <typename ConstBufferSequence>
128  std::size_t write_some(const ConstBufferSequence& buffers,
129  asio::error_code& ec)
130  {
131  return next_layer_.write_some(buffers, ec);
132  }
133 
136  template <typename ConstBufferSequence, typename WriteHandler>
137  ASIO_INITFN_RESULT_TYPE(WriteHandler,
138  void (asio::error_code, std::size_t))
139  async_write_some(const ConstBufferSequence& buffers,
140  ASIO_MOVE_ARG(WriteHandler) handler)
141  {
143  WriteHandler, void (asio::error_code, std::size_t)> init(
144  ASIO_MOVE_CAST(WriteHandler)(handler));
145 
146  next_layer_.async_write_some(buffers,
147  ASIO_MOVE_CAST(ASIO_HANDLER_TYPE(WriteHandler,
148  void (asio::error_code, std::size_t)))(init.handler));
149 
150  return init.result.get();
151  }
152 
155  std::size_t fill();
156 
159  std::size_t fill(asio::error_code& ec);
160 
162  template <typename ReadHandler>
163  ASIO_INITFN_RESULT_TYPE(ReadHandler,
164  void (asio::error_code, std::size_t))
165  async_fill(ASIO_MOVE_ARG(ReadHandler) handler);
166 
169  template <typename MutableBufferSequence>
170  std::size_t read_some(const MutableBufferSequence& buffers);
171 
174  template <typename MutableBufferSequence>
175  std::size_t read_some(const MutableBufferSequence& buffers,
176  asio::error_code& ec);
177 
180  template <typename MutableBufferSequence, typename ReadHandler>
181  ASIO_INITFN_RESULT_TYPE(ReadHandler,
182  void (asio::error_code, std::size_t))
183  async_read_some(const MutableBufferSequence& buffers,
184  ASIO_MOVE_ARG(ReadHandler) handler);
185 
188  template <typename MutableBufferSequence>
189  std::size_t peek(const MutableBufferSequence& buffers);
190 
193  template <typename MutableBufferSequence>
194  std::size_t peek(const MutableBufferSequence& buffers,
195  asio::error_code& ec);
196 
198  std::size_t in_avail()
199  {
200  return storage_.size();
201  }
202 
204  std::size_t in_avail(asio::error_code& ec)
205  {
206  ec = asio::error_code();
207  return storage_.size();
208  }
209 
210 private:
213  template <typename MutableBufferSequence>
214  std::size_t copy(const MutableBufferSequence& buffers)
215  {
216  std::size_t bytes_copied = asio::buffer_copy(
217  buffers, storage_.data(), storage_.size());
218  storage_.consume(bytes_copied);
219  return bytes_copied;
220  }
221 
225  template <typename MutableBufferSequence>
226  std::size_t peek_copy(const MutableBufferSequence& buffers)
227  {
228  return asio::buffer_copy(buffers, storage_.data(), storage_.size());
229  }
230 
232  Stream next_layer_;
233 
234  // The data in the buffer.
236 };
237 
238 } // namespace asio
239 
241 
243 
244 #endif // ASIO_BUFFERED_READ_STREAM_HPP
std::size_t in_avail()
Determine the amount of data that may be read without blocking.
std::size_t write_some(const ConstBufferSequence &buffers, asio::error_code &ec)
Provides core I/O functionality.
Definition: io_service.hpp:184
lowest_layer_type & lowest_layer()
Get a reference to the lowest layer.
next_layer_type & next_layer()
Get a reference to the next layer.
asio::basic_streambuf< Allocator > MatchCondition enable_if< is_match_condition< MatchCondition >::value >::type *detail::async_result_init< ReadHandler, void(asio::error_code, std::size_t)> init(ASIO_MOVE_CAST(ReadHandler)(handler))
#define ASIO_HANDLER_TYPE(h, sig)
const lowest_layer_type & lowest_layer() const
Get a const reference to the lowest layer.
ASIO_INITFN_RESULT_TYPE(WriteHandler, void(asio::error_code, std::size_t)) async_write_some(const ConstBufferSequence &buffers
remove_reference< Stream >::type next_layer_type
The type of the next layer.
ASIO_MOVE_ARG(WriteHandler) handler)
buffered_read_stream(Arg &a, std::size_t buffer_size)
Construct, passing the specified argument to initialise the next layer.
std::size_t write_some(const ConstBufferSequence &buffers)
std::size_t buffer_size(const mutable_buffer &b)
Get the number of bytes in a modifiable buffer.
Definition: buffer.hpp:357
const MutableBufferSequence & buffers
Definition: read.hpp:521
std::size_t peek(const MutableBufferSequence &buffers)
Adds buffering to the read-related operations of a stream.
buffered_read_stream(Arg &a)
Construct, passing the specified argument to initialise the next layer.
Class to represent an error code value.
Definition: error_code.hpp:80
asio::io_service & get_io_service()
Get the io_service associated with the object.
std::size_t in_avail(asio::error_code &ec)
Determine the amount of data that may be read without blocking.
ASIO_STATIC_CONSTANT(std::size_t, default_buffer_size=1024)
handler_type< Handler, Signature >::type handler
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
asio::error_code close(asio::error_code &ec)
Close the stream.
std::size_t read_some(const MutableBufferSequence &buffers)
async_result< typename handler_type< Handler, Signature >::type > result
void close()
Close the stream.
std::size_t buffer_copy(const mutable_buffer &target, const const_buffer &source)
Copies bytes from a source buffer to a target buffer.
Definition: buffer.hpp:1295
next_layer_type::lowest_layer_type lowest_layer_type
The type of the lowest layer.