ゴミ箱
static_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_STATIC_BUFFER_HPP
11 #define BOOST_BEAST_STATIC_BUFFER_HPP
12 
13 #include <boost/beast/config.hpp>
14 #include <boost/asio/buffer.hpp>
15 #include <algorithm>
16 #include <array>
17 #include <cstddef>
18 #include <cstring>
19 
20 namespace boost {
21 namespace beast {
22 
42 {
43  char* begin_;
44  std::size_t in_off_ = 0;
45  std::size_t in_size_ = 0;
46  std::size_t out_size_ = 0;
47  std::size_t capacity_;
48 
49  static_buffer_base(static_buffer_base const& other) = delete;
50  static_buffer_base& operator=(static_buffer_base const&) = delete;
51 
52 public:
54  using const_buffers_type =
55  std::array<boost::asio::mutable_buffer, 2>;
56 
58  using mutable_buffers_type =
59  std::array<boost::asio::mutable_buffer, 2>;
60 
69  static_buffer_base(void* p, std::size_t size);
70 
72  std::size_t
73  size() const
74  {
75  return in_size_;
76  }
77 
79  std::size_t
80  max_size() const
81  {
82  return capacity_;
83  }
84 
86  std::size_t
87  capacity() const
88  {
89  return capacity_;
90  }
91 
95  data() const;
96 
104  prepare(std::size_t size);
105 
112  void
113  commit(std::size_t size);
114 
121  void
122  consume(std::size_t size);
123 
124 protected:
132 
144  void
145  reset(void* p, std::size_t size);
146 };
147 
148 //------------------------------------------------------------------------------
149 
165 template<std::size_t N>
167 {
168  char buf_[N];
169 
170 public:
173 
176  : static_buffer_base(buf_, N)
177  {
178  }
179 
181  static_buffer& operator=(static_buffer const&);
182 
186  {
187  return *this;
188  }
189 
191  static_buffer_base const&
192  base() const
193  {
194  return *this;
195  }
196 
198  std::size_t constexpr
199  max_size() const
200  {
201  return N;
202  }
203 
205  std::size_t constexpr
206  capacity() const
207  {
208  return N;
209  }
210 };
211 
212 } // beast
213 } // boost
214 
216 
217 #endif
Definition: async_result.hpp:20
std::size_t size() const
Return the size of the input sequence.
Definition: static_buffer.hpp:73
static_buffer_base const & base() const
Returns the static_buffer_base portion of this object.
Definition: static_buffer.hpp:192
std::size_t capacity() const
Return the maximum sum of input and output sizes that can be held without an allocation.
Definition: static_buffer.hpp:87
mutable_buffers_type prepare(std::size_t size)
Definition: static_buffer.ipp:56
void consume(std::size_t size)
Definition: static_buffer.ipp:91
std::array< boost::asio::mutable_buffer, 2 > mutable_buffers_type
The type used to represent the output sequence as a list of buffers.
Definition: static_buffer.hpp:59
Definition: static_buffer.hpp:166
static_buffer_base & base()
Returns the static_buffer_base portion of this object.
Definition: static_buffer.hpp:185
std::array< boost::asio::mutable_buffer, 2 > const_buffers_type
The type used to represent the input sequence as a list of buffers.
Definition: static_buffer.hpp:55
const_buffers_type data() const
Definition: static_buffer.ipp:35
static_buffer()
Constructor.
Definition: static_buffer.hpp:175
std::size_t max_size() const
Return the maximum sum of the input and output sequence sizes.
Definition: static_buffer.hpp:80
std::size_t constexpr max_size() const
Return the maximum sum of the input and output sequence sizes.
Definition: static_buffer.hpp:199
void reset(void *p, std::size_t size)
Definition: static_buffer.ipp:111
Definition: static_buffer.hpp:41
void commit(std::size_t size)
Definition: static_buffer.ipp:82
std::size_t constexpr capacity() const
Return the maximum sum of input and output sizes that can be held without an allocation.
Definition: static_buffer.hpp:206