From 709b4d6ef091d1883e2894f1bce99588679937d6 Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Wed, 23 Jan 2019 16:28:55 -0800 Subject: [PATCH] Cleanup. --- include/engine/api/base_api.hpp | 10 +-- include/engine/api/match_parameters.hpp | 13 ++-- include/engine/api/route_api.hpp | 6 +- include/engine/api/route_parameters.hpp | 68 ++++++++++++++++--- .../server/api/match_parameter_grammar.hpp | 10 ++- .../server/api/route_parameters_grammar.hpp | 8 +-- src/engine/plugins/match.cpp | 7 +- src/engine/plugins/viaroute.cpp | 6 +- 8 files changed, 85 insertions(+), 43 deletions(-) diff --git a/include/engine/api/base_api.hpp b/include/engine/api/base_api.hpp index 38c209cdb..e0c924348 100644 --- a/include/engine/api/base_api.hpp +++ b/include/engine/api/base_api.hpp @@ -31,10 +31,10 @@ class BaseAPI util::json::Array MakeWaypoints(const std::vector &segment_end_coordinates) const { BOOST_ASSERT(parameters.coordinates.size() > 0); - // BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1); + BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1); util::json::Array waypoints; - waypoints.values.resize(segment_end_coordinates.size() + 1); + waypoints.values.resize(parameters.coordinates.size()); waypoints.values[0] = MakeWaypoint(segment_end_coordinates.front().source_phantom); auto out_iter = std::next(waypoints.values.begin()); @@ -75,8 +75,8 @@ class BaseAPI const BaseParameters ¶meters; }; -} // namespace api -} // namespace engine -} // namespace osrm +} // ns api +} // ns engine +} // ns osrm #endif diff --git a/include/engine/api/match_parameters.hpp b/include/engine/api/match_parameters.hpp index 79ce84c55..b54076582 100644 --- a/include/engine/api/match_parameters.hpp +++ b/include/engine/api/match_parameters.hpp @@ -63,7 +63,7 @@ struct MatchParameters : public RouteParameters RouteParameters::GeometriesType::Polyline, RouteParameters::OverviewType::Simplified, {}), - gaps(GapsType::Split), tidy(false), waypoints() + gaps(GapsType::Split), tidy(false) { } @@ -79,24 +79,19 @@ struct MatchParameters : public RouteParameters bool tidy_, std::vector waypoints_, Args... args_) - : RouteParameters{std::forward(args_)...}, timestamps{std::move(timestamps_)}, - gaps(gaps_), tidy(tidy_), waypoints{std::move(waypoints_)} + : RouteParameters{std::forward(args_)..., waypoints_}, + timestamps{std::move(timestamps_)}, gaps(gaps_), tidy(tidy_) { } std::vector timestamps; GapsType gaps; bool tidy; - std::vector waypoints; bool IsValid() const { - const auto valid_waypoints = - std::all_of(waypoints.begin(), waypoints.end(), [this](const auto &w) { - return w < coordinates.size(); - }); return RouteParameters::IsValid() && - (timestamps.empty() || timestamps.size() == coordinates.size()) && valid_waypoints; + (timestamps.empty() || timestamps.size() == coordinates.size()); } }; } diff --git a/include/engine/api/route_api.hpp b/include/engine/api/route_api.hpp index 2251c5a87..a24277901 100644 --- a/include/engine/api/route_api.hpp +++ b/include/engine/api/route_api.hpp @@ -359,8 +359,8 @@ class RouteAPI : public BaseAPI const RouteParameters ¶meters; }; -} // namespace api -} // namespace engine -} // namespace osrm +} // ns api +} // ns engine +} // ns osrm #endif diff --git a/include/engine/api/route_parameters.hpp b/include/engine/api/route_parameters.hpp index 0a3fb4880..ba200050d 100644 --- a/include/engine/api/route_parameters.hpp +++ b/include/engine/api/route_parameters.hpp @@ -90,10 +90,16 @@ struct RouteParameters : public BaseParameters Args... args_) // Once we perfectly-forward `args` (see #2990) this constructor can delegate to the one // below. - : BaseParameters{std::forward(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_} + : BaseParameters{std::forward(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_}, + waypoints() { } @@ -109,7 +115,9 @@ struct RouteParameters : public BaseParameters : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_}, annotations_type{annotations_ ? AnnotationsType::All : AnnotationsType::None}, - geometries{geometries_}, overview{overview_}, continue_straight{continue_straight_} + geometries{geometries_}, overview{overview_}, continue_straight{continue_straight_}, + waypoints() + { } @@ -126,7 +134,43 @@ struct RouteParameters : public BaseParameters number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_ == AnnotationsType::None ? false : true}, annotations_type{annotations_}, geometries{geometries_}, overview{overview_}, - continue_straight{continue_straight_} + continue_straight{continue_straight_}, waypoints() + { + } + + // RouteParameters constructor adding the `waypoints` parameter + template + RouteParameters(const bool steps_, + const bool alternatives_, + const bool annotations_, + const GeometriesType geometries_, + const OverviewType overview_, + const boost::optional continue_straight_, + std::vector waypoints_, + const Args... args_) + : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, + number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_}, + annotations_type{annotations_ ? AnnotationsType::All : AnnotationsType::None}, + geometries{geometries_}, overview{overview_}, continue_straight{continue_straight_}, + waypoints{waypoints_} + { + } + + // RouteParameters constructor adding the `waypoints` parameter + template + RouteParameters(const bool steps_, + const bool alternatives_, + const AnnotationsType annotations_, + const GeometriesType geometries_, + const OverviewType overview_, + const boost::optional continue_straight_, + std::vector waypoints_, + Args... args_) + : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, + number_of_alternatives{alternatives_ ? 1u : 0u}, + annotations{annotations_ == AnnotationsType::None ? false : true}, + annotations_type{annotations_}, geometries{geometries_}, overview{overview_}, + continue_straight{continue_straight_}, waypoints{waypoints_} { } @@ -145,7 +189,11 @@ struct RouteParameters : public BaseParameters { const auto coordinates_ok = coordinates.size() >= 2; const auto base_params_ok = BaseParameters::IsValid(); - return coordinates_ok && base_params_ok; + const auto valid_waypoints = + std::all_of(waypoints.begin(), waypoints.end(), [this](const auto &w) { + return w < coordinates.size(); + }); + return coordinates_ok && base_params_ok && valid_waypoints; } }; @@ -169,8 +217,8 @@ inline RouteParameters::AnnotationsType operator|=(RouteParameters::AnnotationsT { return lhs = lhs | rhs; } -} // namespace api -} // namespace engine -} // namespace osrm +} // ns api +} // ns engine +} // ns osrm #endif diff --git a/include/server/api/match_parameter_grammar.hpp b/include/server/api/match_parameter_grammar.hpp index c87c1b44d..2d78cc0e0 100644 --- a/include/server/api/match_parameter_grammar.hpp +++ b/include/server/api/match_parameter_grammar.hpp @@ -18,7 +18,7 @@ namespace { namespace ph = boost::phoenix; namespace qi = boost::spirit::qi; -} // namespace +} template @@ -48,7 +48,6 @@ struct MatchParametersGrammar final : public RouteParametersGrammar -qi::lit(".json") > -('?' > (timestamps_rule(qi::_r1) | BaseGrammar::base_rule(qi::_r1) | - waypoints_rule(qi::_r1) | (qi::lit("gaps=") > gaps_type[ph::bind(&engine::api::MatchParameters::gaps, qi::_r1) = qi::_1]) | (qi::lit("tidy=") > @@ -59,13 +58,12 @@ struct MatchParametersGrammar final : public RouteParametersGrammar root_rule; qi::rule timestamps_rule; - qi::rule waypoints_rule; qi::rule size_t_; qi::symbols gaps_type; }; -} // namespace api -} // namespace server -} // namespace osrm +} +} +} #endif diff --git a/include/server/api/route_parameters_grammar.hpp b/include/server/api/route_parameters_grammar.hpp index 52a3ed607..21463f6ee 100644 --- a/include/server/api/route_parameters_grammar.hpp +++ b/include/server/api/route_parameters_grammar.hpp @@ -18,7 +18,7 @@ namespace { namespace ph = boost::phoenix; namespace qi = boost::spirit::qi; -} // namespace +} template @@ -113,8 +113,8 @@ struct RouteParametersGrammar : public BaseParametersGrammar overview_type; qi::symbols annotations_type; }; -} // namespace api -} // namespace server -} // namespace osrm +} +} +} #endif diff --git a/src/engine/plugins/match.cpp b/src/engine/plugins/match.cpp index 5b62c774a..54ad24231 100644 --- a/src/engine/plugins/match.cpp +++ b/src/engine/plugins/match.cpp @@ -209,6 +209,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, { return routing_algorithms::DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER; } + }); } @@ -316,6 +317,6 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, return Status::Ok; } -} // namespace plugins -} // namespace engine -} // namespace osrm +} +} +} diff --git a/src/engine/plugins/viaroute.cpp b/src/engine/plugins/viaroute.cpp index f7081f6bf..02407fe71 100644 --- a/src/engine/plugins/viaroute.cpp +++ b/src/engine/plugins/viaroute.cpp @@ -200,6 +200,6 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm return Status::Ok; } -} // namespace plugins -} // namespace engine -} // namespace osrm +} +} +}