Realistic 3D camera system
3D camera system components
buffered_stream.hpp
Go to the documentation of this file.
1 //
2 // buffered_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_STREAM_HPP
12 #define ASIO_BUFFERED_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"
25 #include "asio/error.hpp"
26 #include "asio/io_service.hpp"
27 
29 
30 namespace asio {
31 
33 
44 template <typename Stream>
46  : private noncopyable
47 {
48 public:
50  typedef typename remove_reference<Stream>::type next_layer_type;
51 
53  typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
54 
56  template <typename Arg>
57  explicit buffered_stream(Arg& a)
58  : inner_stream_impl_(a),
59  stream_impl_(inner_stream_impl_)
60  {
61  }
62 
64  template <typename Arg>
65  explicit buffered_stream(Arg& a, std::size_t read_buffer_size,
66  std::size_t write_buffer_size)
67  : inner_stream_impl_(a, write_buffer_size),
68  stream_impl_(inner_stream_impl_, read_buffer_size)
69  {
70  }
71 
73  next_layer_type& next_layer()
74  {
75  return stream_impl_.next_layer().next_layer();
76  }
77 
79  lowest_layer_type& lowest_layer()
80  {
81  return stream_impl_.lowest_layer();
82  }
83 
85  const lowest_layer_type& lowest_layer() const
86  {
87  return stream_impl_.lowest_layer();
88  }
89 
92  {
93  return stream_impl_.get_io_service();
94  }
95 
97  void close()
98  {
99  stream_impl_.close();
100  }
101 
104  {
105  return stream_impl_.close(ec);
106  }
107 
111  std::size_t flush()
112  {
113  return stream_impl_.next_layer().flush();
114  }
115 
119  std::size_t flush(asio::error_code& ec)
120  {
121  return stream_impl_.next_layer().flush(ec);
122  }
123 
125  template <typename WriteHandler>
127  void (asio::error_code, std::size_t))
128  async_flush(ASIO_MOVE_ARG(WriteHandler) handler)
129  {
130  return stream_impl_.next_layer().async_flush(
131  ASIO_MOVE_CAST(WriteHandler)(handler));
132  }
133 
136  template <typename ConstBufferSequence>
137  std::size_t write_some(const ConstBufferSequence& buffers)
138  {
139  return stream_impl_.write_some(buffers);
140  }
141 
144  template <typename ConstBufferSequence>
145  std::size_t write_some(const ConstBufferSequence& buffers,
146  asio::error_code& ec)
147  {
148  return stream_impl_.write_some(buffers, ec);
149  }
150 
153  template <typename ConstBufferSequence, typename WriteHandler>
154  ASIO_INITFN_RESULT_TYPE(WriteHandler,
155  void (asio::error_code, std::size_t))
156  async_write_some(const ConstBufferSequence& buffers,
157  ASIO_MOVE_ARG(WriteHandler) handler)
158  {
159  return stream_impl_.async_write_some(buffers,
160  ASIO_MOVE_CAST(WriteHandler)(handler));
161  }
162 
165  std::size_t fill()
166  {
167  return stream_impl_.fill();
168  }
169 
172  std::size_t fill(asio::error_code& ec)
173  {
174  return stream_impl_.fill(ec);
175  }
176 
178  template <typename ReadHandler>
180  void (asio::error_code, std::size_t))
181  async_fill(ASIO_MOVE_ARG(ReadHandler) handler)
182  {
183  return stream_impl_.async_fill(ASIO_MOVE_CAST(ReadHandler)(handler));
184  }
185 
188  template <typename MutableBufferSequence>
189  std::size_t read_some(const MutableBufferSequence& buffers)
190  {
191  return stream_impl_.read_some(buffers);
192  }
193 
196  template <typename MutableBufferSequence>
197  std::size_t read_some(const MutableBufferSequence& buffers,
198  asio::error_code& ec)
199  {
200  return stream_impl_.read_some(buffers, ec);
201  }
202 
205  template <typename MutableBufferSequence, typename ReadHandler>
206  ASIO_INITFN_RESULT_TYPE(ReadHandler,
207  void (asio::error_code, std::size_t))
208  async_read_some(const MutableBufferSequence& buffers,
209  ASIO_MOVE_ARG(ReadHandler) handler)
210  {
211  return stream_impl_.async_read_some(buffers,
212  ASIO_MOVE_CAST(ReadHandler)(handler));
213  }
214 
217  template <typename MutableBufferSequence>
218  std::size_t peek(const MutableBufferSequence& buffers)
219  {
220  return stream_impl_.peek(buffers);
221  }
222 
225  template <typename MutableBufferSequence>
226  std::size_t peek(const MutableBufferSequence& buffers,
227  asio::error_code& ec)
228  {
229  return stream_impl_.peek(buffers, ec);
230  }
231 
233  std::size_t in_avail()
234  {
235  return stream_impl_.in_avail();
236  }
237 
239  std::size_t in_avail(asio::error_code& ec)
240  {
241  return stream_impl_.in_avail(ec);
242  }
243 
244 private:
245  // The buffered write stream.
247  write_stream_type inner_stream_impl_;
248 
249  // The buffered read stream.
251  read_stream_type stream_impl_;
252 };
253 
254 } // namespace asio
255 
257 
258 #endif // ASIO_BUFFERED_STREAM_HPP
std::size_t in_avail(asio::error_code &ec)
Determine the amount of data that may be read without blocking.
std::size_t in_avail()
Determine the amount of data that may be read without blocking.
buffered_stream(Arg &a, std::size_t read_buffer_size, std::size_t write_buffer_size)
Construct, passing the specified argument to initialise the next layer.
buffered_stream(Arg &a)
Construct, passing the specified argument to initialise the next layer.
ASIO_MOVE_ARG(WriteHandler) handler)
Provides core I/O functionality.
Definition: io_service.hpp:184
void close()
Close the stream.
ASIO_INITFN_RESULT_TYPE(WriteHandler, void(asio::error_code, std::size_t)) async_flush(ASIO_MOVE_ARG(WriteHandler) handler)
Start an asynchronous flush.
lowest_layer_type & lowest_layer()
Get a reference to the lowest layer.
std::size_t flush(asio::error_code &ec)
next_layer_type & next_layer()
Get a reference to the next layer.
next_layer_type & next_layer()
Get a reference to the next layer.
ASIO_MOVE_ARG(ReadHandler) handler)
Adds buffering to the read- and write-related operations of a stream.
std::size_t write_some(const ConstBufferSequence &buffers, asio::error_code &ec)
remove_reference< Stream >::type next_layer_type
The type of the next layer.
std::size_t write_some(const ConstBufferSequence &buffers)
asio::io_service & get_io_service()
Get the io_service associated with the object.
const MutableBufferSequence & buffers
Definition: read.hpp:521
std::size_t in_avail()
Determine the amount of data that may be read without blocking.
const lowest_layer_type & lowest_layer() const
Get a const reference to the lowest layer.
std::size_t read_some(const MutableBufferSequence &buffers)
std::size_t peek(const MutableBufferSequence &buffers)
std::size_t peek(const MutableBufferSequence &buffers, asio::error_code &ec)
Class to represent an error code value.
Definition: error_code.hpp:80
lowest_layer_type & lowest_layer()
Get a reference to the lowest layer.
asio::io_service & get_io_service()
Get the io_service associated with the object.
std::size_t peek(const MutableBufferSequence &buffers)
std::size_t fill(asio::error_code &ec)
next_layer_type::lowest_layer_type lowest_layer_type
The type of the lowest layer.
std::size_t write_some(const ConstBufferSequence &buffers)
std::size_t read_some(const MutableBufferSequence &buffers, asio::error_code &ec)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
std::size_t read_some(const MutableBufferSequence &buffers)
void close()
Close the stream.
asio::error_code close(asio::error_code &ec)
Close the stream.
ASIO_INITFN_RESULT_TYPE(ReadHandler, void(asio::error_code, std::size_t)) async_fill(ASIO_MOVE_ARG(ReadHandler) handler)
Start an asynchronous fill.
Adds buffering to the write-related operations of a stream.