2016-02-12 22:23:59 -05:00
|
|
|
#ifndef SERVER_API_ROUTE_PARAMETERS_PARSER_HPP
|
|
|
|
#define SERVER_API_ROUTE_PARAMETERS_PARSER_HPP
|
|
|
|
|
2016-03-02 19:48:30 -05:00
|
|
|
#include "engine/api/base_parameters.hpp"
|
|
|
|
#include "engine/api/tile_parameters.hpp"
|
2016-02-12 22:23:59 -05:00
|
|
|
|
2016-02-17 17:26:22 -05:00
|
|
|
#include <boost/optional/optional.hpp>
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
2022-12-11 04:10:26 -05:00
|
|
|
namespace osrm::server::api
|
2016-02-12 22:23:59 -05:00
|
|
|
{
|
|
|
|
|
2016-02-17 18:06:52 -05:00
|
|
|
// Note: this file provides only the interface for the generic parseParameters function.
|
|
|
|
// The actual implementations for each concrete parameter type live in the cpp file.
|
|
|
|
|
2016-02-17 17:26:22 -05:00
|
|
|
namespace detail
|
|
|
|
{
|
2016-03-02 19:48:30 -05:00
|
|
|
template <typename T>
|
|
|
|
using is_parameter_t =
|
|
|
|
std::integral_constant<bool,
|
|
|
|
std::is_base_of<engine::api::BaseParameters, T>::value ||
|
|
|
|
std::is_same<engine::api::TileParameters, T>::value>;
|
2020-11-26 10:21:39 -05:00
|
|
|
} // namespace detail
|
2016-02-17 17:26:22 -05:00
|
|
|
|
2016-02-12 22:23:59 -05:00
|
|
|
// Starts parsing and iter and modifies it until iter == end or parsing failed
|
2016-02-17 17:26:22 -05:00
|
|
|
template <typename ParameterT,
|
|
|
|
typename std::enable_if<detail::is_parameter_t<ParameterT>::value, int>::type = 0>
|
2024-07-02 16:37:09 -04:00
|
|
|
std::optional<ParameterT> parseParameters(std::string::iterator &iter,
|
|
|
|
const std::string::iterator end);
|
2016-02-12 22:23:59 -05:00
|
|
|
|
2016-02-17 17:26:22 -05:00
|
|
|
// Copy on purpose because we need mutability
|
|
|
|
template <typename ParameterT,
|
|
|
|
typename std::enable_if<detail::is_parameter_t<ParameterT>::value, int>::type = 0>
|
2024-07-02 16:37:09 -04:00
|
|
|
std::optional<ParameterT> parseParameters(std::string options_string)
|
2016-02-12 22:23:59 -05:00
|
|
|
{
|
2016-02-23 15:23:13 -05:00
|
|
|
auto first = options_string.begin();
|
2016-02-17 17:26:22 -05:00
|
|
|
const auto last = options_string.end();
|
|
|
|
return parseParameters<ParameterT>(first, last);
|
2016-02-12 22:23:59 -05:00
|
|
|
}
|
|
|
|
|
2022-12-20 12:00:11 -05:00
|
|
|
} // namespace osrm::server::api
|
2016-02-12 22:23:59 -05:00
|
|
|
|
|
|
|
#endif
|