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