LCOV - code coverage report
Current view: top level - libs/http_proto/src - context.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 17 18 94.4 %
Date: 2024-03-22 16:56:24 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             : #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          33 : context::
      31          33 : ~context()
      32             : {
      33          33 : }
      34             : 
      35          33 : context::
      36          33 : context()
      37          33 :     : p_(new data)
      38             : {
      39          33 : }
      40             : 
      41             : //------------------------------------------------
      42             : 
      43             : auto
      44        1077 : context::
      45             : find_service_impl(
      46             :     detail::type_index id) const noexcept ->
      47             :         service*
      48             : {
      49        1077 :     auto it = p_->services.find(id);
      50        1077 :     if(it != p_->services.end())
      51        1045 :         return it->second.get();
      52          32 :     return nullptr;
      53             : }
      54             : 
      55             : auto
      56          32 : context::
      57             : make_service_impl(
      58             :     detail::type_index id,
      59             :     std::unique_ptr<service> sp) ->
      60             :         service&
      61             : {
      62             :     auto const result =
      63          32 :         p_->services.emplace(
      64          32 :             id, std::move(sp));
      65          32 :     if(! result.second)
      66             :     {
      67             :         // already exists
      68           0 :         detail::throw_out_of_range();
      69             :     }
      70          64 :     return *result.first->second;
      71             : }
      72             : 
      73             : } // http_proto
      74             : } // boost

Generated by: LCOV version 1.15