GCC Code Coverage Report


Directory: libs/http_proto/
File: libs/http_proto/src/context.cpp
Date: 2024-05-09 08:15:19
Exec Total Coverage
Lines: 17 18 94.4%
Functions: 4 4 100.0%
Branches: 4 6 66.7%

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/context.hpp>
11 #include <boost/http_proto/detail/except.hpp>
12 //#include <boost/unordered_map.hpp> // doesn't support heterogenous lookup yet
13 #include <unordered_map>
14
15 namespace boost {
16 namespace http_proto {
17
18 struct context::data
19 {
20 // Installed services
21 std::unordered_map<
22 detail::type_index,
23 std::unique_ptr<service>,
24 detail::type_index_hasher
25 > services;
26 };
27
28 //------------------------------------------------
29
30 33 context::
31 33 ~context()
32 {
33 33 }
34
35 33 context::
36 33 context()
37 33 : p_(new data)
38 {
39 33 }
40
41 //------------------------------------------------
42
43 auto
44 1077 context::
45 find_service_impl(
46 detail::type_index id) const noexcept ->
47 service*
48 {
49 1077 auto it = p_->services.find(id);
50
2/2
✓ Branch 3 taken 1045 times.
✓ Branch 4 taken 32 times.
1077 if(it != p_->services.end())
51 1045 return it->second.get();
52 32 return nullptr;
53 }
54
55 auto
56 32 context::
57 make_service_impl(
58 detail::type_index id,
59 std::unique_ptr<service> sp) ->
60 service&
61 {
62 auto const result =
63 32 p_->services.emplace(
64
1/2
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
32 id, std::move(sp));
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if(! result.second)
66 {
67 // already exists
68 detail::throw_out_of_range();
69 }
70 64 return *result.first->second;
71 }
72
73 } // http_proto
74 } // boost
75