GCC Code Coverage Report


Directory: libs/http_proto/
File: libs/http_proto/src/buffered_base.cpp
Date: 2024-04-24 06:37:24
Exec Total Coverage
Lines: 26 26 100.0%
Functions: 4 4 100.0%
Branches: 8 8 100.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 #include <boost/http_proto/buffered_base.hpp>
11 #include <boost/http_proto/detail/except.hpp>
12
13 namespace boost {
14 namespace http_proto {
15
16 buffered_base::
17 ~buffered_base() = default;
18
19 void
20 2 buffered_base::
21 on_init(allocator&)
22 {
23 2 }
24
25 void
26 8 buffered_base::
27 init(
28 allocator& a,
29 std::size_t max_size)
30 {
31 // max_size exceeds limit
32
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 7 times.
8 if(max_size > a.max_size())
33 1 detail::throw_invalid_argument();
34
35 struct restorer
36 {
37 allocator& a;
38 std::size_t n;
39
40 7 ~restorer()
41 7 {
42 7 a.restore(n);
43 7 }
44 };
45
46 auto const n =
47 7 a.max_size() - max_size;
48 7 a.remove(n);
49 7 restorer r{a, n};
50
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 2 times.
7 init(a);
51 5 }
52
53 //------------------------------------------------
54
55 void*
56 10 buffered_base::
57 allocator::
58 allocate(
59 std::size_t n)
60 {
61 // n exceeds available space
62
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
10 if(n > size_)
63 3 detail::throw_invalid_argument();
64
65 7 size_used_ += n;
66
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
7 if(down_)
67 {
68 3 auto p = base_ + size_ - n;
69 3 size_ -= n;
70 3 return p;
71 }
72 4 auto p = base_;
73 4 base_ += n;
74 4 size_ -= n;
75 4 return p;
76 }
77
78 } // http_proto
79 } // boost
80