GCC Code Coverage Report


Directory: libs/http_proto/include/boost/http_proto/
File: boost/http_proto/detail/impl/array_of_buffers.hpp
Date: 2023-02-02 18:17:22
Exec Total Coverage
Lines: 25 28 89.3%
Functions: 8 8 100.0%
Branches: 7 10 70.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 24 array_of_buffers<isConst>::
22 array_of_buffers(
23 value_type* p,
24 std::size_t n) noexcept
25 : p_(p)
26 24 , n_(n)
27 {
28 24 }
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 42 array_of_buffers<isConst>::
41 data() const noexcept ->
42 value_type*
43 {
44 42 return p_;
45 }
46
47 template<bool isConst>
48 std::size_t
49 25 array_of_buffers<isConst>::
50 size() const noexcept
51 {
52 25 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 31 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 31 times.
31 BOOST_ASSERT(i < n_);
81 31 return p_[i];
82 }
83
84 template<bool isConst>
85 void
86 18 array_of_buffers<isConst>::
87 consume(std::size_t n)
88 {
89
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
18 while(n_ > 0)
90 {
91
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
16 if(n < p_->size())
92 {
93 *p_ += n;
94 return;
95 }
96 16 n -= p_->size();
97 16 ++p_;
98 16 --n_;
99
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
16 if(n == 0)
100 14 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