ゴミ箱
buffer_prefix.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_BUFFER_PREFIX_HPP
11 #define BOOST_BEAST_BUFFER_PREFIX_HPP
12 
13 #include <boost/beast/config.hpp>
16 #include <boost/asio/buffer.hpp>
17 #include <cstdint>
18 #include <type_traits>
19 
20 namespace boost {
21 namespace beast {
22 
31 template<class BufferSequence>
33 {
34  using buffers_type = typename
35  std::decay<BufferSequence>::type;
36 
37  using iter_type =
38  typename buffers_type::const_iterator;
39 
40  BufferSequence bs_;
41  std::size_t size_;
42  iter_type end_;
43 
44  template<class Deduced>
46  Deduced&& other, std::size_t dist)
47  : bs_(std::forward<Deduced>(other).bs_)
48  , size_(other.size_)
49  , end_(std::next(bs_.begin(), dist))
50  {
51  }
52 
53  void
54  setup(std::size_t size);
55 
56 public:
58  using value_type = typename std::conditional<
59  std::is_convertible<typename
60  std::iterator_traits<iter_type>::value_type,
61  boost::asio::mutable_buffer>::value,
62  boost::asio::mutable_buffer,
63  boost::asio::const_buffer>::type;
64 
65 #if BOOST_BEAST_DOXYGEN
66  using const_iterator = implementation_defined;
68 
69 #else
70  class const_iterator;
71 
72 #endif
73 
76 
79 
82 
85 
98  std::size_t size,
99  BufferSequence const& buffers);
100 
110  template<class... Args>
112  std::size_t size,
113  boost::in_place_init_t,
114  Args&&... args);
115 
118  begin() const;
119 
122  end() const;
123 };
124 
139 inline
140 boost::asio::const_buffer
141 buffer_prefix(std::size_t size,
142  boost::asio::const_buffer buffer)
143 {
144  using boost::asio::buffer_cast;
145  using boost::asio::buffer_size;
146  return { buffer_cast<void const*>(buffer),
147  (std::min)(size, buffer_size(buffer)) };
148 }
149 
164 inline
165 boost::asio::mutable_buffer
166 buffer_prefix(std::size_t size,
167  boost::asio::mutable_buffer buffer)
168 {
169  using boost::asio::buffer_cast;
170  using boost::asio::buffer_size;
171  return {buffer_cast<void*>(buffer),
172  (std::min)(size, buffer_size(buffer))};
173 }
174 
191 template<class BufferSequence>
192 #if BOOST_BEAST_DOXYGEN
194 #else
195 inline
196 typename std::enable_if<
197  ! std::is_same<BufferSequence,
198  boost::asio::const_buffer>::value &&
199  ! std::is_same<BufferSequence,
200  boost::asio::mutable_buffer>::value,
202 #endif
203 buffer_prefix(std::size_t size, BufferSequence const& buffers)
204 {
205  static_assert(
208  "BufferSequence requirements not met");
210 }
211 
222 template<class BufferSequence>
223 typename std::conditional<
225  boost::asio::mutable_buffer,
226  boost::asio::const_buffer>::type
227 buffer_front(BufferSequence const& buffers)
228 {
229  auto const first = buffers.begin();
230  if(first == buffers.end())
231  return {};
232  return *first;
233 }
234 
235 } // beast
236 } // boost
237 
239 
240 #endif
buffer_prefix_view & operator=(buffer_prefix_view &&)
Move assignment.
Definition: buffer_prefix.ipp:189
const_iterator end() const
Get a bidirectional iterator to one past the last element.
Definition: buffer_prefix.ipp:245
typename std::conditional< std::is_convertible< typename std::iterator_traits< iter_type >::value_type, boost::asio::mutable_buffer >::value, boost::asio::mutable_buffer, boost::asio::const_buffer >::type value_type
The type for each element in the list of buffers.
Definition: buffer_prefix.hpp:63
Definition: buffer_prefix.ipp:50
Definition: async_result.hpp:20
detail::buffers_helper< ConstBufferSequence > buffers(ConstBufferSequence const &b)
Definition: ostream.hpp:50
Definition: buffer_prefix.hpp:32
Definition: type_traits.hpp:59
std::conditional< is_mutable_buffer_sequence< BufferSequence >::value, boost::asio::mutable_buffer, boost::asio::const_buffer >::type buffer_front(BufferSequence const &buffers)
Definition: buffer_prefix.hpp:227
const_iterator begin() const
Get a bidirectional iterator to the first element.
Definition: buffer_prefix.ipp:236
Definition: type_traits.hpp:96
boost::asio::const_buffer buffer_prefix(std::size_t size, boost::asio::const_buffer buffer)
Definition: buffer_prefix.hpp:141