GCC Code Coverage Report


Directory: libs/http_proto/include/boost/http_proto/
File: boost/http_proto/context.hpp
Date: 2023-01-09 16:11:13
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 1 1 100.0%
Branches: 0 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_CONTEXT_HPP
11 #define BOOST_HTTP_PROTO_CONTEXT_HPP
12
13 #include <boost/http_proto/detail/config.hpp>
14 #include <boost/http_proto/string_view.hpp>
15 #include <boost/http_proto/service/service.hpp>
16 #include <boost/http_proto/detail/type_index.hpp>
17 #include <memory>
18
19 namespace boost {
20 namespace http_proto {
21
22 #ifndef BOOST_HTTP_PROTO_DOCS
23 class codecs;
24 #endif
25
26 class context
27 {
28 struct data;
29
30 http_proto::codecs* codecs_;
31
32 public:
33 context(context const&) = delete;
34 context& operator=(
35 context const&) = delete;
36
37 BOOST_HTTP_PROTO_DECL
38 ~context();
39
40 BOOST_HTTP_PROTO_DECL
41 context() noexcept;
42
43 http_proto::codecs&
44 3 codecs() noexcept
45 {
46 3 return *codecs_;
47 }
48
49 //--------------------------------------------
50
51 /** Create a service.
52
53 The service must not already exist.
54
55 @par Exception Safety
56 Strong guarantee.
57 Calls to allocate may throw.
58
59 @throw std::invalid_argument `find_service<T> != nullptr`
60
61 @return A reference to the new service.
62
63 @tparam T The service type.
64
65 @param args Arguments forwarded to the
66 service constructor.
67 */
68 template<
69 class T,
70 class... Args>
71 T&
72 make_service(
73 Args&&... args);
74
75 /** Return an existing service
76
77 The function returns `nullptr` if the
78 service does not exist.
79
80 @par Complexity
81 Constant.
82
83 @par Exception Safety
84 Throws nothing.
85
86 @return A pointer to the service,
87 or `nullptr`.
88
89 @tparam T The service type.
90 */
91 template<class T>
92 T*
93 find_service() const noexcept;
94
95 /** Return true if a service exists
96
97 @par Effects
98 @code
99 return this->find_service<T>() != nullptr;
100 @endcode
101
102 @par Complexity
103 Constant.
104
105 @par Exception Safety
106 Throws nothing.
107
108 @return `true` if the service exists.
109
110 @tparam T The service type.
111 */
112 template<class T>
113 bool
114 has_service() const noexcept;
115
116 /** Return a reference to an existing service
117
118 The service must exist, or else an
119 exception is thrown.
120
121 @par Complexity
122 Constant.
123
124 @par Exception Safety
125 Strong guarantee.
126
127 @throw std::invalid_argument `find_service<T> == nullptr`.
128
129 @return A reference to the service.
130
131 @tparam T The service type.
132 */
133 template<class T>
134 T&
135 get_service() const;
136
137 private:
138 BOOST_HTTP_PROTO_DECL
139 service*
140 find_service_impl(
141 detail::type_index ti) noexcept;
142
143 BOOST_HTTP_PROTO_DECL
144 service&
145 make_service_impl(
146 detail::type_index ti,
147 std::unique_ptr<service> sp);
148
149 std::unique_ptr<data> p_;
150 };
151
152 } // http_proto
153 } // boost
154
155 #include <boost/http_proto/impl/context.hpp>
156
157 #endif
158