ゴミ箱
multi_buffer.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9 
10 #ifndef BOOST_BEAST_MULTI_BUFFER_HPP
11 #define BOOST_BEAST_MULTI_BUFFER_HPP
12 
13 #include <boost/beast/config.hpp>
16 #include <boost/asio/buffer.hpp>
17 #include <boost/intrusive/list.hpp>
18 #include <iterator>
19 #include <limits>
20 #include <memory>
21 #include <type_traits>
22 
23 namespace boost {
24 namespace beast {
25 
37 template<class Allocator>
39 #if ! BOOST_BEAST_DOXYGEN
41  typename detail::allocator_traits<Allocator>::
42  template rebind_alloc<char>>
43 #endif
44 {
45  using base_alloc_type = typename
47  template rebind_alloc<char>;
48 
49  // Storage for the list of buffers representing the input
50  // and output sequences. The allocation for each element
51  // contains `element` followed by raw storage bytes.
52  class element;
53 
54  using alloc_traits = detail::allocator_traits<base_alloc_type>;
55  using list_type = typename boost::intrusive::make_list<element,
56  boost::intrusive::constant_time_size<true>>::type;
57  using iter = typename list_type::iterator;
58  using const_iter = typename list_type::const_iterator;
59 
60  using size_type = typename alloc_traits::size_type;
61  using const_buffer = boost::asio::const_buffer;
62  using mutable_buffer = boost::asio::mutable_buffer;
63 
64  static_assert(std::is_base_of<std::bidirectional_iterator_tag,
65  typename std::iterator_traits<iter>::iterator_category>::value,
66  "BidirectionalIterator requirements not met");
67 
68  static_assert(std::is_base_of<std::bidirectional_iterator_tag,
69  typename std::iterator_traits<const_iter>::iterator_category>::value,
70  "BidirectionalIterator requirements not met");
71 
72  std::size_t max_ =
73  (std::numeric_limits<std::size_t>::max)();
74  list_type list_; // list of allocated buffers
75  iter out_; // element that contains out_pos_
76  size_type in_size_ = 0; // size of the input sequence
77  size_type in_pos_ = 0; // input offset in list_.front()
78  size_type out_pos_ = 0; // output offset in *out_
79  size_type out_end_ = 0; // output end offset in list_.back()
80 
81 public:
83  using allocator_type = Allocator;
84 
85 #if BOOST_BEAST_DOXYGEN
86  using const_buffers_type = implementation_defined;
88 
90  using mutable_buffers_type = implementation_defined;
91 
92 #else
93  class const_buffers_type;
94 
96 
97 #endif
98 
101 
107 
112  explicit
113  basic_multi_buffer(std::size_t limit);
114 
119  explicit
120  basic_multi_buffer(Allocator const& alloc);
121 
129  std::size_t limit, Allocator const& alloc);
130 
140 
152  Allocator const& alloc);
153 
159 
167  Allocator const& alloc);
168 
173  template<class OtherAlloc>
175  OtherAlloc> const& other);
176 
183  template<class OtherAlloc>
185  OtherAlloc> const& other, allocator_type const& alloc);
186 
196  operator=(basic_multi_buffer&& other);
197 
205 
212  template<class OtherAlloc>
214  basic_multi_buffer<OtherAlloc> const& other);
215 
219  {
220  return this->member();
221  }
222 
224  size_type
225  size() const
226  {
227  return in_size_;
228  }
229 
231  size_type
232  max_size() const
233  {
234  return max_;
235  }
236 
238  std::size_t
239  capacity() const;
240 
246  data() const;
247 
254  prepare(size_type n);
255 
261  void
262  commit(size_type n);
263 
265  void
266  consume(size_type n);
267 
268  template<class Alloc>
269  friend
270  void
271  swap(
274 
275 private:
276  template<class OtherAlloc>
277  friend class basic_multi_buffer;
278 
279  void
280  delete_list();
281 
282  void
283  reset();
284 
285  template<class DynamicBuffer>
286  void
287  copy_from(DynamicBuffer const& other);
288 
289  void
290  move_assign(basic_multi_buffer& other, std::false_type);
291 
292  void
293  move_assign(basic_multi_buffer& other, std::true_type);
294 
295  void
296  copy_assign(basic_multi_buffer const& other, std::false_type);
297 
298  void
299  copy_assign(basic_multi_buffer const& other, std::true_type);
300 
301  void
303 
304  void
305  swap(basic_multi_buffer&, std::true_type);
306 
307  void
308  swap(basic_multi_buffer&, std::false_type);
309 
310  void
311  debug_check() const;
312 };
313 
316 
317 } // beast
318 } // boost
319 
321 
322 #endif
Definition: async_result.hpp:20
void consume(size_type n)
Remove bytes from the input sequence.
Definition: multi_buffer.ipp:776
basic_multi_buffer()
Definition: multi_buffer.ipp:426
basic_multi_buffer & operator=(basic_multi_buffer &&other)
Definition: multi_buffer.ipp:565
size_type size() const
Returns the size of the input sequence.
Definition: multi_buffer.hpp:225
size_type max_size() const
Returns the permitted maximum sum of the sizes of the input and output sequence.
Definition: multi_buffer.hpp:232
friend void swap(basic_multi_buffer< Alloc > &lhs, basic_multi_buffer< Alloc > &rhs)
std::size_t capacity() const
Returns the maximum sum of the sizes of the input sequence and output sequence the buffer can hold wi...
Definition: multi_buffer.ipp:607
void commit(size_type n)
Definition: multi_buffer.ipp:729
Definition: multi_buffer.hpp:38
~basic_multi_buffer()
Destructor.
Definition: multi_buffer.ipp:419
Definition: multi_buffer.ipp:90
mutable_buffers_type prepare(size_type n)
Definition: multi_buffer.ipp:630
allocator_type get_allocator() const
Returns a copy of the associated allocator.
Definition: multi_buffer.hpp:218
std::allocator_traits< Alloc > allocator_traits
Definition: allocator.hpp:34
Definition: empty_base_optimization.hpp:35
const_buffers_type data() const
Definition: multi_buffer.ipp:621
detail::allocator_traits< Allocator >::template rebind_alloc< char > & member() noexcept
Definition: empty_base_optimization.hpp:48
Allocator allocator_type
The type of allocator used.
Definition: multi_buffer.hpp:83