Compare commits

...

8 Commits

Author SHA1 Message Date
Siarhei Fedartsou c8d03e4c3b wip 2024-05-23 19:56:27 +02:00
Siarhei Fedartsou 11a5804d36 wip 2024-05-22 22:42:43 +02:00
Siarhei Fedartsou 14bdf07464 wip 2024-05-22 20:54:19 +02:00
Siarhei Fedartsou c2c0d3e565 wip 2024-05-22 20:50:17 +02:00
Siarhei Fedartsou 75a5d6d586 wip 2024-05-22 20:32:46 +02:00
Siarhei Fedartsou 3552443896 wip 2024-05-22 18:07:59 +02:00
Siarhei Fedartsou 7766a0f42b Use Boost X3 for URL parsing 2024-05-22 18:05:07 +02:00
Mugr Rex efe6840d08 Replace boost::optional with std::optional (#6611) 2024-05-22 14:58:07 +02:00
28 changed files with 160 additions and 170 deletions
+1
View File
@@ -19,6 +19,7 @@
- NodeJS:
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
- Misc:
- CHANGED: Partial fix migration from boost::optional to std::optional [#6551](https://github.com/Project-OSRM/osrm-backend/issues/6551)
- CHANGED: Update Conan Boost version to 1.85.0. [#6868](https://github.com/Project-OSRM/osrm-backend/pull/6868)
- FIXED: Fix an error in a RouteParameters AnnotationsType operator overload. [#6646](https://github.com/Project-OSRM/osrm-backend/pull/6646)
- ADDED: Add support for "unlimited" to be passed as a value for the default-radius and max-matching-radius flags. [#6599](https://github.com/Project-OSRM/osrm-backend/pull/6599)
+1 -1
View File
@@ -359,7 +359,7 @@ if(ENABLE_CONAN)
KEEP_RPATHS
NO_OUTPUT_DIRS
OPTIONS boost:filesystem_version=3 # https://stackoverflow.com/questions/73392648/error-with-boost-filesystem-version-in-cmake
onetbb:shared=${TBB_SHARED}
# onetbb:shared=${TBB_SHARED}
boost:without_stacktrace=True # Apple Silicon cross-compilation fails without it
BUILD missing
)
+2
View File
@@ -12,6 +12,8 @@
#include "osrm/coordinate.hpp"
#include <boost/optional.hpp>
#include <algorithm>
#include <cmath>
#include <iterator>
@@ -122,7 +122,7 @@ void routingStep(const DataFacade<Algorithm> &facade,
const EdgeWeight new_weight = reverseHeapNode->weight + heapNode.weight;
if (new_weight < upper_bound)
{
if (shouldForceStep(force_step_nodes, heapNode, reverseHeapNode.get()) ||
if (shouldForceStep(force_step_nodes, heapNode, *reverseHeapNode) ||
// in this case we are looking at a bi-directional way where the source
// and target phantom are on the same edge based node
new_weight < EdgeWeight{0})
@@ -408,7 +408,7 @@ void routingStep(const DataFacade<Algorithm> &facade,
auto reverse_weight = reverseHeapNode->weight;
auto path_weight = weight + reverse_weight;
if (!shouldForceStep(force_step_nodes, heapNode, reverseHeapNode.get()) &&
if (!shouldForceStep(force_step_nodes, heapNode, *reverseHeapNode) &&
(path_weight >= EdgeWeight{0}) && (path_weight < path_upper_bound))
{
middle_node = heapNode.node;
@@ -11,8 +11,8 @@
#include "util/typedefs.hpp"
#include <boost/assert.hpp>
#include <boost/optional.hpp>
#include <cstdint>
#include <optional>
#include <utility>
namespace osrm::extractor::intersection
@@ -42,10 +42,10 @@ class NodeBasedGraphWalker
* selector not provinding any further edge to traverse)
*/
template <class accumulator_type, class selector_type>
boost::optional<std::pair<NodeID, EdgeID>> TraverseRoad(NodeID starting_at_node_id,
EdgeID following_edge_id,
accumulator_type &accumulator,
const selector_type &selector) const;
std::optional<std::pair<NodeID, EdgeID>> TraverseRoad(NodeID starting_at_node_id,
EdgeID following_edge_id,
accumulator_type &accumulator,
const selector_type &selector) const;
private:
const util::NodeBasedDynamicGraph &node_based_graph;
@@ -111,11 +111,11 @@ struct SelectRoadByNameOnlyChoiceAndStraightness
* traversal. If no such edge is found, return {} is allowed. Usually you want to choose some
* form of obious turn to follow.
*/
boost::optional<EdgeID> operator()(const NodeID nid,
const EdgeID via_edge_id,
const IntersectionView &intersection,
const util::NodeBasedDynamicGraph &node_based_graph,
const EdgeBasedNodeDataContainer &node_data_container) const;
std::optional<EdgeID> operator()(const NodeID nid,
const EdgeID via_edge_id,
const IntersectionView &intersection,
const util::NodeBasedDynamicGraph &node_based_graph,
const EdgeBasedNodeDataContainer &node_data_container) const;
private:
const NameID desired_name_id;
@@ -138,11 +138,11 @@ struct SelectStraightmostRoadByNameAndOnlyChoice
* traversal. If no such edge is found, return {} is allowed. Usually you want to choose some
* form of obious turn to follow.
*/
boost::optional<EdgeID> operator()(const NodeID nid,
const EdgeID via_edge_id,
const IntersectionView &intersection,
const util::NodeBasedDynamicGraph &node_based_graph,
const EdgeBasedNodeDataContainer &node_data_container) const;
std::optional<EdgeID> operator()(const NodeID nid,
const EdgeID via_edge_id,
const IntersectionView &intersection,
const util::NodeBasedDynamicGraph &node_based_graph,
const EdgeBasedNodeDataContainer &node_data_container) const;
private:
const NameID desired_name_id;
@@ -187,7 +187,7 @@ struct IntersectionFinderAccumulator
};
template <class accumulator_type, class selector_type>
boost::optional<std::pair<NodeID, EdgeID>>
std::optional<std::pair<NodeID, EdgeID>>
NodeBasedGraphWalker::TraverseRoad(NodeID current_node_id,
EdgeID current_edge_id,
accumulator_type &accumulator,
@@ -254,19 +254,19 @@ NodeBasedGraphWalker::TraverseRoad(NodeID current_node_id,
struct SkipTrafficSignalBarrierRoadSelector
{
boost::optional<EdgeID> operator()(const NodeID,
const EdgeID,
const IntersectionView &intersection,
const util::NodeBasedDynamicGraph &,
const EdgeBasedNodeDataContainer &) const
std::optional<EdgeID> operator()(const NodeID,
const EdgeID,
const IntersectionView &intersection,
const util::NodeBasedDynamicGraph &,
const EdgeBasedNodeDataContainer &) const
{
if (intersection.isTrafficSignalOrBarrier())
{
return boost::make_optional(intersection[1].eid);
return std::make_optional(intersection[1].eid);
}
else
{
return boost::none;
return std::nullopt;
}
}
};
@@ -3,7 +3,7 @@
#include "maneuver_override.hpp"
#include <boost/optional.hpp>
#include <optional>
#include <string>
#include <vector>
@@ -55,7 +55,7 @@ class ManeuverOverrideRelationParser
{
public:
ManeuverOverrideRelationParser();
boost::optional<InputManeuverOverride> TryParse(const osmium::Relation &relation) const;
std::optional<InputManeuverOverride> TryParse(const osmium::Relation &relation) const;
};
} // namespace osrm::extractor
+2 -2
View File
@@ -7,11 +7,11 @@
#include <boost/assert.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/optional.hpp>
#include <algorithm>
#include <array>
#include <cstdint>
#include <optional>
namespace osrm::extractor
{
@@ -80,7 +80,7 @@ struct ProfileProperties
}
// Check if this classes are excludable
boost::optional<std::size_t> ClassesAreExcludable(ClassData classes) const
std::optional<std::size_t> ClassesAreExcludable(ClassData classes) const
{
auto iter = std::find(excludable_classes.begin(), excludable_classes.end(), classes);
if (iter != excludable_classes.end())
+2 -3
View File
@@ -15,11 +15,10 @@
#include <algorithm>
#include <cstddef>
#include <optional>
#include <utility>
#include <vector>
#include <boost/optional.hpp>
namespace osrm::guidance
{
@@ -129,7 +128,7 @@ class IntersectionHandler
// ^ via
//
// For this scenario returns intersection at `b` and `b`.
boost::optional<IntersectionHandler::IntersectionViewAndNode>
std::optional<IntersectionHandler::IntersectionViewAndNode>
getNextIntersection(const NodeID at, const EdgeID via) const;
bool isSameName(const EdgeID source_edge_id, const EdgeID target_edge_id) const;
+4 -5
View File
@@ -9,10 +9,9 @@
#include "util/node_based_graph.hpp"
#include <optional>
#include <vector>
#include <boost/optional.hpp>
namespace osrm::guidance
{
@@ -43,9 +42,9 @@ class SliproadHandler final : public IntersectionHandler
Intersection intersection) const override final;
private:
boost::optional<std::size_t> getObviousIndexWithSliproads(const EdgeID from,
const Intersection &intersection,
const NodeID at) const;
std::optional<std::size_t> getObviousIndexWithSliproads(const EdgeID from,
const Intersection &intersection,
const NodeID at) const;
// Next intersection from `start` onto `onto` is too far away for a Siproad scenario
bool nextIntersectionIsTooFarAway(const NodeID start, const EdgeID onto) const;
+3 -4
View File
@@ -11,9 +11,8 @@
#include "util/attributes.hpp"
#include "util/node_based_graph.hpp"
#include <boost/optional.hpp>
#include <cstddef>
#include <optional>
#include <utility>
#include <vector>
@@ -72,7 +71,7 @@ class TurnHandler final : public IntersectionHandler
bool hasObvious(const EdgeID &via_edge, const Fork &fork) const;
boost::optional<Fork> findForkCandidatesByGeometry(Intersection &intersection) const;
std::optional<Fork> findForkCandidatesByGeometry(Intersection &intersection) const;
bool isCompatibleByRoadClass(const Intersection &intersection, const Fork fork) const;
@@ -96,7 +95,7 @@ class TurnHandler final : public IntersectionHandler
handleDistinctConflict(const EdgeID via_edge, ConnectedRoad &left, ConnectedRoad &right) const;
// Classification
boost::optional<Fork> findFork(const EdgeID via_edge, Intersection &intersection) const;
std::optional<Fork> findFork(const EdgeID via_edge, Intersection &intersection) const;
OSRM_ATTR_WARN_UNUSED
Intersection assignLeftTurns(const EdgeID via_edge,
+1 -1
View File
@@ -39,7 +39,7 @@ template <typename Key, typename Value> struct CSVFilesParser
{
}
// Operator returns a lambda function that maps input Key to boost::optional<Value>.
// Operator returns a lambda function that maps input Key to std::optional<Value>.
auto operator()(const std::vector<std::string> &csv_filenames) const
{
try
+4 -5
View File
@@ -3,8 +3,7 @@
#include "util/typedefs.hpp"
#include <boost/optional.hpp>
#include <optional>
#include <vector>
namespace osrm::updater
@@ -12,9 +11,9 @@ namespace osrm::updater
template <typename Key, typename Value> struct LookupTable
{
boost::optional<Value> operator()(const Key &key) const
std::optional<Value> operator()(const Key &key) const
{
using Result = boost::optional<Value>;
using Result = std::optional<Value>;
const auto it =
std::lower_bound(lookup.begin(),
lookup.end(),
@@ -50,7 +49,7 @@ struct SpeedSource final
{
SpeedSource() : speed(0.), rate() {}
double speed;
boost::optional<double> rate;
std::optional<double> rate;
std::uint8_t source;
};
+4 -4
View File
@@ -4,11 +4,11 @@
#include "util/coordinate.hpp"
#include <boost/math/constants/constants.hpp>
#include <boost/optional.hpp>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <optional>
#include <utility>
#include <vector>
@@ -109,9 +109,9 @@ double bearing(const Coordinate first_coordinate, const Coordinate second_coordi
double computeAngle(const Coordinate first, const Coordinate second, const Coordinate third);
// find the center of a circle through three coordinates
boost::optional<Coordinate> circleCenter(const Coordinate first_coordinate,
const Coordinate second_coordinate,
const Coordinate third_coordinate);
std::optional<Coordinate> circleCenter(const Coordinate first_coordinate,
const Coordinate second_coordinate,
const Coordinate third_coordinate);
// find the radius of a circle through three coordinates
double circleRadius(const Coordinate first_coordinate,
+5 -6
View File
@@ -1,6 +1,7 @@
#ifndef OSRM_GEOJSON_DEBUG_POLICIES
#define OSRM_GEOJSON_DEBUG_POLICIES
#include <optional>
#include <vector>
#include "extractor/query_node.hpp"
@@ -9,8 +10,6 @@
#include "util/node_based_graph.hpp"
#include "util/typedefs.hpp"
#include <boost/optional.hpp>
namespace osrm::util
{
@@ -20,7 +19,7 @@ struct NodeIdVectorToLineString
// converts a vector of node ids into a linestring geojson feature
util::json::Object operator()(const std::vector<NodeID> &node_ids,
const boost::optional<json::Object> &properties = {}) const;
const std::optional<json::Object> &properties = {}) const;
const std::vector<util::Coordinate> &node_coordinates;
};
@@ -29,7 +28,7 @@ struct CoordinateVectorToLineString
{
// converts a vector of node ids into a linestring geojson feature
util::json::Object operator()(const std::vector<util::Coordinate> &coordinates,
const boost::optional<json::Object> &properties = {}) const;
const std::optional<json::Object> &properties = {}) const;
};
struct NodeIdVectorToMultiPoint
@@ -38,7 +37,7 @@ struct NodeIdVectorToMultiPoint
// converts a vector of node ids into a linestring geojson feature
util::json::Object operator()(const std::vector<NodeID> &node_ids,
const boost::optional<json::Object> &properties = {}) const;
const std::optional<json::Object> &properties = {}) const;
const std::vector<util::Coordinate> &node_coordinates;
};
@@ -47,7 +46,7 @@ struct CoordinateVectorToMultiPoint
{
// converts a vector of node ids into a linestring geojson feature
util::json::Object operator()(const std::vector<util::Coordinate> &coordinates,
const boost::optional<json::Object> &properties = {}) const;
const std::optional<json::Object> &properties = {}) const;
};
} // namespace osrm::util
@@ -7,8 +7,7 @@
#include <algorithm>
#include <iterator>
#include <boost/optional.hpp>
#include <optional>
namespace osrm::util
{
@@ -84,7 +83,7 @@ struct NodeIdToCoordinate
inline util::json::Object makeFeature(std::string type,
util::json::Array coordinates,
const boost::optional<util::json::Object> &properties = {})
const std::optional<util::json::Object> &properties = {})
{
util::json::Object result;
result.values["type"] = "Feature";
+7 -7
View File
@@ -3,12 +3,12 @@
#include <boost/assert.hpp>
#include <boost/heap/d_ary_heap.hpp>
#include <boost/optional.hpp>
#include <algorithm>
#include <cstdint>
#include <limits>
#include <map>
#include <optional>
#include <unordered_map>
#include <vector>
@@ -290,26 +290,26 @@ class QueryHeap
return inserted_nodes[index].node == node;
}
boost::optional<HeapNode &> GetHeapNodeIfWasInserted(const NodeID node)
HeapNode *GetHeapNodeIfWasInserted(const NodeID node)
{
const auto index = node_index.peek_index(node);
if (index >= static_cast<decltype(index)>(inserted_nodes.size()) ||
inserted_nodes[index].node != node)
{
return {};
return nullptr;
}
return inserted_nodes[index];
return &inserted_nodes[index];
}
boost::optional<const HeapNode &> GetHeapNodeIfWasInserted(const NodeID node) const
const HeapNode *GetHeapNodeIfWasInserted(const NodeID node) const
{
const auto index = node_index.peek_index(node);
if (index >= static_cast<decltype(index)>(inserted_nodes.size()) ||
inserted_nodes[index].node != node)
{
return {};
return nullptr;
}
return inserted_nodes[index];
return &inserted_nodes[index];
}
NodeID Min() const
+2 -2
View File
@@ -6,11 +6,11 @@
#include <boost/filesystem/path.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <boost/optional.hpp>
#include <rapidjson/document.h>
#include <chrono>
#include <optional>
namespace osrm::updater
{
@@ -34,7 +34,7 @@ class Timezoner
Timezoner(const char geojson[], std::time_t utc_time_now);
Timezoner(const boost::filesystem::path &tz_shapes_filename, std::time_t utc_time_now);
boost::optional<struct tm> operator()(const point_t &point) const;
std::optional<struct tm> operator()(const point_t &point) const;
private:
void LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t utc_time);
@@ -66,7 +66,7 @@ SelectRoadByNameOnlyChoiceAndStraightness::SelectRoadByNameOnlyChoiceAndStraight
{
}
boost::optional<EdgeID> SelectRoadByNameOnlyChoiceAndStraightness::operator()(
std::optional<EdgeID> SelectRoadByNameOnlyChoiceAndStraightness::operator()(
const NodeID /*nid*/,
const EdgeID /*via_edge_id*/,
const IntersectionView &intersection,
@@ -118,7 +118,7 @@ SelectStraightmostRoadByNameAndOnlyChoice::SelectStraightmostRoadByNameAndOnlyCh
{
}
boost::optional<EdgeID> SelectStraightmostRoadByNameAndOnlyChoice::operator()(
std::optional<EdgeID> SelectStraightmostRoadByNameAndOnlyChoice::operator()(
const NodeID /*nid*/,
const EdgeID /*via_edge_id*/,
const IntersectionView &intersection,
@@ -241,7 +241,7 @@ boost::optional<EdgeID> SelectStraightmostRoadByNameAndOnlyChoice::operator()(
return {};
}
return is_only_choice_with_same_name ? boost::optional<EdgeID>(min_element->eid) : boost::none;
return is_only_choice_with_same_name ? std::optional<EdgeID>(min_element->eid) : std::nullopt;
}
// ---------------------------------------------------------------------------------
@@ -1,9 +1,9 @@
#include "extractor/maneuver_override_relation_parser.hpp"
#include "extractor/maneuver_override.hpp"
#include <boost/optional/optional.hpp>
#include <boost/ref.hpp>
#include <optional>
#include <osmium/osm.hpp>
#include <osmium/tags/filter.hpp>
#include <osmium/tags/taglist.hpp>
@@ -21,7 +21,7 @@ ManeuverOverrideRelationParser::ManeuverOverrideRelationParser() {}
* into an InputManeuverOverride object, if the relation is considered
* valid (i.e. has the minimum tags we expect).
*/
boost::optional<InputManeuverOverride>
std::optional<InputManeuverOverride>
ManeuverOverrideRelationParser::TryParse(const osmium::Relation &relation) const
{
@@ -35,7 +35,7 @@ ManeuverOverrideRelationParser::TryParse(const osmium::Relation &relation) const
if (osmium::tags::match_none_of(tag_list, filter))
// if it's not a maneuver, continue;
{
return boost::none;
return std::nullopt;
}
// we pretend every restriction is a conditional restriction. If we do not find any restriction,
@@ -130,7 +130,7 @@ ManeuverOverrideRelationParser::TryParse(const osmium::Relation &relation) const
}
else
{
return boost::none;
return std::nullopt;
}
return maneuver_override;
}
+4 -5
View File
@@ -427,7 +427,7 @@ void IntersectionHandler::assignTrivialTurns(const EdgeID via_eid,
}
}
boost::optional<IntersectionHandler::IntersectionViewAndNode>
std::optional<IntersectionHandler::IntersectionViewAndNode>
IntersectionHandler::getNextIntersection(const NodeID at, const EdgeID via) const
{
// We use the intersection generator to jump over traffic signals, barriers. The intersection
@@ -450,7 +450,7 @@ IntersectionHandler::getNextIntersection(const NodeID at, const EdgeID via) cons
if (intersection_parameters.node == SPECIAL_NODEID ||
intersection_parameters.edge == SPECIAL_EDGEID)
{
return boost::none;
return std::nullopt;
}
auto intersection = extractor::intersection::getConnectedRoads<false>(node_based_graph,
@@ -465,11 +465,10 @@ IntersectionHandler::getNextIntersection(const NodeID at, const EdgeID via) cons
if (intersection.size() <= 2 || intersection.isTrafficSignalOrBarrier())
{
return boost::none;
return std::nullopt;
}
return boost::make_optional(
IntersectionViewAndNode{std::move(intersection), intersection_node});
return std::make_optional(IntersectionViewAndNode{std::move(intersection), intersection_node});
}
bool IntersectionHandler::isSameName(const EdgeID source_edge_id, const EdgeID target_edge_id) const
+9 -9
View File
@@ -634,7 +634,7 @@ Intersection SliproadHandler::operator()(const NodeID /*nid*/,
// Implementation details
boost::optional<std::size_t> SliproadHandler::getObviousIndexWithSliproads(
std::optional<std::size_t> SliproadHandler::getObviousIndexWithSliproads(
const EdgeID from, const Intersection &intersection, const NodeID at) const
{
BOOST_ASSERT(from != SPECIAL_EDGEID);
@@ -645,14 +645,14 @@ boost::optional<std::size_t> SliproadHandler::getObviousIndexWithSliproads(
if (index != 0)
{
return boost::make_optional(index);
return std::make_optional(index);
}
// Otherwise check if the road is forking into two and one of them is a Sliproad;
// then the non-Sliproad is the obvious one.
if (intersection.size() != 3)
{
return boost::none;
return std::nullopt;
}
const auto forking = intersection[1].instruction.type == TurnType::Fork &&
@@ -660,7 +660,7 @@ boost::optional<std::size_t> SliproadHandler::getObviousIndexWithSliproads(
if (!forking)
{
return boost::none;
return std::nullopt;
}
const auto first = getNextIntersection(at, intersection.getRightmostRoad().eid);
@@ -668,27 +668,27 @@ boost::optional<std::size_t> SliproadHandler::getObviousIndexWithSliproads(
if (!first || !second)
{
return boost::none;
return std::nullopt;
}
if (first->intersection.isDeadEnd() || second->intersection.isDeadEnd())
{
return boost::none;
return std::nullopt;
}
// In case of loops at the end of the road, we will arrive back at the intersection
// itself. If that is the case, the road is obviously not a sliproad.
if (canBeTargetOfSliproad(first->intersection) && at != second->node)
{
return boost::make_optional(std::size_t{2});
return std::make_optional(std::size_t{2});
}
if (canBeTargetOfSliproad(second->intersection) && at != first->node)
{
return boost::make_optional(std::size_t{1});
return std::make_optional(std::size_t{1});
}
return boost::none;
return std::nullopt;
}
bool SliproadHandler::nextIntersectionIsTooFarAway(const NodeID start, const EdgeID onto) const
+6 -6
View File
@@ -6,10 +6,10 @@
#include <algorithm>
#include <limits>
#include <optional>
#include <utility>
#include <boost/assert.hpp>
#include <boost/optional.hpp>
using osrm::util::angularDeviation;
@@ -590,7 +590,7 @@ Intersection TurnHandler::assignRightTurns(const EdgeID via_edge,
}
// finds a fork candidate by just looking at the geometry and angle of an intersection
boost::optional<TurnHandler::Fork>
std::optional<TurnHandler::Fork>
TurnHandler::findForkCandidatesByGeometry(Intersection &intersection) const
{
if (intersection.size() >= 3)
@@ -647,7 +647,7 @@ TurnHandler::findForkCandidatesByGeometry(Intersection &intersection) const
}
}
}
return boost::none;
return std::nullopt;
}
// check if the fork candidates (all roads between left and right) and the
@@ -695,8 +695,8 @@ bool TurnHandler::isCompatibleByRoadClass(const Intersection &intersection, cons
// Checks whether a three-way-intersection coming from `via_edge` is a fork
// with `intersection` as described as in #IntersectionExplanation@intersection_handler.hpp
boost::optional<TurnHandler::Fork> TurnHandler::findFork(const EdgeID via_edge,
Intersection &intersection) const
std::optional<TurnHandler::Fork> TurnHandler::findFork(const EdgeID via_edge,
Intersection &intersection) const
{
auto fork = findForkCandidatesByGeometry(intersection);
if (fork)
@@ -740,7 +740,7 @@ boost::optional<TurnHandler::Fork> TurnHandler::findFork(const EdgeID via_edge,
}
}
return boost::none;
return std::nullopt;
}
void TurnHandler::handleDistinctConflict(const EdgeID via_edge,
+45 -61
View File
@@ -2,88 +2,72 @@
#include "engine/polyline_compressor.hpp"
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/phoenix.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/repository/include/qi_iter_pos.hpp>
#include <boost/optional.hpp>
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
#include <boost/spirit/home/x3/support/utility/annotate_on_success.hpp>
#include <iostream>
#include <sstream>
#include <string>
#include <type_traits>
BOOST_FUSION_ADAPT_STRUCT(osrm::server::api::ParsedURL,
(std::string, service)(unsigned, version)(std::string,
profile)(std::string, query))
// Keep impl. TU local
namespace
{
namespace ph = boost::phoenix;
namespace qi = boost::spirit::qi;
template <typename Iterator, typename Into> //
struct URLParser final : qi::grammar<Iterator, Into>
{
URLParser() : URLParser::base_type(start)
{
using boost::spirit::repository::qi::iter_pos;
identifier = qi::char_("a-zA-Z0-9_.~:-");
percent_encoding =
qi::char_('%') > qi::uint_parser<unsigned char, 16, 2, 2>()[qi::_val = qi::_1];
polyline_chars = qi::char_("a-zA-Z0-9_[]{}@?|\\~`^") | percent_encoding;
all_chars = polyline_chars | qi::char_("=,;:&().-");
service = +identifier;
version = qi::uint_;
profile = +identifier;
query = +all_chars;
// Example input: /route/v1/driving/7.416351,43.731205;7.420363,43.736189
start = qi::lit('/') > service > qi::lit('/') > qi::lit('v') > version > qi::lit('/') >
profile > qi::lit('/') >
qi::omit[iter_pos[ph::bind(&osrm::server::api::ParsedURL::prefix_length, qi::_val) =
qi::_1 - qi::_r1]] > query;
BOOST_SPIRIT_DEBUG_NODES((start)(service)(version)(profile)(query))
}
qi::rule<Iterator, Into> start;
qi::rule<Iterator, std::string()> service;
qi::rule<Iterator, unsigned()> version;
qi::rule<Iterator, std::string()> profile;
qi::rule<Iterator, std::string()> query;
qi::rule<Iterator, char()> identifier;
qi::rule<Iterator, char()> all_chars;
qi::rule<Iterator, char()> polyline_chars;
qi::rule<Iterator, char()> percent_encoding;
};
} // namespace
namespace osrm::server::api
{
namespace x3 = boost::spirit::x3;
struct ParsedURLClass : x3::annotate_on_success
{
};
const x3::rule<struct Service, std::string> service = "service";
const x3::rule<struct Version, unsigned> version = "version";
const x3::rule<struct Profile, std::string> profile = "profile";
const x3::rule<struct Query, std::string> query = "query";
const x3::rule<struct ParsedURL, ParsedURL> start = "start";
const auto identifier = x3::char_("a-zA-Z0-9_.~:-");
const auto service_def = +identifier;
const auto version_def = x3::uint_;
const auto profile_def = +identifier;
const auto percent_encoding = x3::lit('%') >> x3::uint_parser<unsigned char, 16, 2, 2>();
const auto query_char = percent_encoding | x3::char_("a-zA-Z0-9_[]{}@?|\\~`^=,;:&().-");
const auto query_def = +query_char;
const auto start_def = x3::lit('/') > service > x3::lit('/') > x3::lit('v') > version
> x3::lit('/') > profile > x3::lit('/') > query;
BOOST_SPIRIT_DEFINE(service, version, profile, query, start)
boost::optional<ParsedURL> parseURL(std::string::iterator &iter, const std::string::iterator end)
{
using It = std::decay<decltype(iter)>::type;
static URLParser<It, ParsedURL(It)> const parser;
ParsedURL out;
try
{
const auto ok = boost::spirit::qi::parse(iter, end, parser(boost::phoenix::val(iter)), out);
auto iter_copy = iter;
bool r = x3::phrase_parse(iter_copy, end, start, x3::space, out);
if (ok && iter == end)
if (r && iter_copy == end)
{
iter = iter_copy;
// TODO: find a way to do it more effective
std::string parsed_part =
"/" + out.service + "/v" + std::to_string(out.version) + "/" + out.profile + "/";
out.prefix_length = parsed_part.length();
return boost::make_optional(out);
}
}
catch (const qi::expectation_failure<It> &failure)
catch (const x3::expectation_failure<std::string::iterator> &failure)
{
// The grammar above using expectation parsers ">" does not automatically increment the
// iterator to the failing position. Extract the position from the exception ourselves.
iter = failure.first;
iter = failure.where();
}
return boost::none;
+6 -5
View File
@@ -9,6 +9,7 @@
#include <algorithm>
#include <iterator>
#include <limits>
#include <optional>
#include <utility>
namespace osrm::util::coordinate_calculation
@@ -173,14 +174,14 @@ double computeAngle(const Coordinate first, const Coordinate second, const Coord
return angle;
}
boost::optional<Coordinate>
std::optional<Coordinate>
circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3)
{
// free after http://paulbourke.net/geometry/circlesphere/
// require three distinct points
if (C1 == C2 || C2 == C3 || C1 == C3)
{
return boost::none;
return std::nullopt;
}
// define line through c1, c2 and c2,c3
@@ -195,7 +196,7 @@ circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3)
(std::abs(C2C1_lat) < std::numeric_limits<double>::epsilon() &&
std::abs(C3C2_lat) < std::numeric_limits<double>::epsilon()))
{
return boost::none;
return std::nullopt;
}
else if (std::abs(C2C1_lon) < std::numeric_limits<double>::epsilon())
{
@@ -233,7 +234,7 @@ circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3)
// can this ever happen?
if (std::abs(C2C1_slope - C3C2_slope) < std::numeric_limits<double>::epsilon())
return boost::none;
return std::nullopt;
const double C1_y = static_cast<double>(toFloating(C1.lat));
const double C1_x = static_cast<double>(toFloating(C1.lon));
@@ -247,7 +248,7 @@ circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3)
(2 * (C3C2_slope - C2C1_slope));
const double lat = (0.5 * (C1_x + C2_x) - lon) / C2C1_slope + 0.5 * (C1_y + C2_y);
if (lon < -180.0 || lon > 180.0 || lat < -90.0 || lat > 90.0)
return boost::none;
return std::nullopt;
else
return Coordinate(FloatLongitude{lon}, FloatLatitude{lat});
}
+4 -4
View File
@@ -17,7 +17,7 @@ NodeIdVectorToLineString::NodeIdVectorToLineString(
// converts a vector of node ids into a linestring geojson feature
util::json::Object
NodeIdVectorToLineString::operator()(const std::vector<NodeID> &node_ids,
const boost::optional<json::Object> &properties) const
const std::optional<json::Object> &properties) const
{
util::json::Array coordinates;
std::transform(node_ids.begin(),
@@ -37,7 +37,7 @@ NodeIdVectorToMultiPoint::NodeIdVectorToMultiPoint(
util::json::Object
NodeIdVectorToMultiPoint::operator()(const std::vector<NodeID> &node_ids,
const boost::optional<json::Object> &properties) const
const std::optional<json::Object> &properties) const
{
util::json::Array coordinates;
std::transform(node_ids.begin(),
@@ -51,7 +51,7 @@ NodeIdVectorToMultiPoint::operator()(const std::vector<NodeID> &node_ids,
//----------------------------------------------------------------
util::json::Object
CoordinateVectorToMultiPoint::operator()(const std::vector<util::Coordinate> &input_coordinates,
const boost::optional<json::Object> &properties) const
const std::optional<json::Object> &properties) const
{
auto coordinates = makeJsonArray(input_coordinates);
return makeFeature("MultiPoint", std::move(coordinates), properties);
@@ -60,7 +60,7 @@ CoordinateVectorToMultiPoint::operator()(const std::vector<util::Coordinate> &in
//----------------------------------------------------------------
util::json::Object
CoordinateVectorToLineString::operator()(const std::vector<util::Coordinate> &input_coordinates,
const boost::optional<json::Object> &properties) const
const std::optional<json::Object> &properties) const
{
auto coordinates = makeJsonArray(input_coordinates);
return makeFeature("LineString", std::move(coordinates), properties);
+3 -3
View File
@@ -5,13 +5,13 @@
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/optional.hpp>
#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
#include <rapidjson/istreamwrapper.h>
#include <fstream>
#include <optional>
#include <regex>
#include <string>
#include <unordered_map>
@@ -158,7 +158,7 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut
rtree = rtree_t(polygons);
}
boost::optional<struct tm> Timezoner::operator()(const point_t &point) const
std::optional<struct tm> Timezoner::operator()(const point_t &point) const
{
std::vector<rtree_t::value_type> result;
rtree.query(boost::geometry::index::intersects(point), std::back_inserter(result));
@@ -168,6 +168,6 @@ boost::optional<struct tm> Timezoner::operator()(const point_t &point) const
if (boost::geometry::within(point, local_times[index].first))
return local_times[index].second;
}
return boost::none;
return std::nullopt;
}
} // namespace osrm::updater
+9
View File
@@ -130,6 +130,15 @@ BOOST_AUTO_TEST_CASE(valid_urls)
BOOST_CHECK_EQUAL(reference_9.profile, result_9->profile);
CHECK_EQUAL_RANGE(reference_9.query, result_9->query);
BOOST_CHECK_EQUAL(reference_9.prefix_length, result_9->prefix_length);
api::ParsedURL reference_10{"match", 1, "car", "poly line ", 14UL};
auto result_10 = api::parseURL("/match/v1/car/poly%20line%20");
BOOST_CHECK(result_10);
BOOST_CHECK_EQUAL(reference_10.service, result_10->service);
BOOST_CHECK_EQUAL(reference_10.version, result_10->version);
BOOST_CHECK_EQUAL(reference_10.profile, result_10->profile);
CHECK_EQUAL_RANGE(reference_10.query, result_10->query);
BOOST_CHECK_EQUAL(reference_10.prefix_length, result_10->prefix_length);
}
BOOST_AUTO_TEST_SUITE_END()