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