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/buffers/const_buffer.hpp>
15 :
16 : #include <cstdint>
17 :
18 : namespace boost {
19 : namespace http_proto {
20 : namespace detail {
21 :
22 : class array_of_const_buffers
23 : {
24 : public:
25 : using value_type = buffers::const_buffer;
26 : using iterator = value_type*;
27 : using const_iterator = iterator;
28 :
29 57 : array_of_const_buffers() = default;
30 : array_of_const_buffers(
31 : array_of_const_buffers const&) = default;
32 : array_of_const_buffers&
33 : operator=(array_of_const_buffers const&) = default;
34 :
35 : array_of_const_buffers(
36 : value_type* p,
37 : std::uint16_t n) noexcept;
38 :
39 : bool
40 10763 : empty() const noexcept
41 : {
42 10763 : return size_ == 0;
43 : }
44 :
45 : std::uint16_t
46 9045 : size() const noexcept
47 : {
48 9045 : return size_;
49 : }
50 :
51 : std::uint16_t
52 : max_size() const noexcept
53 : {
54 : return cap_;
55 : }
56 :
57 : std::uint16_t
58 25 : capacity() const noexcept
59 : {
60 25 : return cap_ - size_;
61 : }
62 :
63 : iterator
64 18055 : begin() const noexcept
65 : {
66 18055 : return base_ + pos_;
67 : }
68 :
69 : iterator
70 9019 : end() const noexcept
71 : {
72 9019 : return base_ + pos_ + size_;
73 : }
74 :
75 : value_type&
76 202 : operator[](
77 : std::uint16_t i) const noexcept
78 : {
79 202 : BOOST_ASSERT(i < cap_ - pos_);
80 202 : return base_[i + pos_];
81 : }
82 :
83 : void
84 : consume(std::size_t n);
85 :
86 : void
87 : reset(std::uint16_t n) noexcept;
88 :
89 : void
90 : slide_to_front() noexcept;
91 :
92 : void append(value_type) noexcept;
93 :
94 : private:
95 : value_type* base_ = nullptr;
96 : std::uint16_t cap_ = 0;
97 : std::uint16_t pos_ = 0;
98 : std::uint16_t size_ = 0;
99 : };
100 :
101 : } // detail
102 : } // http_proto
103 : } // boost
104 :
105 : #endif
|