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