easy_parser_router.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <restinio/router/impl/target_path_holder.hpp>
#include <restinio/router/non_matched_request_handler.hpp>
#include <restinio/router/method_matcher.hpp>
#include <restinio/helpers/easy_parser.hpp>
#include <vector>
namespace restinio
{
namespace router
{
namespace easy_parser_router
{
namespace impl
{
namespace meta = restinio::utils::metaprogramming;
namespace ep = restinio::easy_parser;
using target_path_holder_t = restinio::router::impl::target_path_holder_t;
struct no_match_t {};
template< typename Extra_Data >
class router_entry_t
{
public:
using actual_request_handle_t = generic_request_handle_t< Extra_Data >;
virtual ~router_entry_t() = default;
RESTINIO_NODISCARD
virtual expected_t< request_handling_status_t, no_match_t >
try_handle(
const actual_request_handle_t & req,
target_path_holder_t & target_path ) const = 0;
};
template< typename Extra_Data >
using router_entry_unique_ptr_t =
std::unique_ptr< router_entry_t< Extra_Data > >;
//
// actual_router_entry_t
//
template< typename Extra_Data, typename Producer, typename Handler >
class actual_router_entry_t : public router_entry_t< Extra_Data >
{
//FIXME: compatibility between Extra_Data and Handler should be
//checked by static_assert. If it's possible.
restinio::router::impl::buffered_matcher_holder_t m_method_matcher;
Producer m_producer;
Handler m_handler;
public:
using actual_request_handle_t =
typename router_entry_t<Extra_Data>::actual_request_handle_t;
template<
typename Method_Matcher,
typename Producer_Arg,
typename Handler_Arg >
actual_router_entry_t(
Method_Matcher && method_matcher,
Producer_Arg && producer,
Handler_Arg && handler )
: m_producer{ std::forward<Producer_Arg>(producer) }
, m_handler{ std::forward<Handler_Arg>(handler) }
{
assign( m_method_matcher, std::forward<Method_Matcher>(method_matcher) );
}
RESTINIO_NODISCARD
expected_t< request_handling_status_t, no_match_t >
try_handle(
const actual_request_handle_t & req,
target_path_holder_t & target_path ) const override
{
if( m_method_matcher->match( req->header().method() ) )
{
auto parse_result = easy_parser::try_parse(
target_path.view(),
m_producer );
if( parse_result )
{
return Producer::invoke_handler( req, m_handler, *parse_result );
}
}
return make_unexpected( no_match_t{} );
}
};
//
// unescape_transformer_t
//
template< typename Unescape_Traits >
struct unescape_transformer_t
: public restinio::easy_parser::impl::transformer_tag< std::string >
{
using input_type = std::string;
RESTINIO_NODISCARD
result_type
transform( input_type && input ) const
{
return restinio::utils::unescape_percent_encoding< Unescape_Traits >(
input );
}
};
//
// special_produce_tuple_item_clause_t
//
template< typename Producer, std::size_t Index >
class special_produce_tuple_item_clause_t
: public ep::impl::consume_value_clause_t<
Producer,
ep::impl::tuple_item_consumer_t<Index> >
{
using consumer_t = ep::impl::tuple_item_consumer_t<Index>;
using base_type_t = ep::impl::consume_value_clause_t<
Producer,
consumer_t >;
// NOTE: this is just a workaround for VS2017.
template< typename Producer_Arg >
RESTINIO_NODISCARD
static Producer
make_producer( Producer_Arg && producer )
{
return { std::forward<Producer_Arg>(producer) };
}
public:
template< typename Producer_Arg >
special_produce_tuple_item_clause_t( Producer_Arg && producer )
: base_type_t{
make_producer( std::forward<Producer_Arg>(producer) ),
consumer_t{} }
{}
};
//
// special_exact_fixed_size_fragment_clause_t
//
template< std::size_t Size >
class special_exact_fixed_size_fragment_clause_t
: public ep::impl::consume_value_clause_t<
ep::impl::exact_fixed_size_fragment_producer_t<Size>,
ep::impl::any_value_skipper_t >
{
using producer_t = ep::impl::exact_fixed_size_fragment_producer_t<Size>;
using consumer_t = ep::impl::any_value_skipper_t;
using base_type_t = ep::impl::consume_value_clause_t<
producer_t,
consumer_t >;
public:
special_exact_fixed_size_fragment_clause_t(
const char (&fragment)[Size] )
: base_type_t{ producer_t{ fragment }, consumer_t{} }
{}
};
//
// special_exact_fragment_clause_t
//
class special_exact_fragment_clause_t
: public ep::impl::consume_value_clause_t<
ep::impl::exact_fragment_producer_t,
ep::impl::any_value_skipper_t >
{
using producer_t = ep::impl::exact_fragment_producer_t;
using consumer_t = ep::impl::any_value_skipper_t;
using base_type_t = ep::impl::consume_value_clause_t<
producer_t,
consumer_t >;
public:
special_exact_fragment_clause_t( std::string value )
: base_type_t{ producer_t{ std::move(value) }, consumer_t{} }
{}
special_exact_fragment_clause_t( string_view_t value )
: base_type_t{
producer_t{ std::string{ value.data(), value.size() } },
consumer_t{} }
{}
};
namespace dsl_details
{
// Adds type H to type list R if Is_Producer is true.
template< typename H, typename R, bool Is_Producer >
struct add_type_if_necessary_impl;
template<
typename H,
template<class...> class To,
typename... Results >
struct add_type_if_necessary_impl< H, To<Results...>, false >
{
using type = To<Results...>;
};
template<
typename H,
template<class...> class To,
typename... Results >
struct add_type_if_necessary_impl< H, To<Results...>, true >
{
using type = To<Results..., typename H::result_type>;
};
// Adds type H to type list R if H is a producer.
template< typename H, typename R >
struct add_type_if_necessary
: add_type_if_necessary_impl< H, R, ep::impl::is_producer_v<H> >
{};
// Produces a type-list of producers from type-list From.
template< typename From, typename To >
struct result_tuple_detector;
// Adds a type from Sources to Results only if this type is a producer.
template<
template<class...> class From,
typename... Sources,
template<class...> class To,
typename... Results >
struct result_tuple_detector< From<Sources...>, To<Results...> >
{
using type = typename result_tuple_detector<
meta::tail_of_t< Sources... >,
typename add_type_if_necessary<
meta::head_of_t< Sources... >,
To< Results... > >::type
>::type;
};
template<
template<class...> class From,
template<class...> class To,
typename... Results >
struct result_tuple_detector< From<>, To<Results...> >
{
using type = To<Results...>;
};
// Produces a type of std::tuple of producers from type-list Args_Type_List.
template< typename Args_Type_List >
struct detect_result_tuple
{
using type = meta::rename_t<
typename result_tuple_detector<
Args_Type_List,
meta::type_list<> >::type,
std::tuple >;
};
template< typename Args_Type_List >
using detect_result_tuple_t = typename detect_result_tuple<Args_Type_List>::type;
// Detects an appropriate type of clause for T.
// If T is a producer then there will be a new clause that
// consumes a value T produces.
// In that case Current_Index will also be incremented.
//
// If T is not a producer then Current_Index will be kept.
//
// If T is a string literal, or std::string, or string_view
// then T will be replaced by a special clause.
template< typename T, bool Is_Producer, std::size_t Current_Index >
struct one_clause_type_processor
{
using clause_type = T;
static constexpr std::size_t next_index = Current_Index;
};
template< std::size_t Size, std::size_t Current_Index >
struct one_clause_type_processor<const char[Size], false, Current_Index>
{
using clause_type = special_exact_fixed_size_fragment_clause_t<Size>;
static constexpr std::size_t next_index = Current_Index;
};
template< std::size_t Current_Index >
struct one_clause_type_processor<std::string, false, Current_Index>
{
using clause_type = special_exact_fragment_clause_t;
static constexpr std::size_t next_index = Current_Index;
};
template< std::size_t Current_Index >
struct one_clause_type_processor<string_view_t, false, Current_Index>
{
using clause_type = special_exact_fragment_clause_t;
static constexpr std::size_t next_index = Current_Index;
};
template< typename T, std::size_t Current_Index >
struct one_clause_type_processor<T, true, Current_Index>
{
using clause_type = special_produce_tuple_item_clause_t< T, Current_Index >;
static constexpr std::size_t next_index = Current_Index + 1u;
};
// Takes a type-list of user-specified types From and produces a
// typelist of actual clauses types To.
//
// The Current_Index should 0 at the first invocation.
template< typename From, typename To, std::size_t Current_Index >
struct clauses_type_maker;
template<
template<class...> class From,
typename... Sources,
template<class...> class To,
typename... Results,
std::size_t Current_Index >
struct clauses_type_maker< From<Sources...>, To<Results...>, Current_Index >
{
private:
using head_type = meta::head_of_t< Sources... >;
using one_clause_type = one_clause_type_processor<
head_type,
ep::impl::is_producer_v<head_type>,
Current_Index >;
public:
using type = typename clauses_type_maker<
meta::tail_of_t< Sources... >,
To< Results..., typename one_clause_type::clause_type >,
one_clause_type::next_index >::type;
};
template<
template<class...> class From,
template<class...> class To,
typename... Results,
std::size_t Current_Index >
struct clauses_type_maker< From<>, To<Results...>, Current_Index >
{
using type = To< Results... >;
};
// Takes a type-list of user-specified types Args_Type_List and produces a
// typelist of actual clauses types to be used for parsing.
template< typename Args_Type_List >
struct make_clauses_types
{
using type = meta::rename_t<
typename clauses_type_maker<
Args_Type_List,
meta::type_list<>,
0u >::type,
std::tuple >;
};
template< typename Args_Type_List >
using make_clauses_types_t = typename make_clauses_types<Args_Type_List>::type;
//
// special_decay
//
template< typename T >
struct special_decay
{
private:
using U = std::remove_reference_t<T>;
public:
using type = typename std::conditional<
std::is_array<U>::value,
U,
std::remove_cv_t<U>
>::type;
};
} /* namespace dsl_details */
//
// dsl_processor
//
template< typename... Args >
struct dsl_processor
{
static_assert( 0u != sizeof...(Args), "Args can't be an empty list" );
using arg_types = meta::transform_t<
dsl_details::special_decay, meta::type_list<Args...> >;
using result_tuple = dsl_details::detect_result_tuple_t< arg_types >;
using clauses_tuple = dsl_details::make_clauses_types_t< arg_types >;
};
//
// path_to_tuple_producer_t
//
template<
typename Target_Type,
typename Subitems_Tuple >
class path_to_tuple_producer_t
: public ep::impl::produce_t< Target_Type, Subitems_Tuple >
{
using base_type_t = ep::impl::produce_t< Target_Type, Subitems_Tuple >;
public:
using base_type_t::base_type_t;
template< typename Extra_Data, typename Handler >
RESTINIO_NODISCARD
static auto
invoke_handler(
const generic_request_handle_t< Extra_Data > & req,
Handler && handler,
typename base_type_t::result_type & type )
{
return handler( req, type );
}
};
namespace path_to_params_details
{
template<
typename F,
typename Extra_Data,
typename Tuple,
std::size_t... Indexes >
decltype(auto)
call_with_tuple_impl(
F && what,
const generic_request_handle_t< Extra_Data > & req,
Tuple && params,
std::index_sequence<Indexes...> )
{
return std::forward<F>(what)(
req,
std::get<Indexes>(std::forward<Tuple>(params))... );
}
//
// call_with_tuple
//
template< typename F, typename Extra_Data, typename Tuple >
decltype(auto)
call_with_tuple(
F && what,
const generic_request_handle_t< Extra_Data > & req,
Tuple && params )
{
return call_with_tuple_impl(
std::forward<F>(what),
req,
std::forward<Tuple>(params),
std::make_index_sequence<
std::tuple_size< std::remove_reference_t<Tuple> >::value
>{} );
}
} /* namespace path_to_params_details */
//
// path_to_params_producer_t
//
template<
typename Target_Type,
typename Subitems_Tuple >
class path_to_params_producer_t
: public ep::impl::produce_t< Target_Type, Subitems_Tuple >
{
using base_type_t = ep::impl::produce_t< Target_Type, Subitems_Tuple >;
public:
using base_type_t::base_type_t;
template< typename User_Type, typename Handler >
RESTINIO_NODISCARD
static auto
invoke_handler(
const generic_request_handle_t< User_Type > & req,
Handler && handler,
typename base_type_t::result_type & type )
{
return path_to_params_details::call_with_tuple( handler, req, type );
}
};
} /* namespace impl */
using namespace restinio::easy_parser;
//
// path_to_tuple
//
template< typename... Args >
RESTINIO_NODISCARD
auto
path_to_tuple( Args && ...args )
{
using dsl_processor = impl::dsl_processor< Args... >;
using result_tuple_type = typename dsl_processor::result_tuple;
using subclauses_tuple_type = typename dsl_processor::clauses_tuple;
using producer_type = impl::path_to_tuple_producer_t<
result_tuple_type,
subclauses_tuple_type >;
return producer_type{
subclauses_tuple_type{ std::forward<Args>(args)... }
};
}
//
// path_to_params
//
template< typename... Args >
RESTINIO_NODISCARD
auto
path_to_params( Args && ...args )
{
using dsl_processor = impl::dsl_processor< Args... >;
using result_tuple_type = typename dsl_processor::result_tuple;
using subclauses_tuple_type = typename dsl_processor::clauses_tuple;
using producer_type = impl::path_to_params_producer_t<
result_tuple_type,
subclauses_tuple_type >;
return producer_type{
subclauses_tuple_type{ std::forward<Args>(args)... }
};
}
RESTINIO_NODISCARD
inline auto
path_fragment_p( char separator = '/' )
{
return produce< std::string >(
repeat( 1, N,
any_symbol_if_not_p( separator ) >> to_container() ) );
}
template< typename Unescape_Traits =
restinio::utils::restinio_default_unescape_traits >
RESTINIO_NODISCARD
auto
unescape()
{
return impl::unescape_transformer_t< Unescape_Traits >{};
}
} /* namespace easy_parser_router */
//
// generic_easy_parser_router_t
//
template< typename Extra_Data_Factory >
class generic_easy_parser_router_t
{
using extra_data_t = typename Extra_Data_Factory::data_t;
public:
using actual_request_handle_t = generic_request_handle_t< extra_data_t >;
generic_easy_parser_router_t() = default;
generic_easy_parser_router_t(
const generic_easy_parser_router_t & ) = delete;
generic_easy_parser_router_t &
operator=( const generic_easy_parser_router_t & ) = delete;
generic_easy_parser_router_t( generic_easy_parser_router_t && ) = default;
generic_easy_parser_router_t &
operator=( generic_easy_parser_router_t && ) = default;
RESTINIO_NODISCARD
request_handling_status_t
operator()( actual_request_handle_t req ) const
{
using namespace easy_parser_router::impl;
// Take care of an optional trailing slash.
string_view_t path_to_inspect{ req->header().path() };
if( path_to_inspect.size() > 1u && '/' == path_to_inspect.back() )
path_to_inspect.remove_suffix( 1u );
target_path_holder_t target_path{ path_to_inspect };
for( const auto & entry : m_entries )
{
const auto r = entry->try_handle( req, target_path );
if( r )
{
return *r;
}
}
// Here: none of the routes matches this handler.
if( m_non_matched_request_handler )
{
// If non matched request handler is set
// then call it.
return m_non_matched_request_handler( std::move( req ) );
}
return request_not_handled();
}
template<
typename Method_Matcher,
typename Route_Producer,
typename Handler >
void
add_handler(
Method_Matcher && method_matcher,
Route_Producer && route,
Handler && handler )
{
using namespace easy_parser_router::impl;
using producer_type = std::decay_t< Route_Producer >;
using handler_type = std::decay_t< Handler >;
using actual_entry_type = actual_router_entry_t<
extra_data_t, producer_type, handler_type >;
auto entry = std::make_unique< actual_entry_type >(
std::forward<Method_Matcher>(method_matcher),
std::forward<Route_Producer>(route),
std::forward<Handler>(handler) );
m_entries.push_back( std::move(entry) );
}
template< typename Route_Producer, typename Handler >
void
http_get(
Route_Producer && route,
Handler && handler )
{
this->add_handler(
http_method_get(),
std::forward<Route_Producer>(route),
std::forward<Handler>(handler) );
}
template< typename Route_Producer, typename Handler >
void
http_delete(
Route_Producer && route,
Handler && handler )
{
this->add_handler(
http_method_delete(),
std::forward<Route_Producer>(route),
std::forward<Handler>(handler) );
}
template< typename Route_Producer, typename Handler >
void
http_head(
Route_Producer && route,
Handler && handler )
{
this->add_handler(
http_method_head(),
std::forward<Route_Producer>(route),
std::forward<Handler>(handler) );
}
template< typename Route_Producer, typename Handler >
void
http_post(
Route_Producer && route,
Handler && handler )
{
this->add_handler(
http_method_post(),
std::forward<Route_Producer>(route),
std::forward<Handler>(handler) );
}
template< typename Route_Producer, typename Handler >
void
http_put(
Route_Producer && route,
Handler && handler )
{
this->add_handler(
http_method_put(),
std::forward<Route_Producer>(route),
std::forward<Handler>(handler) );
}
void
non_matched_request_handler(
generic_non_matched_request_handler_t< extra_data_t > nmrh )
{
m_non_matched_request_handler= std::move( nmrh );
}
private:
using entries_container_t = std::vector<
easy_parser_router::impl::router_entry_unique_ptr_t< extra_data_t >
>;
entries_container_t m_entries;
generic_non_matched_request_handler_t< extra_data_t >
m_non_matched_request_handler;
};
//
// easy_parser_router_t
//
using easy_parser_router_t =
generic_easy_parser_router_t< no_extra_data_factory_t >;
} /* namespace router */
} /* namespace restinio */
restinio::router::easy_parser_router::impl::actual_router_entry_t
An actual implementation of router_entry interface.
Definition: easy_parser_router.hpp:107
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:115
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:128
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:118
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 actual_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:140
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:112
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:627
restinio::router::easy_parser_router::impl::path_to_params_producer_t::invoke_handler
static RESTINIO_NODISCARD auto invoke_handler(const generic_request_handle_t< User_Type > &req, Handler &&handler, typename base_type_t::result_type &type)
Definition: easy_parser_router.hpp:636
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:628
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:544
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:545
restinio::router::easy_parser_router::impl::path_to_tuple_producer_t::invoke_handler
static RESTINIO_NODISCARD auto invoke_handler(const generic_request_handle_t< Extra_Data > &req, Handler &&handler, typename base_type_t::result_type &type)
Definition: easy_parser_router.hpp:553
restinio::router::easy_parser_router::impl::router_entry_t
An interface for one entry of easy_parser-based router.
Definition: easy_parser_router.hpp:56
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 actual_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::impl::router_entry_t::~router_entry_t
virtual ~router_entry_t()=default
restinio::router::easy_parser_router::impl::router_entry_t::actual_request_handle_t
generic_request_handle_t< Extra_Data > actual_request_handle_t
Definition: easy_parser_router.hpp:58
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:240
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:241
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:246
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:242
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:249
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:272
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:285
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:274
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:278
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:281
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:273
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:197
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:198
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:208
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:202
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:215
restinio::router::generic_easy_parser_router_t
A generic request router that uses easy_parser for matching requests with handlers.
Definition: easy_parser_router.hpp:950
restinio::router::generic_easy_parser_router_t::add_handler
void add_handler(Method_Matcher &&method_matcher, Route_Producer &&route, Handler &&handler)
Definition: easy_parser_router.hpp:1004
restinio::router::generic_easy_parser_router_t::extra_data_t
typename Extra_Data_Factory::data_t extra_data_t
Definition: easy_parser_router.hpp:951
restinio::router::generic_easy_parser_router_t::actual_request_handle_t
generic_request_handle_t< extra_data_t > actual_request_handle_t
Definition: easy_parser_router.hpp:954
restinio::router::generic_easy_parser_router_t::operator=
generic_easy_parser_router_t & operator=(generic_easy_parser_router_t &&)=default
restinio::router::generic_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:1028
restinio::router::generic_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:1054
restinio::router::generic_easy_parser_router_t::non_matched_request_handler
void non_matched_request_handler(generic_non_matched_request_handler_t< extra_data_t > nmrh)
Set handler for requests that don't match any route.
Definition: easy_parser_router.hpp:1092
restinio::router::generic_easy_parser_router_t::operator=
generic_easy_parser_router_t & operator=(const generic_easy_parser_router_t &)=delete
restinio::router::generic_easy_parser_router_t::m_non_matched_request_handler
generic_non_matched_request_handler_t< extra_data_t > m_non_matched_request_handler
Handler that is called for requests that don't match any route.
Definition: easy_parser_router.hpp:1107
restinio::router::generic_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:1041
restinio::router::generic_easy_parser_router_t::generic_easy_parser_router_t
generic_easy_parser_router_t(generic_easy_parser_router_t &&)=default
restinio::router::generic_easy_parser_router_t::generic_easy_parser_router_t
generic_easy_parser_router_t()=default
restinio::router::generic_easy_parser_router_t::entries_container_t
std::vector< easy_parser_router::impl::router_entry_unique_ptr_t< extra_data_t > > entries_container_t
Definition: easy_parser_router.hpp:1101
restinio::router::generic_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:1067
restinio::router::generic_easy_parser_router_t::m_entries
entries_container_t m_entries
Definition: easy_parser_router.hpp:1103
restinio::router::generic_easy_parser_router_t::generic_easy_parser_router_t
generic_easy_parser_router_t(const generic_easy_parser_router_t &)=delete
restinio::router::generic_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:1080
restinio::router::generic_easy_parser_router_t::operator()
RESTINIO_NODISCARD request_handling_status_t operator()(actual_request_handle_t req) const
Definition: easy_parser_router.hpp:969
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::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::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_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
easy_parser.hpp
An very small, simple and somewhat limited implementation of recursive-descent parser.
method_matcher.hpp
Stuff related to method_matchers.
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:465
restinio::easy_parser
Definition: easy_parser.hpp:39
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::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::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
restinio::easy_parser::N
constexpr std::size_t N
A special marker that means infinite repetitions.
Definition: easy_parser.hpp:455
restinio::easy_parser::to_container
RESTINIO_NODISCARD auto to_container()
A factory function to create a to_container_consumer.
Definition: easy_parser.hpp:4583
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:364
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:464
restinio::router::easy_parser_router::impl::path_to_params_details::call_with_tuple_impl
decltype(auto) call_with_tuple_impl(F &&what, const generic_request_handle_t< Extra_Data > &req, Tuple &&params, std::index_sequence< Indexes... >)
Definition: easy_parser_router.hpp:571
restinio::router::easy_parser_router::impl::path_to_params_details::call_with_tuple
decltype(auto) call_with_tuple(F &&what, const generic_request_handle_t< Extra_Data > &req, Tuple &&params)
A helper function to call a request-handler with a tuple.
Definition: easy_parser_router.hpp:594
restinio::router::easy_parser_router::impl::router_entry_unique_ptr_t
std::unique_ptr< router_entry_t< Extra_Data > > router_entry_unique_ptr_t
An alias for unique_ptr of router_entry.
Definition: easy_parser_router.hpp:87
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
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:748
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:805
restinio::router::easy_parser_router::unescape
RESTINIO_NODISCARD auto unescape()
A factory for unescape_transformer.
Definition: easy_parser_router.hpp:862
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:694
restinio::router::generic_non_matched_request_handler_t
std::function< request_handling_status_t(generic_request_handle_t< Extra_Data >) > generic_non_matched_request_handler_t
A generic type of handler for non-matched requests.
Definition: non_matched_request_handler.hpp:45
restinio::utils::metaprogramming
Definition: metaprogramming.hpp:24
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::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::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::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
Definition: asio_include.hpp:21
restinio::request_not_handled
RESTINIO_NODISCARD constexpr request_handling_status_t request_not_handled() noexcept
Definition: common_types.hpp:63
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
restinio::generic_request_handle_t
std::shared_ptr< generic_request_t< Extra_Data > > generic_request_handle_t
An alias for shared-pointer to incoming request.
Definition: request_handler.hpp:447
restinio::request_handling_status_t
request_handling_status_t
Request handling status.
Definition: common_types.hpp:26
restinio::expected_t
nonstd::expected< T, E > expected_t
Definition: expected.hpp:22
std
STL namespace.
non_matched_request_handler.hpp
The definition of the non_matched_request_handler type.
restinio::easy_parser::impl::transformer_tag
A special base class to be used with transformers.
Definition: easy_parser.hpp:999
restinio::easy_parser::impl::transformer_tag< std::string >::result_type
std::string result_type
Definition: easy_parser.hpp:1000
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:314
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:305
restinio::router::easy_parser_router::impl::dsl_details::add_type_if_necessary_impl
Definition: easy_parser_router.hpp:297
restinio::router::easy_parser_router::impl::dsl_details::add_type_if_necessary
Definition: easy_parser_router.hpp:321
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:426
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:437
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:447
restinio::router::easy_parser_router::impl::dsl_details::clauses_type_maker
Definition: easy_parser_router.hpp:415
restinio::router::easy_parser_router::impl::dsl_details::detect_result_tuple
Definition: easy_parser_router.hpp:355
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:360
restinio::router::easy_parser_router::impl::dsl_details::make_clauses_types
Definition: easy_parser_router.hpp:454
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:460
restinio::router::easy_parser_router::impl::dsl_details::one_clause_type_processor
Definition: easy_parser_router.hpp:377
restinio::router::easy_parser_router::impl::dsl_details::one_clause_type_processor::clause_type
T clause_type
Definition: easy_parser_router.hpp:378
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:379
restinio::router::easy_parser_router::impl::dsl_details::result_tuple_detector< From<>, To< Results... > >::type
To< Results... > type
Definition: easy_parser_router.hpp:349
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:340
restinio::router::easy_parser_router::impl::dsl_details::result_tuple_detector
Definition: easy_parser_router.hpp:325
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:485
restinio::router::easy_parser_router::impl::dsl_details::special_decay::U
std::remove_reference_t< T > U
Definition: easy_parser_router.hpp:487
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:494
restinio::router::easy_parser_router::impl::dsl_processor
The main meta-function for processing route DSL.
Definition: easy_parser_router.hpp:517
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:525
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:523
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:521
restinio::router::easy_parser_router::impl::no_match_t
Helper type to indicate a negative match attempt.
Definition: easy_parser_router.hpp:44
restinio::router::easy_parser_router::impl::unescape_transformer_t
A transformer that performs percent-unescaping of an input string.
Definition: easy_parser_router.hpp:171
restinio::router::easy_parser_router::impl::unescape_transformer_t::input_type
std::string input_type
Definition: easy_parser_router.hpp:172
restinio::router::easy_parser_router::impl::unescape_transformer_t::transform
RESTINIO_NODISCARD result_type transform(input_type &&input) const
Definition: easy_parser_router.hpp:176
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::utils::metaprogramming::type_list
The basic building block: a type for representation of a type list.
Definition: metaprogramming.hpp:54
restinio::utils::restinio_default_unescape_traits
The default traits for escaping and unexcaping symbols in a query string.
Definition: percent_encoding.hpp:36
target_path_holder.hpp
Implementation of target_path_holder helper class.
const
#define const
Definition: zconf.h:230