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
13 changed files with 72 additions and 1883 deletions
+1 -1
View File
@@ -19,7 +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), see also [#6592](https://github.com/Project-OSRM/osrm-backend/issues/6592)
- 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>
+2 -2
View File
@@ -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 {};
return std::nullopt;
}
auto intersection = extractor::intersection::getConnectedRoads<false>(node_based_graph,
@@ -465,7 +465,7 @@ IntersectionHandler::getNextIntersection(const NodeID at, const EdgeID via) cons
if (intersection.size() <= 2 || intersection.isTrafficSignalOrBarrier())
{
return {};
return std::nullopt;
}
return std::make_optional(IntersectionViewAndNode{std::move(intersection), intersection_node});
+5 -5
View File
@@ -652,7 +652,7 @@ std::optional<std::size_t> SliproadHandler::getObviousIndexWithSliproads(
// then the non-Sliproad is the obvious one.
if (intersection.size() != 3)
{
return {};
return std::nullopt;
}
const auto forking = intersection[1].instruction.type == TurnType::Fork &&
@@ -660,7 +660,7 @@ std::optional<std::size_t> SliproadHandler::getObviousIndexWithSliproads(
if (!forking)
{
return {};
return std::nullopt;
}
const auto first = getNextIntersection(at, intersection.getRightmostRoad().eid);
@@ -668,12 +668,12 @@ std::optional<std::size_t> SliproadHandler::getObviousIndexWithSliproads(
if (!first || !second)
{
return {};
return std::nullopt;
}
if (first->intersection.isDeadEnd() || second->intersection.isDeadEnd())
{
return {};
return std::nullopt;
}
// In case of loops at the end of the road, we will arrive back at the intersection
@@ -688,7 +688,7 @@ std::optional<std::size_t> SliproadHandler::getObviousIndexWithSliproads(
return std::make_optional(std::size_t{1});
}
return {};
return std::nullopt;
}
bool SliproadHandler::nextIntersectionIsTooFarAway(const NodeID start, const EdgeID onto) const
+2 -2
View File
@@ -647,7 +647,7 @@ TurnHandler::findForkCandidatesByGeometry(Intersection &intersection) const
}
}
}
return {};
return std::nullopt;
}
// check if the fork candidates (all roads between left and right) and the
@@ -740,7 +740,7 @@ std::optional<TurnHandler::Fork> TurnHandler::findFork(const EdgeID via_edge,
}
}
return {};
return std::nullopt;
}
void TurnHandler::handleDistinctConflict(const EdgeID via_edge,
-68
View File
@@ -1,68 +0,0 @@
#ifndef OSRM_BINDINGS_NODE_JSON_V8_RENDERER_HPP
#define OSRM_BINDINGS_NODE_JSON_V8_RENDERER_HPP
#include "osrm/json_container.hpp"
#include <napi.h>
#include <functional>
namespace node_osrm
{
struct V8Renderer
{
explicit V8Renderer(const Napi::Env &env, Napi::Value &out) : env(env), out(out) {}
void operator()(const osrm::json::String &string) const
{
out = Napi::String::New(env, string.value);
}
void operator()(const osrm::json::Number &number) const
{
out = Napi::Number::New(env, number.value);
}
void operator()(const osrm::json::Object &object) const
{
Napi::Object obj = Napi::Object::New(env);
for (const auto &keyValue : object.values)
{
Napi::Value child;
mapbox::util::apply_visitor(V8Renderer(env, child), keyValue.second);
obj.Set(keyValue.first, child);
}
out = obj;
}
void operator()(const osrm::json::Array &array) const
{
Napi::Array a = Napi::Array::New(env, array.values.size());
for (auto i = 0u; i < array.values.size(); ++i)
{
Napi::Value child;
mapbox::util::apply_visitor(V8Renderer(env, child), array.values[i]);
a.Set(i, child);
}
out = a;
}
void operator()(const osrm::json::True &) const { out = Napi::Boolean::New(env, true); }
void operator()(const osrm::json::False &) const { out = Napi::Boolean::New(env, false); }
void operator()(const osrm::json::Null &) const { out = env.Null(); }
private:
const Napi::Env &env;
Napi::Value &out;
};
inline void renderToV8(const Napi::Env &env, Napi::Value &out, const osrm::json::Object &object)
{
V8Renderer renderer(env, out);
renderer(object);
}
} // namespace node_osrm
#endif // JSON_V8_RENDERER_HPP
-32
View File
@@ -1,32 +0,0 @@
#ifndef OSRM_BINDINGS_NODE_HPP
#define OSRM_BINDINGS_NODE_HPP
#include "osrm/osrm_fwd.hpp"
#include <napi.h>
#include <memory>
namespace node_osrm
{
class Engine final : public Napi::ObjectWrap<Engine>
{
public:
static Napi::Object Init(Napi::Env env, Napi::Object exports);
Engine(const Napi::CallbackInfo &info);
std::shared_ptr<osrm::OSRM> this_;
private:
Napi::Value route(const Napi::CallbackInfo &info);
Napi::Value nearest(const Napi::CallbackInfo &info);
Napi::Value table(const Napi::CallbackInfo &info);
Napi::Value tile(const Napi::CallbackInfo &info);
Napi::Value match(const Napi::CallbackInfo &info);
Napi::Value trip(const Napi::CallbackInfo &info);
};
} // namespace node_osrm
#endif
File diff suppressed because it is too large Load Diff
+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;
+4 -4
View File
@@ -181,7 +181,7 @@ circleCenter(const Coordinate C1, const Coordinate C2, const Coordinate C3)
// require three distinct points
if (C1 == C2 || C2 == C3 || C1 == C3)
{
return {};
return std::nullopt;
}
// define line through c1, c2 and c2,c3
@@ -196,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 {};
return std::nullopt;
}
else if (std::abs(C2C1_lon) < std::numeric_limits<double>::epsilon())
{
@@ -234,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 {};
return std::nullopt;
const double C1_y = static_cast<double>(toFloating(C1.lat));
const double C1_x = static_cast<double>(toFloating(C1.lon));
@@ -248,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 {};
return std::nullopt;
else
return Coordinate(FloatLongitude{lon}, FloatLatitude{lat});
}
+1 -1
View File
@@ -168,6 +168,6 @@ std::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 {};
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()