Line | Branch | Exec | Source |
---|---|---|---|
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/buffers/sans_prefix.hpp> | ||
14 | #include <boost/http_proto/detail/except.hpp> | ||
15 | #include <boost/assert.hpp> | ||
16 | |||
17 | namespace boost { | ||
18 | namespace http_proto { | ||
19 | namespace detail { | ||
20 | |||
21 | template<bool isConst> | ||
22 | 99 | array_of_buffers<isConst>:: | |
23 | array_of_buffers( | ||
24 | value_type* p, | ||
25 | std::size_t n) noexcept | ||
26 | 99 | : o_(p) | |
27 | 99 | , p_(p) | |
28 | 99 | , n_(n) | |
29 | 99 | , c_(n) | |
30 | { | ||
31 | 99 | } | |
32 | |||
33 | template<bool isConst> | ||
34 | bool | ||
35 | array_of_buffers<isConst>:: | ||
36 | empty() const noexcept | ||
37 | { | ||
38 | return n_ == 0; | ||
39 | } | ||
40 | |||
41 | template<bool isConst> | ||
42 | auto | ||
43 | 15535 | array_of_buffers<isConst>:: | |
44 | data() const noexcept -> | ||
45 | value_type* | ||
46 | { | ||
47 | 15535 | return p_; | |
48 | } | ||
49 | |||
50 | template<bool isConst> | ||
51 | std::size_t | ||
52 | 12487 | array_of_buffers<isConst>:: | |
53 | size() const noexcept | ||
54 | { | ||
55 | 12487 | return n_; | |
56 | } | ||
57 | |||
58 | template<bool isConst> | ||
59 | std::size_t | ||
60 | 24800 | array_of_buffers<isConst>:: | |
61 | capacity() const noexcept | ||
62 | { | ||
63 | 24800 | return c_; | |
64 | } | ||
65 | |||
66 | template<bool isConst> | ||
67 | auto | ||
68 | 25214 | array_of_buffers<isConst>:: | |
69 | begin() const noexcept -> | ||
70 | iterator | ||
71 | { | ||
72 | 25214 | return p_; | |
73 | } | ||
74 | |||
75 | template<bool isConst> | ||
76 | auto | ||
77 | 25214 | array_of_buffers<isConst>:: | |
78 | end() const noexcept -> | ||
79 | iterator | ||
80 | { | ||
81 | 25214 | return p_ + n_; | |
82 | } | ||
83 | |||
84 | template<bool isConst> | ||
85 | auto | ||
86 | 37561 | array_of_buffers<isConst>:: | |
87 | operator[]( | ||
88 | std::size_t i) const noexcept -> | ||
89 | value_type& | ||
90 | { | ||
91 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37561 times.
|
37561 | BOOST_ASSERT(i < n_); |
92 | 37561 | return p_[i]; | |
93 | } | ||
94 | |||
95 | template<bool isConst> | ||
96 | void | ||
97 | 15951 | array_of_buffers<isConst>:: | |
98 | consume(std::size_t n) | ||
99 | { | ||
100 |
2/2✓ Branch 0 taken 34606 times.
✓ Branch 1 taken 45 times.
|
34651 | while(n_ > 0) |
101 | { | ||
102 |
2/2✓ Branch 1 taken 2942 times.
✓ Branch 2 taken 31664 times.
|
34606 | if(n < p_->size()) |
103 | { | ||
104 | 2942 | *p_ = buffers::sans_prefix(*p_, n); | |
105 | 2942 | return; | |
106 | } | ||
107 | 31664 | n -= p_->size(); | |
108 | 31664 | ++p_; | |
109 | 31664 | --n_; | |
110 |
2/2✓ Branch 0 taken 12964 times.
✓ Branch 1 taken 18700 times.
|
31664 | if(n == 0) |
111 | 12964 | return; | |
112 | } | ||
113 | |||
114 | // n exceeded available size | ||
115 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if(n > 0) |
116 | ✗ | detail::throw_logic_error(); | |
117 | } | ||
118 | |||
119 | template<bool isConst> | ||
120 | void | ||
121 | 12400 | array_of_buffers<isConst>:: | |
122 | reset(std::size_t n) | ||
123 | { | ||
124 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12400 times.
|
12400 | BOOST_ASSERT(n <= capacity()); |
125 | 12400 | p_ = o_; | |
126 | 12400 | n_ = n; | |
127 |
2/2✓ Branch 0 taken 55839 times.
✓ Branch 1 taken 12400 times.
|
68239 | for( auto p = p_; p < p_ + n; ++p ) |
128 | 55839 | *p = value_type(); | |
129 | 12400 | } | |
130 | |||
131 | } // detail | ||
132 | } // http_proto | ||
133 | } // boost | ||
134 | |||
135 | #endif | ||
136 |