Add avoid parameter to the API
This commit is contained in:
parent
9c11197768
commit
58061a68c4
@ -81,6 +81,23 @@ struct RouteParameters : public BaseParameters
|
||||
|
||||
RouteParameters() = default;
|
||||
|
||||
template <typename... Args>
|
||||
RouteParameters(const bool steps_,
|
||||
const bool alternatives_,
|
||||
const GeometriesType geometries_,
|
||||
const OverviewType overview_,
|
||||
const boost::optional<bool> continue_straight_,
|
||||
std::vector<std::string> avoid_,
|
||||
Args... args_)
|
||||
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternatives{alternatives_},
|
||||
number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{false},
|
||||
annotations_type{AnnotationsType::None}, geometries{geometries_}, overview{overview_},
|
||||
continue_straight{continue_straight_}, avoid{std::move(avoid_)}
|
||||
// Once we perfectly-forward `args` (see #2990) this constructor can delegate to the one below.
|
||||
{
|
||||
}
|
||||
|
||||
// Without avoid flags
|
||||
template <typename... Args>
|
||||
RouteParameters(const bool steps_,
|
||||
const bool alternatives_,
|
||||
@ -92,7 +109,6 @@ struct RouteParameters : public BaseParameters
|
||||
number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{false},
|
||||
annotations_type{AnnotationsType::None}, geometries{geometries_}, overview{overview_},
|
||||
continue_straight{continue_straight_}
|
||||
// Once we perfectly-forward `args` (see #2990) this constructor can delegate to the one below.
|
||||
{
|
||||
}
|
||||
|
||||
@ -138,6 +154,7 @@ struct RouteParameters : public BaseParameters
|
||||
GeometriesType geometries = GeometriesType::Polyline;
|
||||
OverviewType overview = OverviewType::Simplified;
|
||||
boost::optional<bool> continue_straight;
|
||||
std::vector<std::string> avoid;
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
|
@ -70,6 +70,8 @@ struct RouteParametersGrammar : public BaseParametersGrammar<Iterator, Signature
|
||||
"distance", AnnotationsType::Distance)("weight", AnnotationsType::Weight)(
|
||||
"datasources", AnnotationsType::Datasources)("speed", AnnotationsType::Speed);
|
||||
|
||||
avoid_rule = qi::lit("avoid=") > (qi::as_string[+qi::char_("a-zA-Z")] % ',');
|
||||
|
||||
base_rule =
|
||||
BaseGrammar::base_rule(qi::_r1) |
|
||||
(qi::lit("steps=") >
|
||||
@ -82,7 +84,8 @@ struct RouteParametersGrammar : public BaseParametersGrammar<Iterator, Signature
|
||||
(qi::lit("annotations=") >
|
||||
(qi::lit("true")[ph::bind(add_annotation, qi::_r1, AnnotationsType::All)] |
|
||||
qi::lit("false")[ph::bind(add_annotation, qi::_r1, AnnotationsType::None)] |
|
||||
(annotations_type[ph::bind(add_annotation, qi::_r1, qi::_1)] % ',')));
|
||||
(annotations_type[ph::bind(add_annotation, qi::_r1, qi::_1)] % ','))) |
|
||||
avoid_rule[ph::bind(&engine::api::RouteParameters::avoid, qi::_r1) = qi::_1];
|
||||
|
||||
query_rule = BaseGrammar::query_rule(qi::_r1);
|
||||
}
|
||||
@ -94,6 +97,7 @@ struct RouteParametersGrammar : public BaseParametersGrammar<Iterator, Signature
|
||||
private:
|
||||
qi::rule<Iterator, Signature> root_rule;
|
||||
qi::rule<Iterator, Signature> route_rule;
|
||||
qi::rule<Iterator, std::vector<std::string>()> avoid_rule;
|
||||
|
||||
qi::symbols<char, engine::api::RouteParameters::GeometriesType> geometries_type;
|
||||
qi::symbols<char, engine::api::RouteParameters::OverviewType> overview_type;
|
||||
|
@ -471,6 +471,26 @@ BOOST_AUTO_TEST_CASE(valid_route_urls)
|
||||
CHECK_EQUAL_RANGE(reference_20.approaches, result_20->approaches);
|
||||
CHECK_EQUAL_RANGE(reference_20.coordinates, result_20->coordinates);
|
||||
CHECK_EQUAL_RANGE(reference_20.hints, result_20->hints);
|
||||
|
||||
// avoid flags
|
||||
RouteParameters reference_21{};
|
||||
reference_21.avoid = {"ferry", "motorway"};
|
||||
reference_21.coordinates = coords_1;
|
||||
auto result_21 = parseParameters<RouteParameters>("1,2;3,4?avoid=ferry,motorway");
|
||||
BOOST_CHECK(result_21);
|
||||
BOOST_CHECK_EQUAL(reference_21.steps, result_21->steps);
|
||||
BOOST_CHECK_EQUAL(reference_21.alternatives, result_21->alternatives);
|
||||
BOOST_CHECK_EQUAL(reference_21.number_of_alternatives, result_21->number_of_alternatives);
|
||||
BOOST_CHECK_EQUAL(reference_21.geometries, result_21->geometries);
|
||||
BOOST_CHECK_EQUAL(reference_21.annotations, result_21->annotations);
|
||||
BOOST_CHECK_EQUAL(reference_21.overview, result_21->overview);
|
||||
BOOST_CHECK_EQUAL(reference_21.continue_straight, result_21->continue_straight);
|
||||
CHECK_EQUAL_RANGE(reference_21.bearings, result_21->bearings);
|
||||
CHECK_EQUAL_RANGE(reference_21.radiuses, result_21->radiuses);
|
||||
CHECK_EQUAL_RANGE(reference_21.approaches, result_21->approaches);
|
||||
CHECK_EQUAL_RANGE(reference_21.coordinates, result_21->coordinates);
|
||||
CHECK_EQUAL_RANGE(reference_21.hints, result_21->hints);
|
||||
CHECK_EQUAL_RANGE(reference_21.avoid, result_21->avoid);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(valid_table_urls)
|
||||
|
Loading…
Reference in New Issue
Block a user