GCC Code Coverage Report


Directory: libs/http_proto/include/boost/http_proto/
File: boost/http_proto/detail/impl/flat_buffer.ipp
Date: 2023-02-02 18:17:22
Exec Total Coverage
Lines: 27 35 77.1%
Functions: 6 8 75.0%
Branches: 6 12 50.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_FLAT_BUFFER_IPP
11 #define BOOST_HTTP_PROTO_DETAIL_IMPL_FLAT_BUFFER_IPP
12
13 #include <boost/http_proto/detail/flat_buffer.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 770 flat_buffer::
22 flat_buffer(
23 void* data,
24 std::size_t capacity,
25 770 std::size_t initial_size) noexcept
26 : data_(reinterpret_cast<
27 unsigned char*>(data))
28 , cap_(capacity)
29 770 , in_size_(initial_size)
30 {
31
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 770 times.
770 BOOST_ASSERT(in_size_ <= cap_);
32 770 }
33
34 bool
35 flat_buffer::
36 empty() const noexcept
37 {
38 return in_size_ == 0;
39 }
40
41 std::size_t
42 7173 flat_buffer::
43 size() const noexcept
44 {
45 7173 return in_size_;
46 }
47
48 std::size_t
49 flat_buffer::
50 capacity() const noexcept
51 {
52 return cap_;
53 }
54
55 const_buffer
56 33 flat_buffer::
57 data() const noexcept
58 {
59 return {
60 33 data_ + in_pos_,
61 33 in_size_ };
62 }
63
64 mutable_buffer
65 3185 flat_buffer::
66 prepare(std::size_t n)
67 {
68 // n exceeds available space
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3185 times.
3185 if(n > cap_ - in_size_)
70 detail::throw_invalid_argument();
71
72 3185 out_size_ = n;
73 return {
74 3185 data_ + in_pos_ + in_size_,
75 3185 n };
76 }
77
78 void
79 3185 flat_buffer::
80 commit(std::size_t n)
81 {
82 // n exceeds output size
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3185 times.
3185 if(n > out_size_)
84 detail::throw_invalid_argument();
85
86 3185 in_size_ += n;
87 3185 out_size_ = 0;
88 3185 }
89
90 void
91 33 flat_buffer::
92 consume(std::size_t n) noexcept
93 {
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 BOOST_ASSERT(out_size_ == 0);
95
96 // n exceeds input size
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if(n > in_size_)
98 detail::throw_invalid_argument();
99
100 33 in_size_ -= n;
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if(in_size_ > 0)
102 in_pos_ += n;
103 else
104 33 in_pos_ = 0;
105 33 }
106
107 } // detail
108 } // http_proto
109 } // boost
110
111 #endif
112