Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / buffered_stream_storage.hpp @ 2486

History | View | Annotate | Download (2.9 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/buffered_stream_storage.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
12 2486 sjacqu01
#define BOOST_ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
#include <boost/asio/buffer.hpp>
20 2486 sjacqu01
#include <boost/asio/detail/assert.hpp>
21 2486 sjacqu01
#include <cstddef>
22 2486 sjacqu01
#include <cstring>
23 2486 sjacqu01
#include <vector>
24 2486 sjacqu01
25 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
26 2486 sjacqu01
27 2486 sjacqu01
namespace boost {
28 2486 sjacqu01
namespace asio {
29 2486 sjacqu01
namespace detail {
30 2486 sjacqu01
31 2486 sjacqu01
class buffered_stream_storage
32 2486 sjacqu01
{
33 2486 sjacqu01
public:
34 2486 sjacqu01
  // The type of the bytes stored in the buffer.
35 2486 sjacqu01
  typedef unsigned char byte_type;
36 2486 sjacqu01
37 2486 sjacqu01
  // The type used for offsets into the buffer.
38 2486 sjacqu01
  typedef std::size_t size_type;
39 2486 sjacqu01
40 2486 sjacqu01
  // Constructor.
41 2486 sjacqu01
  explicit buffered_stream_storage(std::size_t buffer_capacity)
42 2486 sjacqu01
    : begin_offset_(0),
43 2486 sjacqu01
      end_offset_(0),
44 2486 sjacqu01
      buffer_(buffer_capacity)
45 2486 sjacqu01
  {
46 2486 sjacqu01
  }
47 2486 sjacqu01
48 2486 sjacqu01
  /// Clear the buffer.
49 2486 sjacqu01
  void clear()
50 2486 sjacqu01
  {
51 2486 sjacqu01
    begin_offset_ = 0;
52 2486 sjacqu01
    end_offset_ = 0;
53 2486 sjacqu01
  }
54 2486 sjacqu01
55 2486 sjacqu01
  // Return a pointer to the beginning of the unread data.
56 2486 sjacqu01
  mutable_buffer data()
57 2486 sjacqu01
  {
58 2486 sjacqu01
    return boost::asio::buffer(buffer_) + begin_offset_;
59 2486 sjacqu01
  }
60 2486 sjacqu01
61 2486 sjacqu01
  // Return a pointer to the beginning of the unread data.
62 2486 sjacqu01
  const_buffer data() const
63 2486 sjacqu01
  {
64 2486 sjacqu01
    return boost::asio::buffer(buffer_) + begin_offset_;
65 2486 sjacqu01
  }
66 2486 sjacqu01
67 2486 sjacqu01
  // Is there no unread data in the buffer.
68 2486 sjacqu01
  bool empty() const
69 2486 sjacqu01
  {
70 2486 sjacqu01
    return begin_offset_ == end_offset_;
71 2486 sjacqu01
  }
72 2486 sjacqu01
73 2486 sjacqu01
  // Return the amount of unread data the is in the buffer.
74 2486 sjacqu01
  size_type size() const
75 2486 sjacqu01
  {
76 2486 sjacqu01
    return end_offset_ - begin_offset_;
77 2486 sjacqu01
  }
78 2486 sjacqu01
79 2486 sjacqu01
  // Resize the buffer to the specified length.
80 2486 sjacqu01
  void resize(size_type length)
81 2486 sjacqu01
  {
82 2486 sjacqu01
    BOOST_ASIO_ASSERT(length <= capacity());
83 2486 sjacqu01
    if (begin_offset_ + length <= capacity())
84 2486 sjacqu01
    {
85 2486 sjacqu01
      end_offset_ = begin_offset_ + length;
86 2486 sjacqu01
    }
87 2486 sjacqu01
    else
88 2486 sjacqu01
    {
89 2486 sjacqu01
      using namespace std; // For memmove.
90 2486 sjacqu01
      memmove(&buffer_[0], &buffer_[0] + begin_offset_, size());
91 2486 sjacqu01
      end_offset_ = length;
92 2486 sjacqu01
      begin_offset_ = 0;
93 2486 sjacqu01
    }
94 2486 sjacqu01
  }
95 2486 sjacqu01
96 2486 sjacqu01
  // Return the maximum size for data in the buffer.
97 2486 sjacqu01
  size_type capacity() const
98 2486 sjacqu01
  {
99 2486 sjacqu01
    return buffer_.size();
100 2486 sjacqu01
  }
101 2486 sjacqu01
102 2486 sjacqu01
  // Consume multiple bytes from the beginning of the buffer.
103 2486 sjacqu01
  void consume(size_type count)
104 2486 sjacqu01
  {
105 2486 sjacqu01
    BOOST_ASIO_ASSERT(begin_offset_ + count <= end_offset_);
106 2486 sjacqu01
    begin_offset_ += count;
107 2486 sjacqu01
    if (empty())
108 2486 sjacqu01
      clear();
109 2486 sjacqu01
  }
110 2486 sjacqu01
111 2486 sjacqu01
private:
112 2486 sjacqu01
  // The offset to the beginning of the unread data.
113 2486 sjacqu01
  size_type begin_offset_;
114 2486 sjacqu01
115 2486 sjacqu01
  // The offset to the end of the unread data.
116 2486 sjacqu01
  size_type end_offset_;
117 2486 sjacqu01
118 2486 sjacqu01
  // The data in the buffer.
119 2486 sjacqu01
  std::vector<byte_type> buffer_;
120 2486 sjacqu01
};
121 2486 sjacqu01
122 2486 sjacqu01
} // namespace detail
123 2486 sjacqu01
} // namespace asio
124 2486 sjacqu01
} // namespace boost
125 2486 sjacqu01
126 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
127 2486 sjacqu01
128 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP