Add avoid parameter to the API

This commit is contained in:
Patrick Niklaus
2017-07-20 23:54:26 +00:00
committed by Patrick Niklaus
parent 9c11197768
commit 58061a68c4
3 changed files with 43 additions and 2 deletions
+18 -1
View File
@@ -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;