Change qi::lit for qi::symbols for the sides parameter parser.
Refactor code : - Suppress StartSide Enum - Change Side Structure for Enum Signed-off-by: FILLAU Jean-Maxime <jean-maxime.fillau@mapotempo.com>
This commit is contained in:
		
							parent
							
								
									2de17f3fd0
								
							
						
					
					
						commit
						ec7934ea33
					
				| @ -714,14 +714,14 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade | ||||
|             input_coordinate, max_results, max_distance, bearing, bearing_range); | ||||
|     } | ||||
| 
 | ||||
|     std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( | ||||
|         const util::Coordinate input_coordinate, | ||||
|         const engine::SideValue side_value) const override final | ||||
|     std::pair<PhantomNode, PhantomNode> | ||||
|     NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, | ||||
|                                                       const engine::Side side) const override final | ||||
|     { | ||||
|         BOOST_ASSERT(m_geospatial_query.get()); | ||||
| 
 | ||||
|         return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent( | ||||
|             input_coordinate, side_value); | ||||
|             input_coordinate, side); | ||||
|     } | ||||
| 
 | ||||
|     std::pair<PhantomNode, PhantomNode> NearestPhantomNodeWithAlternativeFromBigComponent( | ||||
|  | ||||
| @ -120,7 +120,7 @@ class BaseDataFacade | ||||
| 
 | ||||
|     virtual std::pair<PhantomNode, PhantomNode> | ||||
|     NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, | ||||
|                                                       const engine::SideValue side_value) const = 0; | ||||
|                                                       const engine::Side side) const = 0; | ||||
|     virtual std::pair<PhantomNode, PhantomNode> | ||||
|     NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, | ||||
|                                                       const double max_distance) const = 0; | ||||
|  | ||||
| @ -212,19 +212,20 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery | ||||
|     // a second phantom node is return that is the nearest coordinate in a big component.
 | ||||
|     std::pair<PhantomNode, PhantomNode> | ||||
|     NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, | ||||
|                                                       const engine::SideValue side_value) const | ||||
|                                                       const engine::Side side) const | ||||
|     { | ||||
|         bool has_small_component = false; | ||||
|         bool has_big_component = false; | ||||
|         auto results = rtree.Nearest( | ||||
|             input_coordinate, | ||||
|             [this, &side_value, &input_coordinate, &has_big_component, &has_small_component](const CandidateSegment &segment) { | ||||
|             [this, &side, &input_coordinate, &has_big_component, &has_small_component]( | ||||
|                 const CandidateSegment &segment) { | ||||
|                 auto use_segment = | ||||
|                     (!has_small_component || (!has_big_component && !IsTinyComponent(segment))); | ||||
|                 auto use_directions = std::make_pair(use_segment, use_segment); | ||||
|                 bool isOnewaySegment = !(segment.data.forward_segment_id.enabled && | ||||
|                                          segment.data.reverse_segment_id.enabled); | ||||
|                 if (!isOnewaySegment && side_value != BOTH) | ||||
|                 if (!isOnewaySegment && side != BOTH) | ||||
|                 { | ||||
|                     // Check the counter clockwise
 | ||||
|                     //
 | ||||
| @ -241,8 +242,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery | ||||
|                     // if drive left
 | ||||
|                     // input_coordinate_is_at_right = !input_coordinate_is_at_right
 | ||||
| 
 | ||||
|                     // We reverse goCountrySide if side_value is OPPOSITE
 | ||||
|                     if (side_value == OPPOSITE) | ||||
|                     // We reverse goCountrySide if side is OPPOSITE
 | ||||
|                     if (side == OPPOSITE) | ||||
|                         input_coordinate_is_at_right = !input_coordinate_is_at_right; | ||||
| 
 | ||||
|                     // Apply the side.
 | ||||
|  | ||||
| @ -231,11 +231,11 @@ class BasePlugin | ||||
|         BOOST_ASSERT(parameters.IsValid()); | ||||
|         for (const auto i : util::irange<std::size_t>(0UL, parameters.coordinates.size())) | ||||
|         { | ||||
|             SideValue sideValue = engine::SideValue::BOTH; | ||||
|             Side side = engine::Side::BOTH; | ||||
|             // TODO init at SIDE for test
 | ||||
|             // SideValue sideValue = engine::SideValue::DEFAULT;
 | ||||
|             // SideValue side = engine::SideValue::DEFAULT;
 | ||||
|             if (use_sides && parameters.sides[i]) | ||||
|                 sideValue = parameters.sides[i]->side; | ||||
|                 side = parameters.sides[i].get(); | ||||
| 
 | ||||
|             if (use_hints && parameters.hints[i] && | ||||
|                 parameters.hints[i]->IsValid(parameters.coordinates[i], facade)) | ||||
| @ -277,7 +277,7 @@ class BasePlugin | ||||
|                 { | ||||
|                     phantom_node_pairs[i] = | ||||
|                         facade.NearestPhantomNodeWithAlternativeFromBigComponent( | ||||
|                             parameters.coordinates[i], sideValue); | ||||
|                             parameters.coordinates[i], side); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|  | ||||
| @ -28,56 +28,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
| #ifndef OSRM_ENGINE_SIDE_HPP | ||||
| #define OSRM_ENGINE_SIDE_HPP | ||||
| 
 | ||||
| #include <string> | ||||
| 
 | ||||
| namespace osrm | ||||
| { | ||||
| namespace engine | ||||
| { | ||||
| 
 | ||||
| enum SideValue | ||||
| enum Side | ||||
| { | ||||
|     DEFAULT, | ||||
|     OPPOSITE, | ||||
|     BOTH | ||||
| 
 | ||||
| }; | ||||
| 
 | ||||
| struct Side | ||||
| { | ||||
|     SideValue side; | ||||
|     static SideValue fromString(const std::string &str) | ||||
|     { | ||||
|         if (str == "d") | ||||
|             return DEFAULT; | ||||
|         else if (str == "o") | ||||
|             return OPPOSITE; | ||||
|         else | ||||
|             return BOTH; | ||||
|     } | ||||
|     static std::string toString(const Side &side) | ||||
|     { | ||||
|         switch(side.side) | ||||
|         { | ||||
|             case(DEFAULT) : | ||||
|               return "0"; | ||||
|             case(OPPOSITE) : | ||||
|               return "d"; | ||||
|             case(BOTH) : | ||||
|               return "b"; | ||||
|             default : | ||||
|               //TODO I don't know what to do here.
 | ||||
|               return "b"; | ||||
|         } | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| inline bool operator==(const Side lhs, const Side rhs) | ||||
| { | ||||
|     return lhs.side == rhs.side; | ||||
| } | ||||
| inline bool operator!=(const Side lhs, const Side rhs) { return !(lhs == rhs); } | ||||
| } | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
|  | ||||
| @ -99,16 +99,6 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature> | ||||
|                 base_parameters.bearings.push_back(std::move(bearing)); | ||||
|             }; | ||||
| 
 | ||||
|         const auto add_side = [](engine::api::BaseParameters &base_parameters, | ||||
|                                  const boost::optional<std::string> &side_string) { | ||||
|             boost::optional<engine::Side> side; | ||||
|             if (side_string) | ||||
|             { | ||||
|                 side = engine::Side{engine::Side::fromString(side_string.get())}; | ||||
|             } | ||||
|             base_parameters.sides.push_back(std::move(side)); | ||||
|         }; | ||||
| 
 | ||||
|         polyline_chars = qi::char_("a-zA-Z0-9_.--[]{}@?|\\%~`^"); | ||||
|         base64_char = qi::char_("a-zA-Z0-9--_="); | ||||
|         unlimited_rule = qi::lit("unlimited")[qi::_val = std::numeric_limits<double>::infinity()]; | ||||
| @ -159,13 +149,16 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature> | ||||
|             qi::lit("bearings=") > | ||||
|             (-(qi::short_ > ',' > qi::short_))[ph::bind(add_bearing, qi::_r1, qi::_1)] % ';'; | ||||
| 
 | ||||
|         sides_rule = qi::lit("sides=") > | ||||
|                      (-qi::as_string[qi::char_("a-zA")])[ph::bind(add_side, qi::_r1, qi::_1)] % ';'; | ||||
|         side_type.add("d", engine::Side::DEFAULT)("o", engine::Side::OPPOSITE)("b", engine::Side::BOTH); | ||||
|         sides_rule = | ||||
|             qi::lit("sides=") > | ||||
|             (-side_type % ';')[ph::bind(&engine::api::BaseParameters::sides, qi::_r1) = qi::_1]; | ||||
| 
 | ||||
|         base_rule = radiuses_rule(qi::_r1)   //
 | ||||
|                     | hints_rule(qi::_r1)    //
 | ||||
|                     | bearings_rule(qi::_r1) //
 | ||||
|                     | generate_hints_rule(qi::_r1) | sides_rule(qi::_r1); | ||||
|                     | generate_hints_rule(qi::_r1) | ||||
|                     | sides_rule(qi::_r1); | ||||
|     } | ||||
| 
 | ||||
|   protected: | ||||
| @ -176,9 +169,9 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature> | ||||
|     qi::rule<Iterator, Signature> bearings_rule; | ||||
|     qi::rule<Iterator, Signature> radiuses_rule; | ||||
|     qi::rule<Iterator, Signature> hints_rule; | ||||
|     qi::rule<Iterator, Signature> sides_rule; | ||||
| 
 | ||||
|     qi::rule<Iterator, Signature> generate_hints_rule; | ||||
|     qi::rule<Iterator, Signature> sides_rule; | ||||
| 
 | ||||
|     qi::rule<Iterator, osrm::engine::Bearing()> bearing_rule; | ||||
|     qi::rule<Iterator, osrm::util::Coordinate()> location_rule; | ||||
| @ -188,6 +181,8 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature> | ||||
|     qi::rule<Iterator, std::string()> polyline_chars; | ||||
|     qi::rule<Iterator, double()> unlimited_rule; | ||||
|     qi::real_parser<double, json_policy> double_; | ||||
| 
 | ||||
|     qi::symbols<char, engine::Side> side_type; | ||||
| }; | ||||
| } | ||||
| } | ||||
|  | ||||
| @ -146,9 +146,8 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade | ||||
|     } | ||||
| 
 | ||||
|     std::pair<engine::PhantomNode, engine::PhantomNode> | ||||
|     NearestPhantomNodeWithAlternativeFromBigComponent( | ||||
|         const util::Coordinate /*input_coordinate*/, | ||||
|         const engine::SideValue /*side_value*/) const override | ||||
|     NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/, | ||||
|                                                       const engine::Side /*side*/) const override | ||||
|     { | ||||
|         return {}; | ||||
|     } | ||||
|  | ||||
| @ -57,7 +57,7 @@ inline std::ostream &operator<<(std::ostream &out, Bearing bearing) | ||||
| 
 | ||||
| inline std::ostream &operator<<(std::ostream &out, Side side) | ||||
| { | ||||
|     out << Side::toString(side); | ||||
|     out << side; | ||||
|     return out; | ||||
| } | ||||
| } | ||||
|  | ||||
| @ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(invalid_route_urls) | ||||
|     BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&radiuses=foo"), | ||||
|                       32UL); | ||||
|     BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&sides=foo"), | ||||
|                       30UL); | ||||
|                       29UL); | ||||
|     BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&hints=foo"), | ||||
|                       29UL); | ||||
|     BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?overview=false&hints=;;; ;"), | ||||
| @ -400,10 +400,7 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) | ||||
|     BOOST_CHECK_EQUAL(result_17->annotations, true); | ||||
| 
 | ||||
|     std::vector<boost::optional<engine::Side>> sides_18 = { | ||||
|         boost::none, | ||||
|         engine::Side{engine::SideValue::DEFAULT}, | ||||
|         engine::Side{engine::SideValue::BOTH}, | ||||
|         engine::Side{engine::SideValue::OPPOSITE}, | ||||
|         boost::none, engine::Side::DEFAULT, engine::Side::BOTH, engine::Side::OPPOSITE, | ||||
|     }; | ||||
|     RouteParameters reference_18{false, | ||||
|                                  false, | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user