Realistic 3D camera system
3D camera system components
buffered_write_stream.hpp
Go to the documentation of this file.
1 //
2 // buffered_write_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_WRITE_STREAM_HPP
12 #define ASIO_BUFFERED_WRITE_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>
21 #include "asio/buffer.hpp"
27 #include "asio/error.hpp"
28 #include "asio/io_service.hpp"
29 #include "asio/write.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_write_stream(Arg& a)
68  : next_layer_(a),
69  storage_(default_buffer_size)
70  {
71  }
72 
74  template <typename Arg>
75  buffered_write_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 
120  std::size_t flush();
121 
125  std::size_t flush(asio::error_code& ec);
126 
128  template <typename WriteHandler>
129  ASIO_INITFN_RESULT_TYPE(WriteHandler,
130  void (asio::error_code, std::size_t))
131  async_flush(ASIO_MOVE_ARG(WriteHandler) handler);
132 
135  template <typename ConstBufferSequence>
136  std::size_t write_some(const ConstBufferSequence& buffers);
137 
140  template <typename ConstBufferSequence>
141  std::size_t write_some(const ConstBufferSequence& buffers,
142  asio::error_code& ec);
143 
146  template <typename ConstBufferSequence, typename WriteHandler>
147  ASIO_INITFN_RESULT_TYPE(WriteHandler,
148  void (asio::error_code, std::size_t))
149  async_write_some(const ConstBufferSequence& buffers,
150  ASIO_MOVE_ARG(WriteHandler) handler);
151 
154  template <typename MutableBufferSequence>
155  std::size_t read_some(const MutableBufferSequence& buffers)
156  {
157  return next_layer_.read_some(buffers);
158  }
159 
162  template <typename MutableBufferSequence>
163  std::size_t read_some(const MutableBufferSequence& buffers,
164  asio::error_code& ec)
165  {
166  return next_layer_.read_some(buffers, ec);
167  }
168 
171  template <typename MutableBufferSequence, typename ReadHandler>
172  ASIO_INITFN_RESULT_TYPE(ReadHandler,
173  void (asio::error_code, std::size_t))
174  async_read_some(const MutableBufferSequence& buffers,
175  ASIO_MOVE_ARG(ReadHandler) handler)
176  {
178  ReadHandler, void (asio::error_code, std::size_t)> init(
179  ASIO_MOVE_CAST(ReadHandler)(handler));
180 
181  next_layer_.async_read_some(buffers,
182  ASIO_MOVE_CAST(ASIO_HANDLER_TYPE(ReadHandler,
183  void (asio::error_code, std::size_t)))(init.handler));
184 
185  return init.result.get();
186  }
187 
190  template <typename MutableBufferSequence>
191  std::size_t peek(const MutableBufferSequence& buffers)
192  {
193  return next_layer_.peek(buffers);
194  }
195 
198  template <typename MutableBufferSequence>
199  std::size_t peek(const MutableBufferSequence& buffers,
200  asio::error_code& ec)
201  {
202  return next_layer_.peek(buffers, ec);
203  }
204 
206  std::size_t in_avail()
207  {
208  return next_layer_.in_avail();
209  }
210 
212  std::size_t in_avail(asio::error_code& ec)
213  {
214  return next_layer_.in_avail(ec);
215  }
216 
217 private:
220  template <typename ConstBufferSequence>
221  std::size_t copy(const ConstBufferSequence& buffers);
222 
224  Stream next_layer_;
225 
226  // The data in the buffer.
228 };
229 
230 } // namespace asio
231 
233 
235 
236 #endif // ASIO_BUFFERED_WRITE_STREAM_HPP
buffered_write_stream(Arg &a, std::size_t buffer_size)
Construct, passing the specified argument to initialise the next layer.
std::size_t in_avail(asio::error_code &ec)
Determine the amount of data that may be read without blocking.
Provides core I/O functionality.
Definition: io_service.hpp:184
asio::error_code close(asio::error_code &ec)
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 peek(const MutableBufferSequence &buffers)
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)
std::size_t read_some(const MutableBufferSequence &buffers)
const lowest_layer_type & lowest_layer() const
Get a const reference to the lowest layer.
next_layer_type::lowest_layer_type lowest_layer_type
The type of the lowest layer.
std::size_t peek(const MutableBufferSequence &buffers, asio::error_code &ec)
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 in_avail()
Determine the amount of data that may be read without blocking.
ASIO_STATIC_CONSTANT(std::size_t, default_buffer_size=1024)
next_layer_type & next_layer()
Get a reference to the next layer.
Class to represent an error code value.
Definition: error_code.hpp:80
buffered_write_stream(Arg &a)
Construct, passing the specified argument to initialise the next layer.
handler_type< Handler, Signature >::type handler
ASIO_MOVE_ARG(WriteHandler) handler)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
std::size_t read_some(const MutableBufferSequence &buffers, asio::error_code &ec)
async_result< typename handler_type< Handler, Signature >::type > result
void close()
Close the stream.
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.
Adds buffering to the write-related operations of a stream.