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