RESTinio
Loading...
Searching...
No Matches
growable_size.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
12#pragma once
13
15
16#include <vector>
17
19{
20
21//
22// growable_size_chain_t
23//
179template< typename Extra_Data_Factory = no_extra_data_factory_t >
181{
182 // Helper class to allow the creation of growable_size_chain_t only
183 // for the friends of growable_size_chain_t.
185
188
191
193 using schedulers_vector_t = std::vector< scheduler_holder_t >;
194
198
202
210 : public async_handling_controller_t< Extra_Data_Factory >
211 {
217
222 std::size_t m_current{};
223
224 public:
232
233 [[nodiscard]]
235 request_handle() const noexcept override { return m_request; }
236
237 private:
238 [[nodiscard]]
240 on_next() override
241 {
242 const auto index_to_use = m_current;
243 ++m_current;
244
245 if( index_to_use >= m_schedulers.size() )
246 {
247 return { no_more_schedulers_t{} };
248 }
249 else
250 {
251 return { m_schedulers[ index_to_use ] };
252 }
253 }
254 };
255
256public:
257 friend class builder_t;
258
276 {
277 public:
281
289 [[nodiscard]]
290 std::unique_ptr< growable_size_chain_t >
292 {
293 return { std::move(m_chain) };
294 }
295
299 template< typename Scheduler >
300 void
302 {
303 if( !m_chain )
304 throw exception_t{ "an attempt to add a scheduler to "
305 "a growable-size-chain builder that already "
306 "released"
307 };
308 m_chain->m_schedulers.push_back(
310 std::forward<Scheduler>(scheduler)
311 } );
312 }
313
314 private:
315 std::unique_ptr< growable_size_chain_t > m_chain;
316 };
317
318private:
321
329
330public:
337
344 [[nodiscard]]
347 {
349 std::make_unique< actual_controller_t >(
350 req,
351 m_schedulers );
352 next( std::move(controller) );
353
354 return request_accepted();
355 }
356};
357
358} /* namespace restinio::async_chain */
359
Interface of a controller of an async chan.
Definition common.hpp:146
generic_request_handle_t< typename Extra_Data_Factory::data_t > actual_request_handle_t
Short alias for request_handle type.
Definition common.hpp:154
on_next_result_t< Extra_Data_Factory > actual_on_next_result_t
Short alias for the result type of on_next method.
Definition common.hpp:162
Actual implementation of the controller interface.
actual_on_next_result_t on_next() override
Command to try find a next scheduler to be invoked.
std::size_t m_current
Index of the current scheduler to be used.
const actual_request_handle_t & request_handle() const noexcept override
Get reference to the source request.
actual_controller_t(actual_request_handle_t request, const schedulers_vector_t &schedulers)
Initializing constructor.
const actual_request_handle_t m_request
The source request.
A builder of an instance of growable_size_chain.
std::unique_ptr< growable_size_chain_t > release() noexcept
Stop adding of new schedulers and acquire the chain instance.
std::unique_ptr< growable_size_chain_t > m_chain
void add(Scheduler &&scheduler)
Add a new scheduler to the chain.
A holder of variable-size chain of asynchronous handlers.
typename async_handling_controller_t< Extra_Data_Factory >::actual_request_handle_t actual_request_handle_t
Short alias to a smart pointer to the source request.
unique_async_handling_controller_t< Extra_Data_Factory > unique_controller_t
Short alias for a handling controller.
typename async_handling_controller_t< Extra_Data_Factory >::actual_on_next_result_t actual_on_next_result_t
Short alias for the result of controller's on_next method.
generic_async_request_scheduler_t< Extra_Data_Factory > scheduler_holder_t
Short alias for a scheduler.
schedulers_vector_t m_schedulers
The vector of schedulers.
request_handling_status_t operator()(const actual_request_handle_t &req) const
growable_size_chain_t(creation_token_t)
The main constructor.
std::vector< scheduler_holder_t > schedulers_vector_t
Short alias for a vector of schedulers.
Exception class for all exceptions thrown by RESTinio.
Definition exception.hpp:26
Common stuff for different types of async handlers chains.
std::function< schedule_result_t(unique_async_handling_controller_t< Extra_Data_Factory >) > generic_async_request_scheduler_t
Short alias for a type of a scheduler to be used in async chains.
Definition common.hpp:93
void next(unique_async_handling_controller_t< Extra_Data_Factory > controller)
Command to try to switch to the next handler in an async chain.
Definition common.hpp:327
std::unique_ptr< async_handling_controller_t< Extra_Data_Factory > > unique_async_handling_controller_t
Short alias for unique_ptr to async_handling_controller.
Definition common.hpp:84
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_accepted() noexcept
request_handling_status_t
Request handling status.
Special type to be used as an indicator that there are no more schedulers in an async chain.
Definition common.hpp:106