File indexing completed on 2025-01-18 09:28:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
0012 #define BOOST_ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/buffer.hpp>
0020 #include <boost/asio/detail/assert.hpp>
0021 #include <cstddef>
0022 #include <cstring>
0023 #include <vector>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029 namespace detail {
0030
0031 class buffered_stream_storage
0032 {
0033 public:
0034
0035 typedef unsigned char byte_type;
0036
0037
0038 typedef std::size_t size_type;
0039
0040
0041 explicit buffered_stream_storage(std::size_t buffer_capacity)
0042 : begin_offset_(0),
0043 end_offset_(0),
0044 buffer_(buffer_capacity)
0045 {
0046 }
0047
0048
0049 void clear()
0050 {
0051 begin_offset_ = 0;
0052 end_offset_ = 0;
0053 }
0054
0055
0056 mutable_buffer data()
0057 {
0058 return boost::asio::buffer(buffer_) + begin_offset_;
0059 }
0060
0061
0062 const_buffer data() const
0063 {
0064 return boost::asio::buffer(buffer_) + begin_offset_;
0065 }
0066
0067
0068 bool empty() const
0069 {
0070 return begin_offset_ == end_offset_;
0071 }
0072
0073
0074 size_type size() const
0075 {
0076 return end_offset_ - begin_offset_;
0077 }
0078
0079
0080 void resize(size_type length)
0081 {
0082 BOOST_ASIO_ASSERT(length <= capacity());
0083 if (begin_offset_ + length <= capacity())
0084 {
0085 end_offset_ = begin_offset_ + length;
0086 }
0087 else
0088 {
0089 using namespace std;
0090 memmove(&buffer_[0], &buffer_[0] + begin_offset_, size());
0091 end_offset_ = length;
0092 begin_offset_ = 0;
0093 }
0094 }
0095
0096
0097 size_type capacity() const
0098 {
0099 return buffer_.size();
0100 }
0101
0102
0103 void consume(size_type count)
0104 {
0105 BOOST_ASIO_ASSERT(begin_offset_ + count <= end_offset_);
0106 begin_offset_ += count;
0107 if (empty())
0108 clear();
0109 }
0110
0111 private:
0112
0113 size_type begin_offset_;
0114
0115
0116 size_type end_offset_;
0117
0118
0119 std::vector<byte_type> buffer_;
0120 };
0121
0122 }
0123 }
0124 }
0125
0126 #include <boost/asio/detail/pop_options.hpp>
0127
0128 #endif