11 #ifndef ASIO_BASIC_STREAMBUF_HPP 12 #define ASIO_BASIC_STREAMBUF_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 20 #if !defined(ASIO_NO_IOSTREAM) 105 #if defined(GENERATING_DOCUMENTATION) 106 template <
typename Allocator = std::allocator<
char> >
108 template <
typename Allocator>
115 #if defined(GENERATING_DOCUMENTATION) 132 std::size_t maximum_size = (std::numeric_limits<std::size_t>::max)(),
133 const Allocator&
allocator = Allocator())
134 : max_size_(maximum_size),
137 std::size_t pend = (std::min<std::size_t>)(max_size_,
buffer_delta);
138 buffer_.resize((std::max<std::size_t>)(pend, 1));
139 setg(&buffer_[0], &buffer_[0], &buffer_[0]);
140 setp(&buffer_[0], &buffer_[0] + pend);
160 return pptr() - gptr();
182 const_buffers_type
data()
const 185 (pptr() - gptr()) *
sizeof(char_type)));
208 pptr(), n *
sizeof(char_type)));
225 if (pptr() + n > epptr())
226 n = epptr() - pptr();
227 pbump(static_cast<int>(n));
228 setg(eback(), gptr(), pptr());
240 if (egptr() < pptr())
241 setg(&buffer_[0], gptr(), pptr());
242 if (gptr() + n > pptr())
244 gbump(static_cast<int>(n));
258 setg(&buffer_[0], gptr(), pptr());
259 return traits_type::to_int_type(*gptr());
278 if (pptr() == epptr())
281 if (buffer_size < max_size_ && max_size_ - buffer_size <
buffer_delta)
283 reserve(max_size_ - buffer_size);
291 *pptr() = traits_type::to_char_type(c);
296 return traits_type::not_eof(c);
302 std::size_t gnext = gptr() - &buffer_[0];
303 std::size_t pnext = pptr() - &buffer_[0];
304 std::size_t pend = epptr() - &buffer_[0];
307 if (n <= pend - pnext)
316 std::memmove(&buffer_[0], &buffer_[0] + gnext, pnext);
320 if (n > pend - pnext)
322 if (n <= max_size_ && pnext <= max_size_ - n)
325 buffer_.resize((std::max<std::size_t>)(pend, 1));
329 std::length_error ex(
"asio::streambuf too long");
335 setg(&buffer_[0], &buffer_[0], &buffer_[0] + pnext);
336 setp(&buffer_[0] + pnext, &buffer_[0] + pend);
340 std::size_t max_size_;
341 std::vector<char_type, Allocator> buffer_;
347 return std::min<std::size_t>(
348 std::max<std::size_t>(512, sb.buffer_.capacity() - sb.
size()),
349 std::min<std::size_t>(max_size, sb.
max_size() - sb.
size()));
355 template <
typename Allocator>
359 return std::min<std::size_t>(512,
367 #endif // !defined(ASIO_NO_IOSTREAM) 369 #endif // ASIO_BASIC_STREAMBUF_HPP basic_streambuf(std::size_t maximum_size=(std::numeric_limits< std::size_t >::max)(), const Allocator &allocator=Allocator())
Construct a basic_streambuf object.
friend std::size_t read_size_helper(basic_streambuf &sb, std::size_t max_size)
void reserve(std::size_t n)
basic_streambuf streambuf
Typedef for the typical usage of basic_streambuf.
Holds a buffer that cannot be modified.
int_type overflow(int_type c)
Override std::streambuf behaviour.
std::size_t max_size() const
Get the maximum size of the basic_streambuf.
mutable_buffers_type prepare(std::size_t n)
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
asio::mutable_buffers_1 mutable_buffers_type
int_type underflow()
Override std::streambuf behaviour.
std::size_t buffer_size(const mutable_buffer &b)
Get the number of bytes in a modifiable buffer.
void commit(std::size_t n)
Move characters from the output sequence to the input sequence.
std::size_t size() const
Get the size of the input sequence.
Holds a buffer that can be modified.
Automatically resizable buffer class based on std::streambuf.
const_buffers_type data() const
Get a list of buffers that represents the input sequence.
void consume(std::size_t n)
Remove characters from the input sequence.
asio::const_buffers_1 const_buffers_type
void throw_exception(const Exception &e)