LCOV - code coverage report
Current view: top level - http_proto/impl - context.ipp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 17 18 94.4 %
Date: 2023-02-27 20:43:06 Functions: 4 4 100.0 %

          Line data    Source code
       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             : struct context::data
      22             : {
      23             :     // Installed services
      24             :     std::unordered_map<
      25             :         detail::type_index,
      26             :         std::unique_ptr<service>
      27             :             > services;
      28             : };
      29             : 
      30             : //------------------------------------------------
      31             : 
      32           8 : context::
      33           8 : ~context()
      34             : {
      35           8 : }
      36             : 
      37           8 : context::
      38           8 : context()
      39           8 :     : p_(new data)
      40             : {
      41           8 : }
      42             : 
      43             : //------------------------------------------------
      44             : 
      45             : auto
      46        6653 : context::
      47             : find_service_impl(
      48             :     detail::type_index id) const noexcept ->
      49             :         service*
      50             : {
      51        6653 :     auto it = p_->services.find(id);
      52        6653 :     if(it != p_->services.end())
      53        6646 :         return it->second.get();
      54           7 :     return nullptr;
      55             : }
      56             : 
      57             : auto
      58           7 : context::
      59             : make_service_impl(
      60             :     detail::type_index id,
      61             :     std::unique_ptr<service> sp) ->
      62             :         service&    
      63             : {
      64             :     auto const result =
      65           7 :         p_->services.emplace(
      66           7 :             id, std::move(sp));
      67           7 :     if(! result.second)
      68             :     {
      69             :         // already exists
      70           0 :         detail::throw_out_of_range();
      71             :     }
      72          14 :     return *result.first->second;
      73             : }
      74             : 
      75             : } // http_proto
      76             : } // boost
      77             : 
      78             : #endif

Generated by: LCOV version 1.15