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 | 78 | context:: | |
31 | ~context() | ||
32 | { | ||
33 | 78 | } | |
34 | |||
35 | 78 | context:: | |
36 | 78 | context() | |
37 | 78 | : p_(new data) | |
38 | { | ||
39 | 78 | } | |
40 | |||
41 | //------------------------------------------------ | ||
42 | |||
43 | auto | ||
44 | 1155 | context:: | |
45 | find_service_impl( | ||
46 | detail::type_index id) const noexcept -> | ||
47 | service* | ||
48 | { | ||
49 | 1155 | auto it = p_->services.find(id); | |
50 |
2/2✓ Branch 3 taken 1095 times.
✓ Branch 4 taken 60 times.
|
1155 | if(it != p_->services.end()) |
51 | 1095 | return it->second.get(); | |
52 | 60 | return nullptr; | |
53 | } | ||
54 | |||
55 | auto | ||
56 | 60 | context:: | |
57 | make_service_impl( | ||
58 | detail::type_index id, | ||
59 | std::unique_ptr<service> sp) -> | ||
60 | service& | ||
61 | { | ||
62 | auto const result = | ||
63 |
1/2✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
|
120 | p_->services.emplace( |
64 | 60 | id, std::move(sp)); | |
65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60 | if(! result.second) |
66 | { | ||
67 | // already exists | ||
68 | ✗ | detail::throw_out_of_range(); | |
69 | } | ||
70 | 120 | return *result.first->second; | |
71 | } | ||
72 | |||
73 | } // http_proto | ||
74 | } // boost | ||
75 |