osrm-backend/include/server/api/parameters_parser.hpp

45 lines
1.5 KiB
C++
Raw Normal View History

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
#include <boost/optional/optional.hpp>
#include <type_traits>
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.
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>;
} // namespace detail
2016-02-12 22:23:59 -05:00
// Starts parsing and iter and modifies it until iter == end or parsing failed
template <typename ParameterT,
typename std::enable_if<detail::is_parameter_t<ParameterT>::value, int>::type = 0>
boost::optional<ParameterT> parseParameters(std::string::iterator &iter,
const std::string::iterator end);
2016-02-12 22:23:59 -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>
boost::optional<ParameterT> parseParameters(std::string options_string)
2016-02-12 22:23:59 -05:00
{
auto first = options_string.begin();
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