RESTinio
Loading...
Searching...
No Matches
fixed_size.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
12#pragma once
13
15
16#include <array>
17
18namespace restinio
19{
20
21namespace sync_chain
22{
23
24//
25// fixed_size_chain_t
26//
160template<
161 std::size_t Size,
164{
167
168 using handler_holder_t = std::function<
170 >;
171
172 std::array< handler_holder_t, Size > m_handlers;
173
174 template<
175 typename Head,
176 typename... Tail >
177 void
178 store_to( std::size_t index, Head && head, Tail && ...tail )
179 {
180 m_handlers[ index ] =
181 [handler = std::move(head)]
183 {
184 return handler( req );
185 };
186
187 if constexpr( 0u != sizeof...(tail) )
188 store_to( index + 1u, std::forward<Tail>(tail)... );
189 }
190
191public:
199
207 template< typename... Handlers >
209 {
210 static_assert( Size == sizeof...(handlers),
211 "Wrong number of parameters for the constructor of "
212 "fixed_size_chain_t<Size>. Exact `Size` parameters expected" );
213
214 store_to( 0u, std::forward<Handlers>(handlers)... );
215 }
216
217 [[nodiscard]]
220 {
221 for( auto & h : m_handlers )
222 {
224
225 switch( result )
226 {
229 // There is no need to try next handler.
230 return result;
231
233 // Nothing to do. The next handler should be tried.
234 break;
235 }
236 }
237
238 return request_not_handled();
239 }
240};
241
242} /* namespace sync_chain */
243
244} /* namespace restinio */
245
A holder of fixed-size chain of synchronous handlers.
std::array< handler_holder_t, Size > m_handlers
void store_to(std::size_t index, Head &&head, Tail &&...tail)
fixed_size_chain_t(Handlers &&...handlers)
Initializing constructor.
generic_request_handle_t< typename Extra_Data_Factory::data_t > actual_request_handle_t
std::function< request_handling_status_t(const actual_request_handle_t &) > handler_holder_t
request_handling_status_t operator()(const actual_request_handle_t &req) const
std::shared_ptr< generic_request_t< Extra_Data > > generic_request_handle_t
An alias for shared-pointer to incoming request.
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.
constexpr request_handling_status_t request_not_handled() noexcept
request_handling_status_t
Request handling status.
@ accepted
Request accepted for handling.
@ not_handled
The request wasn't handled. If there is another handler to be tried it should be tried....
@ rejected
Request wasn't accepted for handling.
The default extra-data-factory to be used in server's traits if a user doesn't specify own one.