Line data Source code
1 : //
2 : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 : // Copyright (c) 2025 Mohammad Nejati
4 : //
5 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 : //
8 : // Official repository: https://github.com/cppalliance/http_proto
9 : //
10 :
11 : #ifndef BOOST_HTTP_PROTO_DETAIL_ARRAY_OF_BUFFERS_HPP
12 : #define BOOST_HTTP_PROTO_DETAIL_ARRAY_OF_BUFFERS_HPP
13 :
14 : #include <boost/assert.hpp>
15 : #include <boost/buffers/buffer.hpp>
16 :
17 : #include <cstdint>
18 :
19 : namespace boost {
20 : namespace http_proto {
21 : namespace detail {
22 :
23 : class array_of_const_buffers
24 : {
25 : public:
26 : using value_type = buffers::const_buffer;
27 : using iterator = value_type*;
28 : using const_iterator = iterator;
29 :
30 24 : array_of_const_buffers() = default;
31 : array_of_const_buffers(
32 : array_of_const_buffers const&) = default;
33 : array_of_const_buffers&
34 : operator=(array_of_const_buffers const&) = default;
35 :
36 : array_of_const_buffers(
37 : value_type* p,
38 : std::uint16_t n) noexcept;
39 :
40 : bool
41 3704 : empty() const noexcept
42 : {
43 3704 : return size_ == 0;
44 : }
45 :
46 : std::uint16_t
47 10 : size() const noexcept
48 : {
49 10 : return size_;
50 : }
51 :
52 : std::uint16_t
53 : max_size() const noexcept
54 : {
55 : return cap_;
56 : }
57 :
58 : std::uint16_t
59 61 : capacity() const noexcept
60 : {
61 61 : return cap_ - size_;
62 : }
63 :
64 : iterator
65 1978 : begin() const noexcept
66 : {
67 1978 : return base_ + pos_;
68 : }
69 :
70 : iterator
71 1976 : end() const noexcept
72 : {
73 1976 : return base_ + pos_ + size_;
74 : }
75 :
76 : value_type&
77 85 : operator[](
78 : std::uint16_t i) const noexcept
79 : {
80 85 : BOOST_ASSERT(i < cap_ - pos_);
81 85 : return base_[i + pos_];
82 : }
83 :
84 : void
85 : consume(std::size_t n);
86 :
87 : void
88 : reset(std::uint16_t n) noexcept;
89 :
90 : void
91 : slide_to_front() noexcept;
92 :
93 : void append(value_type) noexcept;
94 :
95 : private:
96 : value_type* base_ = nullptr;
97 : std::uint16_t cap_ = 0;
98 : std::uint16_t pos_ = 0;
99 : std::uint16_t size_ = 0;
100 : };
101 :
102 : } // detail
103 : } // http_proto
104 : } // boost
105 :
106 : #endif
|