Line data Source code
1 : //
2 : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 : //
4 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 : //
7 : // Official repository: https://github.com/cppalliance/http_proto
8 : //
9 :
10 : #ifndef BOOST_HTTP_PROTO_DETAIL_IMPL_ARRAY_OF_BUFFERS_HPP
11 : #define BOOST_HTTP_PROTO_DETAIL_IMPL_ARRAY_OF_BUFFERS_HPP
12 :
13 : #include <boost/http_proto/detail/except.hpp>
14 : #include <boost/assert.hpp>
15 :
16 : namespace boost {
17 : namespace http_proto {
18 : namespace detail {
19 :
20 : template<bool isConst>
21 33 : array_of_buffers<isConst>::
22 : array_of_buffers(
23 : value_type* p,
24 : std::size_t n) noexcept
25 33 : : p_(p)
26 33 : , n_(n)
27 : {
28 33 : }
29 :
30 : template<bool isConst>
31 : bool
32 6 : array_of_buffers<isConst>::
33 : empty() const noexcept
34 : {
35 6 : return n_ == 0;
36 : }
37 :
38 : template<bool isConst>
39 : auto
40 1876 : array_of_buffers<isConst>::
41 : data() const noexcept ->
42 : value_type*
43 : {
44 1876 : return p_;
45 : }
46 :
47 : template<bool isConst>
48 : std::size_t
49 76 : array_of_buffers<isConst>::
50 : size() const noexcept
51 : {
52 76 : return n_;
53 : }
54 :
55 : template<bool isConst>
56 : auto
57 1 : array_of_buffers<isConst>::
58 : begin() const noexcept ->
59 : iterator
60 : {
61 1 : return p_;
62 : }
63 :
64 : template<bool isConst>
65 : auto
66 1 : array_of_buffers<isConst>::
67 : end() const noexcept ->
68 : iterator
69 : {
70 1 : return p_ + n_;
71 : }
72 :
73 : template<bool isConst>
74 : auto
75 146 : array_of_buffers<isConst>::
76 : operator[](
77 : std::size_t i) const noexcept ->
78 : value_type&
79 : {
80 146 : BOOST_ASSERT(i < n_);
81 146 : return p_[i];
82 : }
83 :
84 : template<bool isConst>
85 : void
86 34 : array_of_buffers<isConst>::
87 : consume(std::size_t n)
88 : {
89 36 : while(n_ > 0)
90 : {
91 34 : if(n < p_->size())
92 : {
93 11 : *p_ += n;
94 11 : return;
95 : }
96 23 : n -= p_->size();
97 23 : ++p_;
98 23 : --n_;
99 23 : if(n == 0)
100 21 : return;
101 : }
102 :
103 : // n exceeded available size
104 2 : if(n > 0)
105 0 : detail::throw_logic_error();
106 : }
107 :
108 : } // detail
109 : } // http_proto
110 : } // boost
111 :
112 : #endif
|