GCC Code Coverage Report


Directory: libs/http_proto/
File: boost/http_proto/detail/impl/array_of_buffers.hpp
Date: 2024-04-04 20:17:10
Exec Total Coverage
Lines: 27 28 96.4%
Functions: 8 8 100.0%
Branches: 8 10 80.0%

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 32 array_of_buffers<isConst>::
22 array_of_buffers(
23 value_type* p,
24 std::size_t n) noexcept
25 : p_(p)
26 32 , n_(n)
27 {
28 32 }
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 505 array_of_buffers<isConst>::
41 data() const noexcept ->
42 value_type*
43 {
44 505 return p_;
45 }
46
47 template<bool isConst>
48 std::size_t
49 87 array_of_buffers<isConst>::
50 size() const noexcept
51 {
52 87 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 167 array_of_buffers<isConst>::
76 operator[](
77 std::size_t i) const noexcept ->
78 value_type&
79 {
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 167 times.
167 BOOST_ASSERT(i < n_);
81 167 return p_[i];
82 }
83
84 template<bool isConst>
85 void
86 32 array_of_buffers<isConst>::
87 consume(std::size_t n)
88 {
89
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 2 times.
32 while(n_ > 0)
90 {
91
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 22 times.
30 if(n < p_->size())
92 {
93 8 *p_ += n;
94 8 return;
95 }
96 22 n -= p_->size();
97 22 ++p_;
98 22 --n_;
99
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2 times.
22 if(n == 0)
100 20 return;
101 }
102
103 // n exceeded available size
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(n > 0)
105 detail::throw_logic_error();
106 }
107
108 } // detail
109 } // http_proto
110 } // boost
111
112 #endif
113