#include "server/api/parameters_parser.hpp" #include "server/api/match_parameter_grammar.hpp" #include "server/api/nearest_parameter_grammar.hpp" #include "server/api/route_parameters_grammar.hpp" #include "server/api/table_parameter_grammar.hpp" #include "server/api/tile_parameter_grammar.hpp" #include "server/api/trip_parameter_grammar.hpp" #include namespace osrm::server::api { namespace detail { template using is_grammar_t = std::integral_constant, T>::value || std::is_same, T>::value || std::is_same, T>::value || std::is_same, T>::value || std::is_same, T>::value || std::is_same, T>::value>; template ::value, int>::type = 0, typename std::enable_if::value, int>::type = 0> std::optional parseParameters(std::string::iterator &iter, const std::string::iterator end) { using It = std::decay::type; static const GrammarT grammar; try { ParameterT parameters; const auto ok = boost::spirit::qi::parse(iter, end, grammar(boost::phoenix::ref(parameters))); if (ok && iter == end) return parameters; } catch (const qi::expectation_failure &failure) { // The grammar above using expectation parsers ">" does not automatically increment the // iterator to the failing position. Extract the position from the exception ourselves. iter = failure.first; } catch (const boost::numeric::bad_numeric_cast &) { // this can happen if we get bad numeric values in the request, just handle // as normal parser error } return std::nullopt; } } // namespace detail template <> std::optional parseParameters(std::string::iterator &iter, const std::string::iterator end) { return detail::parseParameters>(iter, end); } template <> std::optional parseParameters(std::string::iterator &iter, const std::string::iterator end) { return detail::parseParameters>(iter, end); } template <> std::optional parseParameters(std::string::iterator &iter, const std::string::iterator end) { return detail::parseParameters>(iter, end); } template <> std::optional parseParameters(std::string::iterator &iter, const std::string::iterator end) { return detail::parseParameters>(iter, end); } template <> std::optional parseParameters(std::string::iterator &iter, const std::string::iterator end) { return detail::parseParameters>(iter, end); } template <> std::optional parseParameters(std::string::iterator &iter, const std::string::iterator end) { return detail::parseParameters>(iter, end); } } // namespace osrm::server::api