make annotations={true|false|(values)+} grammar
This commit is contained in:
parent
d28713b845
commit
2b00d92463
@ -42,11 +42,13 @@ struct RouteParametersGrammar : public BaseParametersGrammar<Iterator, Signature
|
||||
|
||||
RouteParametersGrammar(qi::rule<Iterator, Signature> &root_rule_) : BaseGrammar(root_rule_)
|
||||
{
|
||||
using AnnotationsType = engine::api::RouteParameters::AnnotationsType;
|
||||
|
||||
const auto add_annotation = [](engine::api::RouteParameters &route_parameters,
|
||||
engine::api::RouteParameters::AnnotationsType &route_param) {
|
||||
AnnotationsType route_param) {
|
||||
route_parameters.annotations_type = route_parameters.annotations_type | route_param;
|
||||
route_parameters.annotations = route_parameters.annotations_type !=
|
||||
engine::api::RouteParameters::AnnotationsType::None;
|
||||
route_parameters.annotations =
|
||||
route_parameters.annotations_type != AnnotationsType::None;
|
||||
};
|
||||
|
||||
geometries_type.add("geojson", engine::api::RouteParameters::GeometriesType::GeoJSON)(
|
||||
@ -57,13 +59,9 @@ struct RouteParametersGrammar : public BaseParametersGrammar<Iterator, Signature
|
||||
"full", engine::api::RouteParameters::OverviewType::Full)(
|
||||
"false", engine::api::RouteParameters::OverviewType::False);
|
||||
|
||||
annotations_type.add("true", engine::api::RouteParameters::AnnotationsType::All)(
|
||||
"false", engine::api::RouteParameters::AnnotationsType::None)(
|
||||
"duration", engine::api::RouteParameters::AnnotationsType::Duration)(
|
||||
"nodes", engine::api::RouteParameters::AnnotationsType::Nodes)(
|
||||
"distance", engine::api::RouteParameters::AnnotationsType::Distance)(
|
||||
"weight", engine::api::RouteParameters::AnnotationsType::Weight)(
|
||||
"datasources", engine::api::RouteParameters::AnnotationsType::Datasources);
|
||||
annotations_type.add("duration", AnnotationsType::Duration)(
|
||||
"nodes", AnnotationsType::Nodes)("distance", AnnotationsType::Distance)(
|
||||
"weight", AnnotationsType::Weight)("datasources", AnnotationsType::Datasources);
|
||||
|
||||
base_rule =
|
||||
BaseGrammar::base_rule(qi::_r1) |
|
||||
@ -75,7 +73,9 @@ struct RouteParametersGrammar : public BaseParametersGrammar<Iterator, Signature
|
||||
(qi::lit("overview=") >
|
||||
overview_type[ph::bind(&engine::api::RouteParameters::overview, qi::_r1) = qi::_1]) |
|
||||
(qi::lit("annotations=") >
|
||||
annotations_type[ph::bind(add_annotation, qi::_r1, qi::_1)] % ',');
|
||||
(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)] % ',')));
|
||||
|
||||
query_rule = BaseGrammar::query_rule(qi::_r1);
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ BOOST_AUTO_TEST_CASE(invalid_route_urls)
|
||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>(std::string{"1,2;3,"} + '\0'), 6);
|
||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?annotations=distances"), 28UL);
|
||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?annotations="), 20UL);
|
||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?annotations=true,false"), 24UL);
|
||||
BOOST_CHECK_EQUAL(
|
||||
testInvalidOptions<RouteParameters>("1,2;3,4?annotations=&overview=simplified"), 20UL);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user