From a6cd0863bcfcbd5c62a4d0dfb5b1cb87227a0e61 Mon Sep 17 00:00:00 2001 From: karenzshea Date: Thu, 26 Jan 2017 08:37:00 -0500 Subject: [PATCH] store/accept individual annotations parameters in addition to bool --- include/engine/api/route_parameters.hpp | 28 +++++++++++++++++-- .../server/api/route_parameters_grammar.hpp | 22 +++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/include/engine/api/route_parameters.hpp b/include/engine/api/route_parameters.hpp index 039ba4384..77f543d9a 100644 --- a/include/engine/api/route_parameters.hpp +++ b/include/engine/api/route_parameters.hpp @@ -67,6 +67,14 @@ struct RouteParameters : public BaseParameters Full, False }; + enum class AnnotationsType + { + None = 0, + Duration = 1 << 1, + Nodes = 1 << 2, + Distance = 1 << 3, + All = Duration | Nodes | Distance + }; RouteParameters() = default; @@ -78,7 +86,7 @@ struct RouteParameters : public BaseParameters const boost::optional continue_straight_, Args... args_) : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, - annotations{false}, geometries{geometries_}, overview{overview_}, + 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. { @@ -94,7 +102,22 @@ struct RouteParameters : public BaseParameters const boost::optional continue_straight_, Args... args_) : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, - annotations{annotations_}, geometries{geometries_}, overview{overview_}, + annotations{annotations_}, annotations_type{annotations_ ? AnnotationsType::All : AnnotationsType::None}, geometries{geometries_}, overview{overview_}, + continue_straight{continue_straight_} + { + } + + // enum based implementation of annotations parameter + template + RouteParameters(const bool steps_, + const bool alternatives_, + const AnnotationsType annotations_, + const GeometriesType geometries_, + const OverviewType overview_, + const boost::optional continue_straight_, + Args... args_) + : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, + annotations_type{annotations_}, annotations{true}, geometries{geometries_}, overview{overview_}, continue_straight{continue_straight_} { } @@ -102,6 +125,7 @@ struct RouteParameters : public BaseParameters bool steps = false; bool alternatives = false; bool annotations = false; + AnnotationsType annotations_type = AnnotationsType::None; GeometriesType geometries = GeometriesType::Polyline; OverviewType overview = OverviewType::Simplified; boost::optional continue_straight; diff --git a/include/server/api/route_parameters_grammar.hpp b/include/server/api/route_parameters_grammar.hpp index deaa7a984..7c2610ed3 100644 --- a/include/server/api/route_parameters_grammar.hpp +++ b/include/server/api/route_parameters_grammar.hpp @@ -26,6 +26,15 @@ struct RouteParametersGrammar : public BaseParametersGrammar; + const auto add_annotation = [](engine::api::RouteParameters &route_parameters, + engine::api::RouteParameters::AnnotationsType &route_param) { + // bitflag each parameter + if (route_param) + { + route_parameters.annotations_ = route_parameters.annotations_ | route_param; + } + }; + RouteParametersGrammar() : RouteParametersGrammar(root_rule) { route_rule = @@ -50,17 +59,23 @@ struct RouteParametersGrammar : public BaseParametersGrammar