GCC Code Coverage Report


Directory: libs/http_proto/include/boost/http_proto/
File: boost/http_proto/codec/impl/codecs.ipp
Date: 2023-01-09 16:11:13
Exec Total Coverage
Lines: 14 29 48.3%
Functions: 4 6 66.7%
Branches: 2 8 25.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot 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_CODEC_IMPL_CODECS_IPP
11 #define BOOST_HTTP_PROTO_CODEC_IMPL_CODECS_IPP
12
13 #include <boost/http_proto/codec/codecs.hpp>
14 #include <boost/http_proto/context.hpp>
15 #include <boost/http_proto/detail/except.hpp>
16 #include <boost/url/grammar/ci_string.hpp>
17 #include <boost/container/map.hpp>
18 //#include <boost/unordered_map.hpp> // doesn't support heterogenous lookup yet
19 #include <string>
20
21 namespace boost {
22 namespace http_proto {
23
24 codecs::
25 ~codecs() noexcept = default;
26
27 namespace detail {
28
29 class codecs_impl
30 : public codecs
31 , public service
32 {
33 boost::container::map<
34 std::string,
35 decoder_type*,
36 grammar::ci_less
37 > decoders_;
38
39 boost::container::map<
40 std::string,
41 encoder_type*,
42 grammar::ci_less
43 > encoders_;
44 public:
45 using key_type = codecs;
46
47 explicit
48 5 codecs_impl(
49 context&) noexcept
50 10 {
51 5 }
52
53 void
54 2 add_decoder(
55 string_view name,
56 decoder_type& dt) override
57 {
58 auto const result =
59 2 decoders_.emplace(name, &dt);
60
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(result.second)
61 2 return;
62 detail::throw_out_of_range(
63 BOOST_CURRENT_LOCATION);
64 }
65
66 decoder_type*
67 1 find_decoder(
68 string_view name) noexcept override
69 {
70 auto const result =
71 1 decoders_.find(name);
72 1 if(result !=
73
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 decoders_.end())
74 1 return result->second;
75 return nullptr;
76 }
77
78 void
79 add_encoder(
80 string_view name,
81 encoder_type& dt) override
82 {
83 auto const result =
84 encoders_.emplace(name, &dt);
85 if(result.second)
86 return;
87 detail::throw_out_of_range(
88 BOOST_CURRENT_LOCATION);
89 }
90
91 encoder_type*
92 find_encoder(
93 string_view name) noexcept override
94 {
95 auto const result =
96 encoders_.find(name);
97 if(result !=
98 encoders_.end())
99 return result->second;
100 return nullptr;
101 }
102 };
103
104 codecs&
105 5 install_codecs_service(
106 context& ctx)
107 {
108 5 return ctx.make_service<codecs_impl>();
109 }
110
111 } // detail
112
113 } // http_proto
114 } // boost
115
116 #endif
117