2
// buffered_stream_storage.hpp
3
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11
#ifndef ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
12
#define ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include "asio/detail/push_options.hpp"
20
#include "asio/detail/push_options.hpp"
21
#include <boost/config.hpp>
26
#include "asio/detail/pop_options.hpp"
31
class buffered_stream_storage
34
// The type of the bytes stored in the buffer.
35
typedef unsigned char byte_type;
37
// The type used for offsets into the buffer.
38
typedef std::size_t size_type;
41
explicit buffered_stream_storage(std::size_t capacity)
55
// Return a pointer to the beginning of the unread data.
58
return &buffer_[0] + begin_offset_;
61
// Return a pointer to the beginning of the unread data.
62
const byte_type* data() const
64
return &buffer_[0] + begin_offset_;
67
// Is there no unread data in the buffer.
70
return begin_offset_ == end_offset_;
73
// Return the amount of unread data the is in the buffer.
74
size_type size() const
76
return end_offset_ - begin_offset_;
79
// Resize the buffer to the specified length.
80
void resize(size_type length)
82
assert(length <= capacity());
83
if (begin_offset_ + length <= capacity())
85
end_offset_ = begin_offset_ + length;
89
using namespace std; // For memmove.
90
memmove(&buffer_[0], &buffer_[0] + begin_offset_, size());
96
// Return the maximum size for data in the buffer.
97
size_type capacity() const
99
return buffer_.size();
102
// Consume multiple bytes from the beginning of the buffer.
103
void consume(size_type count)
105
assert(begin_offset_ + count <= end_offset_);
106
begin_offset_ += count;
112
// The offset to the beginning of the unread data.
113
size_type begin_offset_;
115
// The offset to the end of the unread data.
116
size_type end_offset_;
118
// The data in the buffer.
119
std::vector<byte_type> buffer_;
122
} // namespace detail
125
#include "asio/detail/pop_options.hpp"
127
#endif // ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP