File indexing completed on 2025-01-30 09:34:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_IMPL_FLAT_STATIC_BUFFER_IPP
0011 #define BOOST_BEAST_IMPL_FLAT_STATIC_BUFFER_IPP
0012
0013 #include <boost/beast/core/flat_static_buffer.hpp>
0014 #include <boost/throw_exception.hpp>
0015 #include <algorithm>
0016 #include <cstring>
0017 #include <iterator>
0018 #include <memory>
0019 #include <stdexcept>
0020
0021 namespace boost {
0022 namespace beast {
0023
0024
0025
0026
0027
0028
0029
0030
0031 void
0032 flat_static_buffer_base::
0033 clear() noexcept
0034 {
0035 in_ = begin_;
0036 out_ = begin_;
0037 last_ = begin_;
0038 }
0039
0040 auto
0041 flat_static_buffer_base::
0042 prepare(std::size_t n) ->
0043 mutable_buffers_type
0044 {
0045 if(n <= dist(out_, end_))
0046 {
0047 last_ = out_ + n;
0048 return {out_, n};
0049 }
0050 auto const len = size();
0051 if(n > capacity() - len)
0052 BOOST_THROW_EXCEPTION(std::length_error{
0053 "buffer overflow"});
0054 if(len > 0)
0055 std::memmove(begin_, in_, len);
0056 in_ = begin_;
0057 out_ = in_ + len;
0058 last_ = out_ + n;
0059 return {out_, n};
0060 }
0061
0062 void
0063 flat_static_buffer_base::
0064 consume(std::size_t n) noexcept
0065 {
0066 if(n >= size())
0067 {
0068 in_ = begin_;
0069 out_ = in_;
0070 return;
0071 }
0072 in_ += n;
0073 }
0074
0075 void
0076 flat_static_buffer_base::
0077 reset(void* p, std::size_t n) noexcept
0078 {
0079 begin_ = static_cast<char*>(p);
0080 in_ = begin_;
0081 out_ = begin_;
0082 last_ = begin_;
0083 end_ = begin_ + n;
0084 }
0085
0086 }
0087 }
0088
0089 #endif