RESTinio
easy_parser_router.hpp
Go to the documentation of this file.
1 /*
2  * RESTinio
3  */
4 
12 #pragma once
13 
17 
19 
20 #include <vector>
21 
22 namespace restinio
23 {
24 
25 namespace router
26 {
27 
28 namespace easy_parser_router
29 {
30 
31 namespace impl
32 {
33 
35 namespace ep = restinio::easy_parser;
36 
38 
44 struct no_match_t {};
45 
52 {
53 public:
54  virtual ~router_entry_t() = default;
55 
57 
67  const request_handle_t & req,
68  target_path_holder_t & target_path ) const = 0;
69 };
70 
76 using router_entry_unique_ptr_t = std::unique_ptr< router_entry_t >;
77 
78 //
79 // actual_router_entry_t
80 //
91 template< typename Producer, typename Handler >
93 {
96 
98  Producer m_producer;
99 
101  Handler m_handler;
102 
103 public:
104  template<
105  typename Method_Matcher,
106  typename Producer_Arg,
107  typename Handler_Arg >
109  Method_Matcher && method_matcher,
110  Producer_Arg && producer,
111  Handler_Arg && handler )
112  : m_producer{ std::forward<Producer_Arg>(producer) }
113  , m_handler{ std::forward<Handler_Arg>(handler) }
114  {
115  assign( m_method_matcher, std::forward<Method_Matcher>(method_matcher) );
116  }
117 
121  const request_handle_t & req,
122  target_path_holder_t & target_path ) const override
123  {
124  if( m_method_matcher->match( req->header().method() ) )
125  {
126  auto parse_result = easy_parser::try_parse(
127  target_path.view(),
128  m_producer );
129  if( parse_result )
130  {
131  return Producer::invoke_handler( req, m_handler, *parse_result );
132  }
133  }
134 
135  return make_unexpected( no_match_t{} );
136  }
137 };
138 
139 //
140 // unescape_transformer_t
141 //
148 template< typename Unescape_Traits >
150  : public restinio::easy_parser::impl::transformer_tag< std::string >
151 {
152  using input_type = std::string;
153 
156  transform( input_type && input ) const
157  {
158  return restinio::utils::unescape_percent_encoding< Unescape_Traits >(
159  input );
160  }
161 };
162 
163 //
164 // special_produce_tuple_item_clause_t
165 //
172 template< typename Producer, std::size_t Index >
174  : public ep::impl::consume_value_clause_t<
175  Producer,
176  ep::impl::tuple_item_consumer_t<Index> >
177 {
178  using consumer_t = ep::impl::tuple_item_consumer_t<Index>;
179 
180  using base_type_t = ep::impl::consume_value_clause_t<
181  Producer,
182  consumer_t >;
183 
184  // NOTE: this is just a workaround for VS2017.
185  template< typename Producer_Arg >
187  static Producer
188  make_producer( Producer_Arg && producer )
189  {
190  return { std::forward<Producer_Arg>(producer) };
191  }
192 
193 public:
194  template< typename Producer_Arg >
195  special_produce_tuple_item_clause_t( Producer_Arg && producer )
196  : base_type_t{
197  make_producer( std::forward<Producer_Arg>(producer) ),
198  consumer_t{} }
199  {}
200 };
201 
202 //
203 // special_exact_fixed_size_fragment_clause_t
204 //
215 template< std::size_t Size >
217  : public ep::impl::consume_value_clause_t<
218  ep::impl::exact_fixed_size_fragment_producer_t<Size>,
219  ep::impl::any_value_skipper_t >
220 {
221  using producer_t = ep::impl::exact_fixed_size_fragment_producer_t<Size>;
222  using consumer_t = ep::impl::any_value_skipper_t;
223 
224  using base_type_t = ep::impl::consume_value_clause_t<
225  producer_t,
226  consumer_t >;
227 
228 public:
230  const char (&fragment)[Size] )
231  : base_type_t{ producer_t{ fragment }, consumer_t{} }
232  {}
233 };
234 
235 //
236 // special_exact_fragment_clause_t
237 //
249  : public ep::impl::consume_value_clause_t<
250  ep::impl::exact_fragment_producer_t,
251  ep::impl::any_value_skipper_t >
252 {
253  using producer_t = ep::impl::exact_fragment_producer_t;
254  using consumer_t = ep::impl::any_value_skipper_t;
255 
256  using base_type_t = ep::impl::consume_value_clause_t<
257  producer_t,
258  consumer_t >;
259 
260 public:
261  special_exact_fragment_clause_t( std::string value )
262  : base_type_t{ producer_t{ std::move(value) }, consumer_t{} }
263  {}
264 
266  : base_type_t{
267  producer_t{ std::string{ value.data(), value.size() } },
268  consumer_t{} }
269  {}
270 };
271 
272 namespace dsl_details
273 {
274 
275 // Adds type H to type list R if Is_Producer is true.
276 template< typename H, typename R, bool Is_Producer >
278 
279 template<
280  typename H,
281  template<class...> class To,
282  typename... Results >
283 struct add_type_if_necessary_impl< H, To<Results...>, false >
284 {
285  using type = To<Results...>;
286 };
287 
288 template<
289  typename H,
290  template<class...> class To,
291  typename... Results >
292 struct add_type_if_necessary_impl< H, To<Results...>, true >
293 {
294  using type = To<Results..., typename H::result_type>;
295 };
296 
297 // Adds type H to type list R if H is a producer.
298 template< typename H, typename R >
300  : add_type_if_necessary_impl< H, R, ep::impl::is_producer_v<H> >
301 {};
302 
303 // Produces a type-list of producers from type-list From.
304 template< typename From, typename To >
306 
307 // Adds a type from Sources to Results only if this type is a producer.
308 template<
309  template<class...> class From,
310  typename... Sources,
311  template<class...> class To,
312  typename... Results >
313 struct result_tuple_detector< From<Sources...>, To<Results...> >
314 {
315  using type = typename result_tuple_detector<
316  meta::tail_of_t< Sources... >,
317  typename add_type_if_necessary<
318  meta::head_of_t< Sources... >,
319  To< Results... > >::type
320  >::type;
321 };
322 
323 template<
324  template<class...> class From,
325  template<class...> class To,
326  typename... Results >
327 struct result_tuple_detector< From<>, To<Results...> >
328 {
329  using type = To<Results...>;
330 };
331 
332 // Produces a type of std::tuple of producers from type-list Args_Type_List.
333 template< typename Args_Type_List >
335 {
337  typename result_tuple_detector<
338  Args_Type_List,
340  std::tuple >;
341 };
342 
343 template< typename Args_Type_List >
345 
346 // Detects an appropriate type of clause for T.
347 // If T is a producer then there will be a new clause that
348 // consumes a value T produces.
349 // In that case Current_Index will also be incremented.
350 //
351 // If T is not a producer then Current_Index will be kept.
352 //
353 // If T is a string literal, or std::string, or string_view
354 // then T will be replaced by a special clause.
355 template< typename T, bool Is_Producer, std::size_t Current_Index >
357 {
358  using clause_type = T;
359  static constexpr std::size_t next_index = Current_Index;
360 };
361 
362 template< std::size_t Size, std::size_t Current_Index >
363 struct one_clause_type_processor<const char[Size], false, Current_Index>
364 {
366  static constexpr std::size_t next_index = Current_Index;
367 };
368 
369 template< std::size_t Current_Index >
370 struct one_clause_type_processor<std::string, false, Current_Index>
371 {
373  static constexpr std::size_t next_index = Current_Index;
374 };
375 
376 template< std::size_t Current_Index >
377 struct one_clause_type_processor<string_view_t, false, Current_Index>
378 {
380  static constexpr std::size_t next_index = Current_Index;
381 };
382 
383 template< typename T, std::size_t Current_Index >
384 struct one_clause_type_processor<T, true, Current_Index>
385 {
387  static constexpr std::size_t next_index = Current_Index + 1u;
388 };
389 
390 // Takes a type-list of user-specified types From and produces a
391 // typelist of actual clauses types To.
392 //
393 // The Current_Index should 0 at the first invocation.
394 template< typename From, typename To, std::size_t Current_Index >
396 
397 template<
398  template<class...> class From,
399  typename... Sources,
400  template<class...> class To,
401  typename... Results,
402  std::size_t Current_Index >
403 struct clauses_type_maker< From<Sources...>, To<Results...>, Current_Index >
404 {
405 private:
406  using head_type = meta::head_of_t< Sources... >;
407 
409  head_type,
410  ep::impl::is_producer_v<head_type>,
411  Current_Index >;
412 
413 public:
414  using type = typename clauses_type_maker<
415  meta::tail_of_t< Sources... >,
416  To< Results..., typename one_clause_type::clause_type >,
417  one_clause_type::next_index >::type;
418 };
419 
420 template<
421  template<class...> class From,
422  template<class...> class To,
423  typename... Results,
424  std::size_t Current_Index >
425 struct clauses_type_maker< From<>, To<Results...>, Current_Index >
426 {
427  using type = To< Results... >;
428 };
429 
430 // Takes a type-list of user-specified types Args_Type_List and produces a
431 // typelist of actual clauses types to be used for parsing.
432 template< typename Args_Type_List >
434 {
436  typename clauses_type_maker<
437  Args_Type_List,
439  0u >::type,
440  std::tuple >;
441 };
442 
443 template< typename Args_Type_List >
445 
446 //
447 // special_decay
448 //
463 template< typename T >
465 {
466 private:
467  using U = std::remove_reference_t<T>;
468 
469 public:
470  using type = typename std::conditional<
471  std::is_array<U>::value,
472  U,
473  std::remove_cv_t<U>
474  >::type;
475 };
476 
477 } /* namespace dsl_details */
478 
479 //
480 // dsl_processor
481 //
495 template< typename... Args >
497 {
498  static_assert( 0u != sizeof...(Args), "Args can't be an empty list" );
499 
502 
504 
506 };
507 
508 //
509 // path_to_tuple_producer_t
510 //
519 template<
520  typename Target_Type,
521  typename Subitems_Tuple >
523  : public ep::impl::produce_t< Target_Type, Subitems_Tuple >
524 {
525  using base_type_t = ep::impl::produce_t< Target_Type, Subitems_Tuple >;
526 
527 public:
528  using base_type_t::base_type_t;
529 
530  template< typename Handler >
532  static auto
534  const request_handle_t & req,
535  Handler && handler,
536  typename base_type_t::result_type & type )
537  {
538  return handler( req, type );
539  }
540 };
541 
542 namespace path_to_params_details
543 {
544 
545 template<
546  typename F,
547  typename Tuple,
548  std::size_t... Indexes >
549 decltype(auto)
551  F && what,
552  const request_handle_t & req,
553  Tuple && params,
554  std::index_sequence<Indexes...> )
555 {
556  return std::forward<F>(what)(
557  req,
558  std::get<Indexes>(std::forward<Tuple>(params))... );
559 }
560 
561 //
562 // call_with_tuple
563 //
571 template< typename F, typename Tuple >
572 decltype(auto)
574  F && what,
575  const request_handle_t & req,
576  Tuple && params )
577 {
578  return call_with_tuple_impl(
579  std::forward<F>(what),
580  req,
581  std::forward<Tuple>(params),
582  std::make_index_sequence<
583  std::tuple_size< std::remove_reference_t<Tuple> >::value
584  >{} );
585 }
586 
587 } /* namespace path_to_params_details */
588 
589 //
590 // path_to_params_producer_t
591 //
601 template<
602  typename Target_Type,
603  typename Subitems_Tuple >
605  : public ep::impl::produce_t< Target_Type, Subitems_Tuple >
606 {
607  using base_type_t = ep::impl::produce_t< Target_Type, Subitems_Tuple >;
608 
609 public:
610  using base_type_t::base_type_t;
611 
612  template< typename Handler >
614  static auto
616  const request_handle_t & req,
617  Handler && handler,
618  typename base_type_t::result_type & type )
619  {
620  return path_to_params_details::call_with_tuple( handler, req, type );
621  }
622 };
623 
624 } /* namespace impl */
625 
626 using namespace restinio::easy_parser;
627 
628 //
629 // path_to_tuple
630 //
670 template< typename... Args >
672 auto
673 path_to_tuple( Args && ...args )
674 {
675  using dsl_processor = impl::dsl_processor< Args... >;
676  using result_tuple_type = typename dsl_processor::result_tuple;
677  using subclauses_tuple_type = typename dsl_processor::clauses_tuple;
678 
679  using producer_type = impl::path_to_tuple_producer_t<
680  result_tuple_type,
681  subclauses_tuple_type >;
682 
683  return producer_type{
684  subclauses_tuple_type{ std::forward<Args>(args)... }
685  };
686 }
687 
688 //
689 // path_to_params
690 //
724 template< typename... Args >
726 auto
727 path_to_params( Args && ...args )
728 {
729  using dsl_processor = impl::dsl_processor< Args... >;
730  using result_tuple_type = typename dsl_processor::result_tuple;
731  using subclauses_tuple_type = typename dsl_processor::clauses_tuple;
732 
733  using producer_type = impl::path_to_params_producer_t<
734  result_tuple_type,
735  subclauses_tuple_type >;
736 
737  return producer_type{
738  subclauses_tuple_type{ std::forward<Args>(args)... }
739  };
740 }
741 
783 inline auto
784 path_fragment_p( char separator = '/' )
785 {
786  return produce< std::string >(
787  repeat( 1, N,
788  any_symbol_if_not_p( separator ) >> to_container() ) );
789 }
790 
837 template< typename Unescape_Traits =
840 auto
842 {
844 }
845 
846 } /* namespace easy_parser_router */
847 
848 //
849 // easy_parser_router_t
850 //
908 {
909 public:
910  easy_parser_router_t() = default;
911 
914  operator=( const easy_parser_router_t & ) = delete;
915 
919 
923  {
924  using namespace easy_parser_router::impl;
925 
926  // Take care of an optional trailing slash.
927  string_view_t path_to_inspect{ req->header().path() };
928  if( path_to_inspect.size() > 1u && '/' == path_to_inspect.back() )
929  path_to_inspect.remove_suffix( 1u );
930 
931  target_path_holder_t target_path{ path_to_inspect };
932  for( const auto & entry : m_entries )
933  {
934  const auto r = entry->try_handle( req, target_path );
935  if( r )
936  {
937  return *r;
938  }
939  }
940 
941  // Here: none of the routes matches this handler.
942  if( m_non_matched_request_handler )
943  {
944  // If non matched request handler is set
945  // then call it.
946  return m_non_matched_request_handler( std::move( req ) );
947  }
948 
949  return request_rejected();
950  }
951 
952  template<
953  typename Method_Matcher,
954  typename Route_Producer,
955  typename Handler >
956  void
958  Method_Matcher && method_matcher,
959  Route_Producer && route,
960  Handler && handler )
961  {
962  using namespace easy_parser_router::impl;
963 
964  using producer_type = std::decay_t< Route_Producer >;
965  using handler_type = std::decay_t< Handler >;
966 
967  using actual_entry_type = actual_router_entry_t<
968  producer_type, handler_type >;
969 
970  auto entry = std::make_unique< actual_entry_type >(
971  std::forward<Method_Matcher>(method_matcher),
972  std::forward<Route_Producer>(route),
973  std::forward<Handler>(handler) );
974 
975  m_entries.push_back( std::move(entry) );
976  }
977 
979  template< typename Route_Producer, typename Handler >
980  void
982  Route_Producer && route,
983  Handler && handler )
984  {
985  this->add_handler(
986  http_method_get(),
987  std::forward<Route_Producer>(route),
988  std::forward<Handler>(handler) );
989  }
990 
992  template< typename Route_Producer, typename Handler >
993  void
995  Route_Producer && route,
996  Handler && handler )
997  {
998  this->add_handler(
999  http_method_delete(),
1000  std::forward<Route_Producer>(route),
1001  std::forward<Handler>(handler) );
1002  }
1003 
1005  template< typename Route_Producer, typename Handler >
1006  void
1008  Route_Producer && route,
1009  Handler && handler )
1010  {
1011  this->add_handler(
1012  http_method_head(),
1013  std::forward<Route_Producer>(route),
1014  std::forward<Handler>(handler) );
1015  }
1016 
1018  template< typename Route_Producer, typename Handler >
1019  void
1021  Route_Producer && route,
1022  Handler && handler )
1023  {
1024  this->add_handler(
1025  http_method_post(),
1026  std::forward<Route_Producer>(route),
1027  std::forward<Handler>(handler) );
1028  }
1029 
1031  template< typename Route_Producer, typename Handler >
1032  void
1034  Route_Producer && route,
1035  Handler && handler )
1036  {
1037  this->add_handler(
1038  http_method_put(),
1039  std::forward<Route_Producer>(route),
1040  std::forward<Handler>(handler) );
1041  }
1042 
1044  void
1046  {
1047  m_non_matched_request_handler= std::move( nmrh );
1048  }
1049 
1050 private:
1052  std::vector< easy_parser_router::impl::router_entry_unique_ptr_t >;
1053 
1055 
1058 };
1059 
1060 } /* namespace router */
1061 
1062 } /* namespace restinio */
1063 
restinio::router::easy_parser_router::path_to_tuple
RESTINIO_NODISCARD auto path_to_tuple(Args &&...args)
Describe a route for a handler that accepts params from the route in form of a tuple.
Definition: easy_parser_router.hpp:673
restinio::utils::metaprogramming::type_list
The basic building block: a type for representation of a type list.
Definition: metaprogramming.hpp:54
restinio::router::easy_parser_router::impl::dsl_details::make_clauses_types_t
typename make_clauses_types< Args_Type_List >::type make_clauses_types_t
Definition: easy_parser_router.hpp:444
restinio::router::easy_parser_router::impl::path_to_params_producer_t::base_type_t
ep::impl::produce_t< Target_Type, Subitems_Tuple > base_type_t
Definition: easy_parser_router.hpp:607
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
restinio::router::easy_parser_router::impl::dsl_processor::result_tuple
dsl_details::detect_result_tuple_t< arg_types > result_tuple
Definition: easy_parser_router.hpp:503
restinio::router::impl::buffered_matcher_holder_t
A special class that allows to hold a copy of small-size method_matchers or a pointer to dynamically ...
Definition: method_matcher.hpp:225
restinio::utils::metaprogramming::rename_t
typename impl::rename< From, To >::type rename_t
Allows to pass all template arguments from one type to another.
Definition: metaprogramming.hpp:203
restinio::router::easy_parser_router_t::non_matched_request_handler
void non_matched_request_handler(non_matched_request_handler_t nmrh)
Set handler for requests that don't match any route.
Definition: easy_parser_router.hpp:1045
restinio::router::easy_parser_router_t::http_get
void http_get(Route_Producer &&route, Handler &&handler)
Set handler for HTTP GET request.
Definition: easy_parser_router.hpp:981
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t::special_exact_fragment_clause_t
special_exact_fragment_clause_t(std::string value)
Definition: easy_parser_router.hpp:261
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:421
restinio::router::easy_parser_router::impl::special_produce_tuple_item_clause_t::make_producer
static RESTINIO_NODISCARD Producer make_producer(Producer_Arg &&producer)
Definition: easy_parser_router.hpp:188
restinio::router::easy_parser_router::impl::dsl_details::special_decay::type
typename std::conditional< std::is_array< U >::value, U, std::remove_cv_t< U > >::type type
Definition: easy_parser_router.hpp:474
restinio::easy_parser::impl::transformer_tag< std::string >::result_type
std::string result_type
Definition: easy_parser.hpp:1000
restinio::router::easy_parser_router_t::entries_container_t
std::vector< easy_parser_router::impl::router_entry_unique_ptr_t > entries_container_t
Definition: easy_parser_router.hpp:1052
restinio::router::easy_parser_router::impl::actual_router_entry_t::m_method_matcher
restinio::router::impl::buffered_matcher_holder_t m_method_matcher
HTTP method to match.
Definition: easy_parser_router.hpp:95
restinio::utils::metaprogramming::transform_t
typename impl::transform< Transform_F, From, type_list<> >::type transform_t
Applies a specified meta-function to every item from a specified type-list and return a new type-list...
Definition: metaprogramming.hpp:263
restinio::router::easy_parser_router_t::http_delete
void http_delete(Route_Producer &&route, Handler &&handler)
Set handler for HTTP DELETE request.
Definition: easy_parser_router.hpp:994
restinio::router::easy_parser_router_t::add_handler
void add_handler(Method_Matcher &&method_matcher, Route_Producer &&route, Handler &&handler)
Definition: easy_parser_router.hpp:957
restinio::router::easy_parser_router::impl::actual_router_entry_t::try_handle
RESTINIO_NODISCARD expected_t< request_handling_status_t, no_match_t > try_handle(const request_handle_t &req, target_path_holder_t &target_path) const override
An attempt to match a request against the route.
Definition: easy_parser_router.hpp:120
restinio::router::easy_parser_router::impl::path_to_tuple_producer_t::base_type_t
ep::impl::produce_t< Target_Type, Subitems_Tuple > base_type_t
Definition: easy_parser_router.hpp:525
restinio::easy_parser::N
constexpr std::size_t N
A special marker that means infinite repetitions.
Definition: easy_parser.hpp:455
restinio::router::easy_parser_router_t::http_head
void http_head(Route_Producer &&route, Handler &&handler)
Set handler for HTTP HEAD request.
Definition: easy_parser_router.hpp:1007
restinio::router::easy_parser_router_t::easy_parser_router_t
easy_parser_router_t(easy_parser_router_t &&)=default
restinio::router::easy_parser_router::impl::dsl_details::special_decay::U
std::remove_reference_t< T > U
Definition: easy_parser_router.hpp:467
restinio::router::easy_parser_router::path_fragment_p
RESTINIO_NODISCARD auto path_fragment_p(char separator='/')
A factory that creates a string-producer that extracts a sequence on symbols until the separator will...
Definition: easy_parser_router.hpp:784
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
restinio::router::easy_parser_router::impl::special_exact_fixed_size_fragment_clause_t::special_exact_fixed_size_fragment_clause_t
special_exact_fixed_size_fragment_clause_t(const char(&fragment)[Size])
Definition: easy_parser_router.hpp:229
restinio::router::easy_parser_router::impl::dsl_details::result_tuple_detector
Definition: easy_parser_router.hpp:305
restinio::router::easy_parser_router_t::http_put
void http_put(Route_Producer &&route, Handler &&handler)
Set handler for HTTP PUT request.
Definition: easy_parser_router.hpp:1033
restinio::router::easy_parser_router_t::easy_parser_router_t
easy_parser_router_t(const easy_parser_router_t &)=delete
restinio::utils::metaprogramming
Definition: metaprogramming.hpp:24
restinio::router::easy_parser_router_t::operator=
easy_parser_router_t & operator=(const easy_parser_router_t &)=delete
restinio::router::easy_parser_router::impl::dsl_details::add_type_if_necessary_impl< H, To< Results... >, false >::type
To< Results... > type
Definition: easy_parser_router.hpp:285
restinio::router::easy_parser_router::impl::dsl_details::result_tuple_detector< From< Sources... >, To< Results... > >::type
typename result_tuple_detector< meta::tail_of_t< Sources... >, typename add_type_if_necessary< meta::head_of_t< Sources... >, To< Results... > >::type >::type type
Definition: easy_parser_router.hpp:320
restinio::router::method_matcher_t::match
virtual RESTINIO_NODISCARD bool match(const http_method_id_t &method) const noexcept=0
Is the specified method can be applied to a route?
restinio::router::easy_parser_router::impl::dsl_processor::arg_types
meta::transform_t< dsl_details::special_decay, meta::type_list< Args... > > arg_types
Definition: easy_parser_router.hpp:501
restinio::router::easy_parser_router::impl::actual_router_entry_t::m_handler
Handler m_handler
Request handler to be used.
Definition: easy_parser_router.hpp:101
target_path_holder.hpp
Implementation of target_path_holder helper class.
restinio::router::impl::target_path_holder_t
Helper class for holding a unique instance of char array with target_path value.
Definition: target_path_holder.hpp:46
restinio::utils::restinio_default_unescape_traits
The default traits for escaping and unexcaping symbols in a query string.
Definition: percent_encoding.hpp:36
restinio::router::easy_parser_router::impl::unescape_transformer_t::transform
RESTINIO_NODISCARD result_type transform(input_type &&input) const
Definition: easy_parser_router.hpp:156
restinio::router::easy_parser_router::impl::dsl_details::result_tuple_detector< From<>, To< Results... > >::type
To< Results... > type
Definition: easy_parser_router.hpp:329
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t::consumer_t
ep::impl::any_value_skipper_t consumer_t
Definition: easy_parser_router.hpp:254
restinio::easy_parser::any_symbol_if_not_p
RESTINIO_NODISCARD auto any_symbol_if_not_p(char sentinel) noexcept
A factory function to create a any_symbol_if_not_producer.
Definition: easy_parser.hpp:3973
restinio::router::easy_parser_router::impl::special_produce_tuple_item_clause_t::special_produce_tuple_item_clause_t
special_produce_tuple_item_clause_t(Producer_Arg &&producer)
Definition: easy_parser_router.hpp:195
restinio::router::easy_parser_router_t
A request router that uses easy_parser for matching requests with handlers.
Definition: easy_parser_router.hpp:908
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t::special_exact_fragment_clause_t
special_exact_fragment_clause_t(string_view_t value)
Definition: easy_parser_router.hpp:265
restinio::router::easy_parser_router::impl::special_exact_fixed_size_fragment_clause_t
A special clause type for case when exact_fixed_size_fragment_producer should be used without storing...
Definition: easy_parser_router.hpp:220
restinio::router::easy_parser_router::impl::dsl_details::clauses_type_maker< From<>, To< Results... >, Current_Index >::type
To< Results... > type
Definition: easy_parser_router.hpp:427
restinio::request_handling_status_t
request_handling_status_t
Request handling status.
Definition: common_types.hpp:26
restinio::router::easy_parser_router::impl::path_to_tuple_producer_t
An implementation of a producer for path_to_tuple case.
Definition: easy_parser_router.hpp:524
restinio::router::easy_parser_router::impl::dsl_details::one_clause_type_processor::clause_type
T clause_type
Definition: easy_parser_router.hpp:358
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t::producer_t
ep::impl::exact_fragment_producer_t producer_t
Definition: easy_parser_router.hpp:253
restinio::router::easy_parser_router_t::operator=
easy_parser_router_t & operator=(easy_parser_router_t &&)=default
easy_parser.hpp
An very small, simple and somewhat limited implementation of recursive-descent parser.
restinio::router::easy_parser_router::impl::dsl_details::make_clauses_types
Definition: easy_parser_router.hpp:434
restinio::router::easy_parser_router::impl::path_to_params_producer_t
An implementation of a producer for path_to_params case.
Definition: easy_parser_router.hpp:606
restinio::utils::metaprogramming::head_of_t
typename impl::head_of< L... >::type head_of_t
Metafunction to get the first item from a list of types.
Definition: metaprogramming.hpp:91
restinio::easy_parser::impl::transformer_tag
A special base class to be used with transformers.
Definition: easy_parser.hpp:999
restinio::router::easy_parser_router::impl::actual_router_entry_t::m_producer
Producer m_producer
Parser of a route and producer of argument(s) for request handler.
Definition: easy_parser_router.hpp:98
restinio::router::easy_parser_router::impl::router_entry_t
An interface for one entry of easy_parser-based router.
Definition: easy_parser_router.hpp:52
restinio::router::easy_parser_router::impl::special_exact_fixed_size_fragment_clause_t::producer_t
ep::impl::exact_fixed_size_fragment_producer_t< Size > producer_t
Definition: easy_parser_router.hpp:221
restinio::router::easy_parser_router::impl::dsl_details::one_clause_type_processor::next_index
static constexpr std::size_t next_index
Definition: easy_parser_router.hpp:359
restinio::router::easy_parser_router::impl::special_exact_fixed_size_fragment_clause_t::base_type_t
ep::impl::consume_value_clause_t< producer_t, consumer_t > base_type_t
Definition: easy_parser_router.hpp:226
restinio::utils::metaprogramming::tail_of_t
typename impl::tail_of< L... >::type tail_of_t
Metafunction to get the tail of a list of types in a form of type_list.
Definition: metaprogramming.hpp:129
restinio::router::easy_parser_router_t::m_entries
entries_container_t m_entries
Definition: easy_parser_router.hpp:1054
restinio::easy_parser::try_parse
RESTINIO_NODISCARD expected_t< typename Producer::result_type, parse_error_t > try_parse(string_view_t from, Producer producer)
Perform the parsing of the specified content by using specified value producer.
Definition: easy_parser.hpp:5042
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t::base_type_t
ep::impl::consume_value_clause_t< producer_t, consumer_t > base_type_t
Definition: easy_parser_router.hpp:258
restinio::router::easy_parser_router::impl::special_exact_fragment_clause_t
A special clause type for case when exact_fragment_producer should be used without storing its value.
Definition: easy_parser_router.hpp:252
restinio::router::easy_parser_router::impl::dsl_details::add_type_if_necessary_impl
Definition: easy_parser_router.hpp:277
restinio::router::easy_parser_router::impl::special_produce_tuple_item_clause_t::consumer_t
ep::impl::tuple_item_consumer_t< Index > consumer_t
Definition: easy_parser_router.hpp:178
restinio::router::non_matched_request_handler_t
std::function< request_handling_status_t(request_handle_t) > non_matched_request_handler_t
Definition: non_matched_request_handler.hpp:29
restinio::router::easy_parser_router_t::operator()
RESTINIO_NODISCARD request_handling_status_t operator()(request_handle_t req) const
Definition: easy_parser_router.hpp:922
restinio::expected_t
nonstd::expected< T, E > expected_t
Definition: expected.hpp:22
restinio::router::easy_parser_router::impl::dsl_details::add_type_if_necessary
Definition: easy_parser_router.hpp:301
restinio::router::easy_parser_router::impl::special_produce_tuple_item_clause_t::base_type_t
ep::impl::consume_value_clause_t< Producer, consumer_t > base_type_t
Definition: easy_parser_router.hpp:182
restinio::router::easy_parser_router::impl::path_to_tuple_producer_t::invoke_handler
static RESTINIO_NODISCARD auto invoke_handler(const request_handle_t &req, Handler &&handler, typename base_type_t::result_type &type)
Definition: easy_parser_router.hpp:533
restinio::router::easy_parser_router::impl::actual_router_entry_t
An actual implementation of router_entry interface.
Definition: easy_parser_router.hpp:93
restinio::router::easy_parser_router::impl::dsl_details::make_clauses_types::type
meta::rename_t< typename clauses_type_maker< Args_Type_List, meta::type_list<>, 0u >::type, std::tuple > type
Definition: easy_parser_router.hpp:440
restinio::router::easy_parser_router::impl::dsl_details::add_type_if_necessary_impl< H, To< Results... >, true >::type
To< Results..., typename H::result_type > type
Definition: easy_parser_router.hpp:294
restinio::easy_parser::to_container
RESTINIO_NODISCARD auto to_container()
A factory function to create a to_container_consumer.
Definition: easy_parser.hpp:4583
method_matcher.hpp
Stuff related to method_matchers.
restinio::router::easy_parser_router::impl::router_entry_t::~router_entry_t
virtual ~router_entry_t()=default
restinio::router::easy_parser_router::impl::dsl_processor
The main meta-function for processing route DSL.
Definition: easy_parser_router.hpp:497
restinio
Definition: asio_include.hpp:21
restinio::router::easy_parser_router::impl::dsl_details::detect_result_tuple::type
meta::rename_t< typename result_tuple_detector< Args_Type_List, meta::type_list<> >::type, std::tuple > type
Definition: easy_parser_router.hpp:340
restinio::router::easy_parser_router::impl::unescape_transformer_t::input_type
std::string input_type
Definition: easy_parser_router.hpp:152
restinio::router::easy_parser_router::impl::dsl_details::detect_result_tuple
Definition: easy_parser_router.hpp:335
restinio::router::easy_parser_router::impl::special_produce_tuple_item_clause_t
A special case of produce-consume clause where the produced value is stored into a tuple.
Definition: easy_parser_router.hpp:177
restinio::router::easy_parser_router::unescape
RESTINIO_NODISCARD auto unescape()
A factory for unescape_transformer.
Definition: easy_parser_router.hpp:841
restinio::router::easy_parser_router::impl::router_entry_unique_ptr_t
std::unique_ptr< router_entry_t > router_entry_unique_ptr_t
An alias for unique_ptr of router_entry.
Definition: easy_parser_router.hpp:76
restinio::router::easy_parser_router::impl::path_to_params_producer_t::invoke_handler
static RESTINIO_NODISCARD auto invoke_handler(const request_handle_t &req, Handler &&handler, typename base_type_t::result_type &type)
Definition: easy_parser_router.hpp:615
restinio::router::easy_parser_router::impl::router_entry_t::try_handle
virtual RESTINIO_NODISCARD expected_t< request_handling_status_t, no_match_t > try_handle(const request_handle_t &req, target_path_holder_t &target_path) const =0
An attempt to match a request against the route.
restinio::router::easy_parser_router_t::m_non_matched_request_handler
non_matched_request_handler_t m_non_matched_request_handler
Handler that is called for requests that don't match any route.
Definition: easy_parser_router.hpp:1057
restinio::router::impl::target_path_holder_t::view
RESTINIO_NODISCARD string_view_t view() const noexcept
Get access to the value of target_path.
Definition: target_path_holder.hpp:86
restinio::router::easy_parser_router_t::http_post
void http_post(Route_Producer &&route, Handler &&handler)
Set handler for HTTP POST request.
Definition: easy_parser_router.hpp:1020
restinio::router::easy_parser_router::impl::dsl_details::detect_result_tuple_t
typename detect_result_tuple< Args_Type_List >::type detect_result_tuple_t
Definition: easy_parser_router.hpp:344
restinio::request_handle_t
std::shared_ptr< request_t > request_handle_t
Request handler, that is the type for calling request handlers.
Definition: request_handler.hpp:182
restinio::router::easy_parser_router::impl::dsl_details::clauses_type_maker< From< Sources... >, To< Results... >, Current_Index >::head_type
meta::head_of_t< Sources... > head_type
Definition: easy_parser_router.hpp:406
restinio::router::easy_parser_router::path_to_params
RESTINIO_NODISCARD auto path_to_params(Args &&...args)
Describe a route for a handler that accepts params from the route in form of a list of separate argum...
Definition: easy_parser_router.hpp:727
restinio::router::easy_parser_router::impl::dsl_details::special_decay
A special analog of std::decay meta-function that is handles array differently.
Definition: easy_parser_router.hpp:465
restinio::router::easy_parser_router::impl::unescape_transformer_t
A transformer that performs percent-unescaping of an input string.
Definition: easy_parser_router.hpp:151
restinio::router::easy_parser_router::impl::path_to_params_details::call_with_tuple_impl
decltype(auto) call_with_tuple_impl(F &&what, const request_handle_t &req, Tuple &&params, std::index_sequence< Indexes... >)
Definition: easy_parser_router.hpp:550
restinio::request_rejected
constexpr request_handling_status_t request_rejected() noexcept
Definition: common_types.hpp:44
restinio::router::easy_parser_router::impl::dsl_processor::clauses_tuple
dsl_details::make_clauses_types_t< arg_types > clauses_tuple
Definition: easy_parser_router.hpp:505
restinio::router::easy_parser_router::impl::dsl_details::clauses_type_maker< From< Sources... >, To< Results... >, Current_Index >::type
typename clauses_type_maker< meta::tail_of_t< Sources... >, To< Results..., typename one_clause_type::clause_type >, one_clause_type::next_index >::type type
Definition: easy_parser_router.hpp:417
restinio::router::easy_parser_router::impl::actual_router_entry_t::actual_router_entry_t
actual_router_entry_t(Method_Matcher &&method_matcher, Producer_Arg &&producer, Handler_Arg &&handler)
Definition: easy_parser_router.hpp:108
restinio::router::easy_parser_router::impl::special_exact_fixed_size_fragment_clause_t::consumer_t
ep::impl::any_value_skipper_t consumer_t
Definition: easy_parser_router.hpp:222
restinio::router::easy_parser_router::impl::path_to_params_details::call_with_tuple
decltype(auto) call_with_tuple(F &&what, const request_handle_t &req, Tuple &&params)
A helper function to call a request-handler with a tuple.
Definition: easy_parser_router.hpp:573
restinio::router::easy_parser_router::impl::dsl_details::one_clause_type_processor
Definition: easy_parser_router.hpp:357
restinio::router::easy_parser_router::impl::dsl_details::clauses_type_maker
Definition: easy_parser_router.hpp:395
restinio::easy_parser
Definition: easy_parser.hpp:39
restinio::router::easy_parser_router::impl::target_path_holder_t
restinio::router::impl::target_path_holder_t target_path_holder_t
Definition: easy_parser_router.hpp:37
non_matched_request_handler.hpp
The definition of the non_matched_request_handler type.
restinio::router::easy_parser_router::impl::no_match_t
Helper type to indicate a negative match attempt.
Definition: easy_parser_router.hpp:44
const
#define const
Definition: zconf.h:230
restinio::router::easy_parser_router_t::easy_parser_router_t
easy_parser_router_t()=default
restinio::easy_parser::repeat
RESTINIO_NODISCARD auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.
Definition: easy_parser.hpp:3876