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/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 | 96 | array_of_buffers<isConst>:: | |
22 | array_of_buffers( | ||
23 | value_type* p, | ||
24 | std::size_t n) noexcept | ||
25 | 96 | : o_(p) | |
26 | 96 | , p_(p) | |
27 | 96 | , n_(n) | |
28 | 96 | , c_(n) | |
29 | { | ||
30 | 96 | } | |
31 | |||
32 | template<bool isConst> | ||
33 | bool | ||
34 | array_of_buffers<isConst>:: | ||
35 | empty() const noexcept | ||
36 | { | ||
37 | return n_ == 0; | ||
38 | } | ||
39 | |||
40 | template<bool isConst> | ||
41 | auto | ||
42 | 15924 | array_of_buffers<isConst>:: | |
43 | data() const noexcept -> | ||
44 | value_type* | ||
45 | { | ||
46 | 15924 | return p_; | |
47 | } | ||
48 | |||
49 | template<bool isConst> | ||
50 | std::size_t | ||
51 | 12614 | array_of_buffers<isConst>:: | |
52 | size() const noexcept | ||
53 | { | ||
54 | 12614 | return n_; | |
55 | } | ||
56 | |||
57 | template<bool isConst> | ||
58 | std::size_t | ||
59 | 25068 | array_of_buffers<isConst>:: | |
60 | capacity() const noexcept | ||
61 | { | ||
62 | 25068 | return c_; | |
63 | } | ||
64 | |||
65 | template<bool isConst> | ||
66 | auto | ||
67 | 32097 | array_of_buffers<isConst>:: | |
68 | begin() const noexcept -> | ||
69 | iterator | ||
70 | { | ||
71 | 32097 | return p_; | |
72 | } | ||
73 | |||
74 | template<bool isConst> | ||
75 | auto | ||
76 | 32097 | array_of_buffers<isConst>:: | |
77 | end() const noexcept -> | ||
78 | iterator | ||
79 | { | ||
80 | 32097 | return p_ + n_; | |
81 | } | ||
82 | |||
83 | template<bool isConst> | ||
84 | auto | ||
85 | 38030 | array_of_buffers<isConst>:: | |
86 | operator[]( | ||
87 | std::size_t i) const noexcept -> | ||
88 | value_type& | ||
89 | { | ||
90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38030 times.
|
38030 | BOOST_ASSERT(i < n_); |
91 | 38030 | return p_[i]; | |
92 | } | ||
93 | |||
94 | template<bool isConst> | ||
95 | void | ||
96 | 16212 | array_of_buffers<isConst>:: | |
97 | consume(std::size_t n) | ||
98 | { | ||
99 |
2/2✓ Branch 0 taken 35080 times.
✓ Branch 1 taken 51 times.
|
35131 | while(n_ > 0) |
100 | { | ||
101 |
2/2✓ Branch 1 taken 3072 times.
✓ Branch 2 taken 32008 times.
|
35080 | if(n < p_->size()) |
102 | { | ||
103 | 3072 | *p_ += n; | |
104 | 3072 | return; | |
105 | } | ||
106 | 32008 | n -= p_->size(); | |
107 | 32008 | ++p_; | |
108 | 32008 | --n_; | |
109 |
2/2✓ Branch 0 taken 13089 times.
✓ Branch 1 taken 18919 times.
|
32008 | if(n == 0) |
110 | 13089 | return; | |
111 | } | ||
112 | |||
113 | // n exceeded available size | ||
114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
|
51 | if(n > 0) |
115 | ✗ | detail::throw_logic_error(); | |
116 | } | ||
117 | |||
118 | template<bool isConst> | ||
119 | void | ||
120 | 12534 | array_of_buffers<isConst>:: | |
121 | reset(std::size_t n) | ||
122 | { | ||
123 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12534 times.
|
12534 | BOOST_ASSERT(n <= capacity()); |
124 | 12534 | p_ = o_; | |
125 | 12534 | n_ = n; | |
126 |
2/2✓ Branch 0 taken 56457 times.
✓ Branch 1 taken 12534 times.
|
68991 | for( auto p = p_; p < p_ + n; ++p ) |
127 | 56457 | *p = value_type(); | |
128 | 12534 | } | |
129 | |||
130 | } // detail | ||
131 | } // http_proto | ||
132 | } // boost | ||
133 | |||
134 | #endif | ||
135 |